Skip to content

Commit 19394a0

Browse files
committed
Adding proper gradle build
1 parent e0f6b5e commit 19394a0

3 files changed

Lines changed: 78 additions & 1 deletion

File tree

‎.gitignore‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.gradle
22
*/.DS_Store
3-
.DS_Store
3+
.DS_Store
4+
target
5+

‎build/build.gradle‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
defaultTasks 'all'
2+
3+
def srcDir = '..'
4+
def outputDir = 'target'
5+
def jshintConfig = 'build/jshint.json'
6+
def jshintOutput = outputDir + '/jshint.xml'
7+
def testDir = 'test'
8+
9+
task clean << {
10+
description = 'Cleans old artifacts'
11+
ant.delete(dir: outputDir)
12+
ant.delete(file: jshintOutput)
13+
}
14+
15+
task init(dependsOn: 'clean') << {
16+
description = 'Creates artifact output directories'
17+
(new File(outputDir)).mkdirs()
18+
}
19+
20+
task jshint(dependsOn: 'init') << {
21+
description = 'runs jshint on all non-test and lib JS files'
22+
def jsPattern = ~/.*stacktrace\.js/
23+
def jsFiles = [];
24+
new File(".").eachFileRecurse {
25+
if (it.canonicalPath =~ jsPattern) {
26+
jsFiles << it.canonicalPath
27+
}
28+
}
29+
30+
def command = "jshint ${jsFiles.join(' ')} --config ${jshintConfig} --jslint-reporter"
31+
println command
32+
new File(jshintOutput).write(command.execute().text)
33+
}
34+
35+
task test(dependsOn: 'init') << {
36+
def specs = []
37+
new File(testDir).eachFile {
38+
if (it.name.endsWith('.html')) {
39+
specs << it
40+
}
41+
}
42+
43+
def startTime = new Date().time
44+
def numFailures = 0
45+
def testsFailed = false
46+
specs.each { File spec ->
47+
println "Running ${spec.name}..."
48+
49+
def outputFile = "${outputDir}/TEST-${spec.name.replace('-', '').replace('.html', '.xml')}"
50+
ant.exec(outputproperty: 'cmdOut', errorproperty: 'cmdErr',
51+
resultproperty: 'exitCode', failonerror: 'false', executable: '/usr/bin/env') {
52+
arg(value: 'DISPLAY=:1')
53+
arg(value: '/usr/local/bin/phantomjs')
54+
arg(value: '../test/phantomjs-qunit-runner.js')
55+
arg(value: "${spec.canonicalPath}")
56+
}
57+
// Check exit code
58+
if (ant.project.properties.exitCode != '0') {
59+
testsFailed = true
60+
numFailures++
61+
println '\tFAILED'
62+
} else {
63+
println '\tPASSED'
64+
}
65+
66+
new File(outputFile).write(ant.project.properties.cmdOut)
67+
}
68+
69+
println "QUnit tests completed in ${new Date().time - startTime}ms"
70+
println "QUnit Tests ${testsFailed ? 'FAILED' : 'PASSED'} - view reports in ${outputDir}"
71+
ant.fail(if: testsFailed, message: 'JS Tests Failed')
72+
}
73+
74+
task all(dependsOn: ['clean', 'jshint', 'test']) << {}

‎test/phantomjs-qunit-runner.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ page.open(url, function(status) {
7272
});
7373
}, function() {
7474
var failedNum = page.evaluate(function() {
75+
var el = document.getElementById('qunit-testresult');
7576
try {
7677
return el.getElementsByClassName('failed')[0].innerHTML;
7778
} catch (e) { }

0 commit comments

Comments
 (0)