@@ -22,17 +22,68 @@ node {
2222 download = true
2323}
2424
25- task installDependencies (type : NpmTask ) {
25+ // -- Testing with Mocha under Node
26+
27+ task installDependenciesMochaNode (type : NpmTask ) {
2628 args = [' install' , ' mocha' , ' source-map-support' , ' --no-save' ]
2729 if (project. hasProperty(" teamcity" )) args + = ' mocha-teamcity-reporter'
2830}
2931
30- task prepareMocha (dependsOn : [compileTestKotlin2Js, populateNodeModules, installDependencies ])
32+ task prepareMochaNode (dependsOn : [compileTestKotlin2Js, populateNodeModules, installDependenciesMochaNode ])
3133
32- task runMocha (type : NodeTask , dependsOn : prepareMocha ) {
34+ task testMochaNode (type : NodeTask , dependsOn : prepareMochaNode ) {
3335 script = file(' node_modules/mocha/bin/mocha' )
34- args = [compileTestKotlin2Js. outputFile, ' --require=source-map-support/register' ]
35- if (project. hasProperty(" teamcity" )) args + = ' --reporter=mocha-teamcity-reporter'
36+ args = [compileTestKotlin2Js. outputFile, ' --require' , ' source-map-support/register' ]
37+ if (project. hasProperty(" teamcity" )) args + = [' --reporter' , ' mocha-teamcity-reporter' ]
38+ }
39+
40+ test. dependsOn testMochaNode
41+
42+
43+ // -- Testing with Mocha under headless Chrome
44+
45+ task installDependenciesMochaChrome (type : NpmTask ) {
46+ args = [' install' , ' mocha-headless-chrome' , " kotlin@$kotlin_version " , " kotlin-test@$kotlin_version " , ' --no-save' ]
47+ if (project. hasProperty(" teamcity" )) args + = ' mocha-teamcity-reporter'
48+ }
49+
50+ task prepareMochaChrome (dependsOn : [compileTestKotlin2Js, populateNodeModules, installDependenciesMochaChrome])
51+
52+ prepareMochaChrome. doLast {
53+ file(" $buildDir /test-page.html" ). text = """
54+ <!DOCTYPE html>
55+ <html>
56+ <head>
57+ <title>Mocha Tests</title>
58+ <meta charset="utf-8">
59+ <link rel="stylesheet" href="$projectDir /node_modules/mocha/mocha.css">
60+ </head>
61+ <body>
62+ <div id="mocha"></div>
63+ <script src="$projectDir /node_modules/mocha/mocha.js"></script>
64+ <script>mocha.setup('bdd');</script>
65+ <script src="$projectDir /node_modules/kotlin/kotlin.js"></script>
66+ <script src="$projectDir /node_modules/kotlin-test/kotlin-test.js"></script>
67+ <script src="$compileKotlin2Js . outputFile "></script>
68+ <script src="$compileTestKotlin2Js . outputFile "></script>
69+ <script>mocha.run();</script>
70+ </body>
71+ </html>
72+ """
73+ }
74+
75+ task testMochaChrome (type : NodeTask , dependsOn : prepareMochaChrome) {
76+ script = file(' node_modules/mocha-headless-chrome/bin/start' )
77+ args = [compileTestKotlin2Js. outputFile, ' --file' , " $buildDir /test-page.html" ]
78+ if (project. hasProperty(" teamcity" )) args + = [' --reporter' , ' mocha-teamcity-reporter' ]
79+ }
80+
81+ test. dependsOn testMochaChrome
82+
83+ // -- Remove node_modules on clean
84+
85+ task deleteNodeModules (type : Delete ) {
86+ delete ' node_modules'
3687}
3788
38- test . dependsOn runMocha
89+ clean . dependsOn deleteNodeModules
0 commit comments