blob: c2f75034a3634aa35e2565eeb688cb2311866101 [file] [log] [blame]
Roman Elizarov5f5107e2018-03-05 12:51:23 +03001// -- Testing with Mocha under Node
2
Roman Elizarovf0fc7702018-03-06 12:45:08 +03003task installDependenciesMochaNode(type: NpmTask, dependsOn: [npmInstall]) {
Roman Elizarov6140ca32018-03-05 14:34:18 +03004 args = ['install',
5 "mocha@$mocha_version",
Roman Elizarov905a5122018-04-04 09:59:33 +03006 "source-map-support@$source_map_support_version",
Roman Elizarov6140ca32018-03-05 14:34:18 +03007 '--no-save']
8 if (project.hasProperty("teamcity")) args += [
9 "mocha-teamcity-reporter@$mocha_teamcity_reporter_version"]
Roman Elizarov65eff0b2017-12-20 15:51:31 +030010}
11
Roman Elizarovf0fc7702018-03-06 12:45:08 +030012task testMochaNode(type: NodeTask, dependsOn: [compileTestKotlin2Js, installDependenciesMochaNode]) {
13 script = file("$node.nodeModulesDir/node_modules/mocha/bin/mocha")
Roman Elizarov5f5107e2018-03-05 12:51:23 +030014 args = [compileTestKotlin2Js.outputFile, '--require', 'source-map-support/register']
15 if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
Roman Elizarov65eff0b2017-12-20 15:51:31 +030016}
17
Roman Elizarov5f5107e2018-03-05 12:51:23 +030018test.dependsOn testMochaNode
19
Roman Elizarov5f5107e2018-03-05 12:51:23 +030020// -- Testing with Mocha under headless Chrome
21
Roman Elizarovf0fc7702018-03-06 12:45:08 +030022task installDependenciesMochaChrome(type: NpmTask, dependsOn: [npmInstall]) {
Roman Elizarov6140ca32018-03-05 14:34:18 +030023 args = ['install',
24 "mocha@$mocha_version",
25 "mocha-headless-chrome@$mocha_headless_chrome_version",
26 "kotlin@$kotlin_version",
27 "kotlin-test@$kotlin_version",
28 '--no-save']
29 if (project.hasProperty("teamcity")) args += [
30 "mocha-teamcity-reporter@$mocha_teamcity_reporter_version"]
Roman Elizarov5f5107e2018-03-05 12:51:23 +030031}
32
Roman Elizarovf0fc7702018-03-06 12:45:08 +030033def mochaChromeTestPage = file("$buildDir/test-page.html")
34
35task prepareMochaChrome(dependsOn: [compileTestKotlin2Js, installDependenciesMochaChrome]) {
36 outputs.file(mochaChromeTestPage)
37}
Roman Elizarov5f5107e2018-03-05 12:51:23 +030038
39prepareMochaChrome.doLast {
Roman Elizarovf0fc7702018-03-06 12:45:08 +030040 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 """
Roman Elizarov5f5107e2018-03-05 12:51:23 +030059}
60
61task testMochaChrome(type: NodeTask, dependsOn: prepareMochaChrome) {
Roman Elizarovf0fc7702018-03-06 12:45:08 +030062 script = file("$node.nodeModulesDir/node_modules/mocha-headless-chrome/bin/start")
63 args = [compileTestKotlin2Js.outputFile, '--file', mochaChromeTestPage]
Roman Elizarov5f5107e2018-03-05 12:51:23 +030064 if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
65}
66
Roman Elizarovb1dad172018-03-05 17:47:10 +030067// todo: Commented out because mocha-headless-chrome does not work on TeamCity
68//test.dependsOn testMochaChrome
Roman Elizarov5f5107e2018-03-05 12:51:23 +030069