forked from sporkmonger/node-scrypt-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
106 lines (89 loc) · 2.47 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import groovy.text.SimpleTemplateEngine
buildscript{
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.eriwen:gradle-js-plugin:1.9.0'
}
}
apply plugin: 'js'
buildDir = "build"
jsSrcDir = "lib"
testDir = "tests"
javascript.source {
dev {
js {
srcDir jsSrcDir
include "*.js"
exclude "*.min.js"
}
}
prod {
js {
srcDir jsSrcDir
include "*.min.js"
}
}
}
combineJs {
source = javascript.source.dev.js.files
dest = file("${buildDir}/scrypt-all.js")
}
minifyJs {
source = combineJs
dest = file("${buildDir}/scrypt-min.js")
closure {
warningLevel = 'QUIET'
}
}
def phantomTest (specs){
def phantomJsPath = "which phantomjs".execute().text.trim()
def startTime = new Date().time
def numFailures = 0
def testsFailed = false
specs.each{ spec ->
def outputFile = "${buildDir}/TEST-${spec.name.replace('.html', '.xml')}"
ant.exec(outputproperty: 'cmdOut', errorproperty: 'cmdErr',
resultproperty: 'exitCode', failonerror: 'false',
executable: phantomJsPath){
arg(value: 'tests/resources/run-qunit.js')
arg(value: spec.canonicalPath)
}
def commandOut = "${ant.project.properties.cmdOut}"
if (ant.project.properties.exitCode != '0'){
testsFailed = true
numFailures++
println "FAILED\n"
println commandOut
} else {
println "PASSED"
}
new File(outputFile).write(commandOut)
}
println "QUnit Tests ${testsFailed ? 'FAILED' : 'PASSED'} - view reports in ${buildDir}"
ant.fail(if: testsFailed, message: 'JS Tests Failed')
}
task prodTest() << {
def specs = []
new File(testDir).eachFile{
if (!it.name.endsWith('.html')) return
specs << it
}
phantomTest (specs)
}
task devTest() << {
def cDir = new File(".")
def jsSources = javascript.source.dev.js.files.collect{
"../"+cDir.toURI().relativize(it.toURI()).toString()
}
def engine = new SimpleTemplateEngine()
template = engine.createTemplate(new File("tests/index.html").text)
.make([jsSources: jsSources])
new File("${testDir}/dev.html").with{
if(exists()) delete();
}
new File("${testDir}/dev.html") << template.toString()
phantomTest ([new File("${testDir}/dev.html")])
}