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