blob: f8a4d4800dfbc5eba3e6a9e61e935b64df053489 [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 Elizarov1fc28392018-05-17 14:05:12 +030016 if (project.hasProperty("mochaTests")) args += ['--grep', "$mochaTests"]
Roman Elizarov65eff0b2017-12-20 15:51:31 +030017}
18
Roman Elizarov5f5107e2018-03-05 12:51:23 +030019test.dependsOn testMochaNode
20
Roman Elizarov5f5107e2018-03-05 12:51:23 +030021// -- Testing with Mocha under headless Chrome
22
Roman Elizarovf0fc7702018-03-06 12:45:08 +030023task installDependenciesMochaChrome(type: NpmTask, dependsOn: [npmInstall]) {
Roman Elizarov6140ca32018-03-05 14:34:18 +030024 args = ['install',
25 "mocha@$mocha_version",
26 "mocha-headless-chrome@$mocha_headless_chrome_version",
27 "kotlin@$kotlin_version",
28 "kotlin-test@$kotlin_version",
29 '--no-save']
30 if (project.hasProperty("teamcity")) args += [
31 "mocha-teamcity-reporter@$mocha_teamcity_reporter_version"]
Roman Elizarov5f5107e2018-03-05 12:51:23 +030032}
33
Roman Elizarovf0fc7702018-03-06 12:45:08 +030034def mochaChromeTestPage = file("$buildDir/test-page.html")
35
36task prepareMochaChrome(dependsOn: [compileTestKotlin2Js, installDependenciesMochaChrome]) {
37 outputs.file(mochaChromeTestPage)
38}
Roman Elizarov5f5107e2018-03-05 12:51:23 +030039
40prepareMochaChrome.doLast {
Roman Elizarovf0fc7702018-03-06 12:45:08 +030041 mochaChromeTestPage.text = """<!DOCTYPE html>
42 <html>
43 <head>
44 <title>Mocha Tests</title>
45 <meta charset="utf-8">
46 <link rel="stylesheet" href="$node.nodeModulesDir/node_modules/mocha/mocha.css">
47 </head>
48 <body>
49 <div id="mocha"></div>
50 <script src="$node.nodeModulesDir/node_modules/mocha/mocha.js"></script>
51 <script>mocha.setup('bdd');</script>
52 <script src="$node.nodeModulesDir/node_modules/kotlin/kotlin.js"></script>
53 <script src="$node.nodeModulesDir/node_modules/kotlin-test/kotlin-test.js"></script>
54 <script src="$compileKotlin2Js.outputFile"></script>
55 <script src="$compileTestKotlin2Js.outputFile"></script>
56 <script>mocha.run();</script>
57 </body>
58 </html>
59 """
Roman Elizarov5f5107e2018-03-05 12:51:23 +030060}
61
62task testMochaChrome(type: NodeTask, dependsOn: prepareMochaChrome) {
Roman Elizarovf0fc7702018-03-06 12:45:08 +030063 script = file("$node.nodeModulesDir/node_modules/mocha-headless-chrome/bin/start")
64 args = [compileTestKotlin2Js.outputFile, '--file', mochaChromeTestPage]
Roman Elizarov5f5107e2018-03-05 12:51:23 +030065 if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
Roman Elizarov1fc28392018-05-17 14:05:12 +030066 if (project.hasProperty("mochaTests")) args += ['--grep', "$mochaTests"]
Roman Elizarov5f5107e2018-03-05 12:51:23 +030067}
68
Roman Elizarovb1dad172018-03-05 17:47:10 +030069// todo: Commented out because mocha-headless-chrome does not work on TeamCity
70//test.dependsOn testMochaChrome
Roman Elizarov5f5107e2018-03-05 12:51:23 +030071