blob: 2e1ffcceae71fdc016951661d6a0dd7fa230bad8 [file] [log] [blame]
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03001/*
2 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
Roman Elizarov5f5107e2018-03-05 12:51:23 +03005// -- Testing with Mocha under Node
6
Roman Elizarovf0fc7702018-03-06 12:45:08 +03007task installDependenciesMochaNode(type: NpmTask, dependsOn: [npmInstall]) {
Roman Elizarov6140ca32018-03-05 14:34:18 +03008 args = ['install',
9 "mocha@$mocha_version",
Roman Elizarov905a5122018-04-04 09:59:33 +030010 "source-map-support@$source_map_support_version",
Roman Elizarov6140ca32018-03-05 14:34:18 +030011 '--no-save']
12 if (project.hasProperty("teamcity")) args += [
13 "mocha-teamcity-reporter@$mocha_teamcity_reporter_version"]
Roman Elizarov65eff0b2017-12-20 15:51:31 +030014}
15
Roman Elizarovf0fc7702018-03-06 12:45:08 +030016task testMochaNode(type: NodeTask, dependsOn: [compileTestKotlin2Js, installDependenciesMochaNode]) {
17 script = file("$node.nodeModulesDir/node_modules/mocha/bin/mocha")
Roman Elizarov5f5107e2018-03-05 12:51:23 +030018 args = [compileTestKotlin2Js.outputFile, '--require', 'source-map-support/register']
19 if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
Roman Elizarov1fc28392018-05-17 14:05:12 +030020 if (project.hasProperty("mochaTests")) args += ['--grep', "$mochaTests"]
Roman Elizarov65eff0b2017-12-20 15:51:31 +030021}
22
Roman Elizarov5f5107e2018-03-05 12:51:23 +030023test.dependsOn testMochaNode
24
Roman Elizarov5f5107e2018-03-05 12:51:23 +030025// -- Testing with Mocha under headless Chrome
26
Roman Elizarovf0fc7702018-03-06 12:45:08 +030027task installDependenciesMochaChrome(type: NpmTask, dependsOn: [npmInstall]) {
Roman Elizarov6140ca32018-03-05 14:34:18 +030028 args = ['install',
29 "mocha@$mocha_version",
30 "mocha-headless-chrome@$mocha_headless_chrome_version",
31 "kotlin@$kotlin_version",
32 "kotlin-test@$kotlin_version",
33 '--no-save']
34 if (project.hasProperty("teamcity")) args += [
35 "mocha-teamcity-reporter@$mocha_teamcity_reporter_version"]
Roman Elizarov5f5107e2018-03-05 12:51:23 +030036}
37
Roman Elizarovf0fc7702018-03-06 12:45:08 +030038def mochaChromeTestPage = file("$buildDir/test-page.html")
39
40task prepareMochaChrome(dependsOn: [compileTestKotlin2Js, installDependenciesMochaChrome]) {
41 outputs.file(mochaChromeTestPage)
42}
Roman Elizarov5f5107e2018-03-05 12:51:23 +030043
44prepareMochaChrome.doLast {
Roman Elizarovf0fc7702018-03-06 12:45:08 +030045 mochaChromeTestPage.text = """<!DOCTYPE html>
46 <html>
47 <head>
48 <title>Mocha Tests</title>
49 <meta charset="utf-8">
50 <link rel="stylesheet" href="$node.nodeModulesDir/node_modules/mocha/mocha.css">
51 </head>
52 <body>
53 <div id="mocha"></div>
54 <script src="$node.nodeModulesDir/node_modules/mocha/mocha.js"></script>
55 <script>mocha.setup('bdd');</script>
56 <script src="$node.nodeModulesDir/node_modules/kotlin/kotlin.js"></script>
57 <script src="$node.nodeModulesDir/node_modules/kotlin-test/kotlin-test.js"></script>
58 <script src="$compileKotlin2Js.outputFile"></script>
59 <script src="$compileTestKotlin2Js.outputFile"></script>
60 <script>mocha.run();</script>
61 </body>
62 </html>
63 """
Roman Elizarov5f5107e2018-03-05 12:51:23 +030064}
65
66task testMochaChrome(type: NodeTask, dependsOn: prepareMochaChrome) {
Roman Elizarovf0fc7702018-03-06 12:45:08 +030067 script = file("$node.nodeModulesDir/node_modules/mocha-headless-chrome/bin/start")
68 args = [compileTestKotlin2Js.outputFile, '--file', mochaChromeTestPage]
Roman Elizarov5f5107e2018-03-05 12:51:23 +030069 if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
Roman Elizarov1fc28392018-05-17 14:05:12 +030070 if (project.hasProperty("mochaTests")) args += ['--grep', "$mochaTests"]
Roman Elizarov5f5107e2018-03-05 12:51:23 +030071}
72
Roman Elizarovb1dad172018-03-05 17:47:10 +030073// todo: Commented out because mocha-headless-chrome does not work on TeamCity
74//test.dependsOn testMochaChrome
Roman Elizarov5f5107e2018-03-05 12:51:23 +030075