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 ' \t FAILED'
62+ } else {
63+ println ' \t PASSED'
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' ]) << {}
0 commit comments