1
- // Configures testing for JS modules
2
-
3
- task populateNodeModules (type : Copy , dependsOn : compileKotlin2Js) {
4
- from compileKotlin2Js. destinationDir
5
- into " ${ buildDir} /node_modules"
6
-
7
- afterEvaluate {
8
- configurations. testCompile. each {
9
- from zipTree(it. absolutePath). matching {
10
- include ' *.js'
11
- include ' *.js.map'
12
- }
13
- }
14
- }
15
- }
16
-
17
1
// -- Testing with Mocha under Node
18
2
19
- task installDependenciesMochaNode (type : NpmTask ) {
3
+ task installDependenciesMochaNode (type : NpmTask , dependsOn : [npmInstall] ) {
20
4
args = [' install' ,
21
5
" mocha@$mocha_version " ,
22
6
" source-map-support@$source_map_suport_version " ,
@@ -25,20 +9,17 @@ task installDependenciesMochaNode(type: NpmTask) {
25
9
" mocha-teamcity-reporter@$mocha_teamcity_reporter_version " ]
26
10
}
27
11
28
- task prepareMochaNode (dependsOn : [compileTestKotlin2Js, populateNodeModules, installDependenciesMochaNode])
29
-
30
- task testMochaNode (type : NodeTask , dependsOn : prepareMochaNode) {
31
- script = file(' node_modules/mocha/bin/mocha' )
12
+ task testMochaNode (type : NodeTask , dependsOn : [compileTestKotlin2Js, installDependenciesMochaNode]) {
13
+ script = file(" $node . nodeModulesDir /node_modules/mocha/bin/mocha" )
32
14
args = [compileTestKotlin2Js. outputFile, ' --require' , ' source-map-support/register' ]
33
15
if (project. hasProperty(" teamcity" )) args + = [' --reporter' , ' mocha-teamcity-reporter' ]
34
16
}
35
17
36
18
test. dependsOn testMochaNode
37
19
38
-
39
20
// -- Testing with Mocha under headless Chrome
40
21
41
- task installDependenciesMochaChrome (type : NpmTask ) {
22
+ task installDependenciesMochaChrome (type : NpmTask , dependsOn : [npmInstall] ) {
42
23
args = [' install' ,
43
24
" mocha@$mocha_version " ,
44
25
" mocha-headless-chrome@$mocha_headless_chrome_version " ,
@@ -49,44 +30,40 @@ task installDependenciesMochaChrome(type: NpmTask) {
49
30
" mocha-teamcity-reporter@$mocha_teamcity_reporter_version " ]
50
31
}
51
32
52
- task prepareMochaChrome (dependsOn : [compileTestKotlin2Js, populateNodeModules, installDependenciesMochaChrome])
33
+ def mochaChromeTestPage = file(" $buildDir /test-page.html" )
34
+
35
+ task prepareMochaChrome (dependsOn : [compileTestKotlin2Js, installDependenciesMochaChrome]) {
36
+ outputs. file(mochaChromeTestPage)
37
+ }
53
38
54
39
prepareMochaChrome. doLast {
55
- file(" $buildDir /test-page.html" ). text = """
56
- <!DOCTYPE html>
57
- <html>
58
- <head>
59
- <title>Mocha Tests</title>
60
- <meta charset="utf-8">
61
- <link rel="stylesheet" href="$projectDir /node_modules/mocha/mocha.css">
62
- </head>
63
- <body>
64
- <div id="mocha"></div>
65
- <script src="$projectDir /node_modules/mocha/mocha.js"></script>
66
- <script>mocha.setup('bdd');</script>
67
- <script src="$projectDir /node_modules/kotlin/kotlin.js"></script>
68
- <script src="$projectDir /node_modules/kotlin-test/kotlin-test.js"></script>
69
- <script src="$compileKotlin2Js . outputFile "></script>
70
- <script src="$compileTestKotlin2Js . outputFile "></script>
71
- <script>mocha.run();</script>
72
- </body>
73
- </html>
74
- """
40
+ mochaChromeTestPage. text = """ <!DOCTYPE html>
41
+ <html>
42
+ <head>
43
+ <title>Mocha Tests</title>
44
+ <meta charset="utf-8">
45
+ <link rel="stylesheet" href="$node . nodeModulesDir /node_modules/mocha/mocha.css">
46
+ </head>
47
+ <body>
48
+ <div id="mocha"></div>
49
+ <script src="$node . nodeModulesDir /node_modules/mocha/mocha.js"></script>
50
+ <script>mocha.setup('bdd');</script>
51
+ <script src="$node . nodeModulesDir /node_modules/kotlin/kotlin.js"></script>
52
+ <script src="$node . nodeModulesDir /node_modules/kotlin-test/kotlin-test.js"></script>
53
+ <script src="$compileKotlin2Js . outputFile "></script>
54
+ <script src="$compileTestKotlin2Js . outputFile "></script>
55
+ <script>mocha.run();</script>
56
+ </body>
57
+ </html>
58
+ """
75
59
}
76
60
77
61
task testMochaChrome (type : NodeTask , dependsOn : prepareMochaChrome) {
78
- script = file(' node_modules/mocha-headless-chrome/bin/start' )
79
- args = [compileTestKotlin2Js. outputFile, ' --file' , " $b uildDir /test-page.html " ]
62
+ script = file(" $n ode . nodeModulesDir / node_modules/mocha-headless-chrome/bin/start" )
63
+ args = [compileTestKotlin2Js. outputFile, ' --file' , mochaChromeTestPage ]
80
64
if (project. hasProperty(" teamcity" )) args + = [' --reporter' , ' mocha-teamcity-reporter' ]
81
65
}
82
66
83
67
// todo: Commented out because mocha-headless-chrome does not work on TeamCity
84
68
// test.dependsOn testMochaChrome
85
69
86
- // -- Remove node_modules on clean
87
-
88
- task deleteNodeModules (type : Delete ) {
89
- delete ' node_modules'
90
- }
91
-
92
- clean. dependsOn deleteNodeModules
0 commit comments