Roman Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 1 | // -- Testing with Mocha under Node |
| 2 | |
Roman Elizarov | f0fc770 | 2018-03-06 12:45:08 +0300 | [diff] [blame] | 3 | task installDependenciesMochaNode(type: NpmTask, dependsOn: [npmInstall]) { |
Roman Elizarov | 6140ca3 | 2018-03-05 14:34:18 +0300 | [diff] [blame] | 4 | args = ['install', |
| 5 | "mocha@$mocha_version", |
Roman Elizarov | 905a512 | 2018-04-04 09:59:33 +0300 | [diff] [blame] | 6 | "source-map-support@$source_map_support_version", |
Roman Elizarov | 6140ca3 | 2018-03-05 14:34:18 +0300 | [diff] [blame] | 7 | '--no-save'] |
| 8 | if (project.hasProperty("teamcity")) args += [ |
| 9 | "mocha-teamcity-reporter@$mocha_teamcity_reporter_version"] |
Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 10 | } |
| 11 | |
Roman Elizarov | f0fc770 | 2018-03-06 12:45:08 +0300 | [diff] [blame] | 12 | task testMochaNode(type: NodeTask, dependsOn: [compileTestKotlin2Js, installDependenciesMochaNode]) { |
| 13 | script = file("$node.nodeModulesDir/node_modules/mocha/bin/mocha") |
Roman Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 14 | args = [compileTestKotlin2Js.outputFile, '--require', 'source-map-support/register'] |
| 15 | if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter'] |
Roman Elizarov | 1fc2839 | 2018-05-17 14:05:12 +0300 | [diff] [blame] | 16 | if (project.hasProperty("mochaTests")) args += ['--grep', "$mochaTests"] |
Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 17 | } |
| 18 | |
Roman Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 19 | test.dependsOn testMochaNode |
| 20 | |
Roman Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 21 | // -- Testing with Mocha under headless Chrome |
| 22 | |
Roman Elizarov | f0fc770 | 2018-03-06 12:45:08 +0300 | [diff] [blame] | 23 | task installDependenciesMochaChrome(type: NpmTask, dependsOn: [npmInstall]) { |
Roman Elizarov | 6140ca3 | 2018-03-05 14:34:18 +0300 | [diff] [blame] | 24 | 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 Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 32 | } |
| 33 | |
Roman Elizarov | f0fc770 | 2018-03-06 12:45:08 +0300 | [diff] [blame] | 34 | def mochaChromeTestPage = file("$buildDir/test-page.html") |
| 35 | |
| 36 | task prepareMochaChrome(dependsOn: [compileTestKotlin2Js, installDependenciesMochaChrome]) { |
| 37 | outputs.file(mochaChromeTestPage) |
| 38 | } |
Roman Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 39 | |
| 40 | prepareMochaChrome.doLast { |
Roman Elizarov | f0fc770 | 2018-03-06 12:45:08 +0300 | [diff] [blame] | 41 | 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 Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | task testMochaChrome(type: NodeTask, dependsOn: prepareMochaChrome) { |
Roman Elizarov | f0fc770 | 2018-03-06 12:45:08 +0300 | [diff] [blame] | 63 | script = file("$node.nodeModulesDir/node_modules/mocha-headless-chrome/bin/start") |
| 64 | args = [compileTestKotlin2Js.outputFile, '--file', mochaChromeTestPage] |
Roman Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 65 | if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter'] |
Roman Elizarov | 1fc2839 | 2018-05-17 14:05:12 +0300 | [diff] [blame] | 66 | if (project.hasProperty("mochaTests")) args += ['--grep', "$mochaTests"] |
Roman Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 67 | } |
| 68 | |
Roman Elizarov | b1dad17 | 2018-03-05 17:47:10 +0300 | [diff] [blame] | 69 | // todo: Commented out because mocha-headless-chrome does not work on TeamCity |
| 70 | //test.dependsOn testMochaChrome |
Roman Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 71 | |