Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame] | 1 | /* |
Aurimas Liutikas | 79e555e | 2021-05-17 17:41:41 +0000 | [diff] [blame] | 2 | * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame] | 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'] |
Steve Elliott | ca095be | 2022-07-25 14:26:10 +0000 | [diff] [blame] | 12 | if (project.hasProperty("teamcity")) args.addAll(["mocha-teamcity-reporter@$mocha_teamcity_reporter_version"]) |
Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 13 | } |
| 14 | |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 15 | def compileJsLegacy = tasks.hasProperty("compileKotlinJsLegacy") |
| 16 | ? compileKotlinJsLegacy |
| 17 | : compileKotlinJs |
| 18 | |
| 19 | def compileTestJsLegacy = tasks.hasProperty("compileTestKotlinJsLegacy") |
| 20 | ? compileTestKotlinJsLegacy |
| 21 | : compileTestKotlinJs |
| 22 | |
Roman Elizarov | b247998 | 2018-10-08 17:53:42 +0300 | [diff] [blame] | 23 | // todo: use atomicfu-transformed test files here (not critical) |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 24 | task testMochaNode(type: NodeTask, dependsOn: [compileTestJsLegacy, installDependenciesMochaNode]) { |
Steve Elliott | ca095be | 2022-07-25 14:26:10 +0000 | [diff] [blame] | 25 | script = file("${node.nodeProjectDir.getAsFile().get()}/node_modules/mocha/bin/mocha") |
| 26 | args = [compileTestJsLegacy.outputFile.path, '--require', 'source-map-support/register'] |
| 27 | if (project.hasProperty("teamcity")) args.addAll(['--reporter', 'mocha-teamcity-reporter']) |
Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 28 | } |
| 29 | |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 30 | def jsLegacyTestTask = project.tasks.findByName('jsLegacyTest') ? jsLegacyTest : jsTest |
Svyatoslav Kuzmich | fa97af2 | 2020-03-11 18:56:26 +0300 | [diff] [blame] | 31 | |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 32 | jsLegacyTestTask.dependsOn testMochaNode |
Roman Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 33 | |
Roman Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 34 | // -- Testing with Mocha under headless Chrome |
| 35 | |
Roman Elizarov | f0fc770 | 2018-03-06 12:45:08 +0300 | [diff] [blame] | 36 | task installDependenciesMochaChrome(type: NpmTask, dependsOn: [npmInstall]) { |
Roman Elizarov | 6140ca3 | 2018-03-05 14:34:18 +0300 | [diff] [blame] | 37 | args = ['install', |
| 38 | "mocha@$mocha_version", |
| 39 | "mocha-headless-chrome@$mocha_headless_chrome_version", |
| 40 | "kotlin@$kotlin_version", |
| 41 | "kotlin-test@$kotlin_version", |
| 42 | '--no-save'] |
Steve Elliott | ca095be | 2022-07-25 14:26:10 +0000 | [diff] [blame] | 43 | if (project.hasProperty("teamcity")) args.addAll([ |
| 44 | "mocha-teamcity-reporter@$mocha_teamcity_reporter_version"]) |
Roman Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 45 | } |
| 46 | |
Roman Elizarov | f0fc770 | 2018-03-06 12:45:08 +0300 | [diff] [blame] | 47 | def mochaChromeTestPage = file("$buildDir/test-page.html") |
| 48 | |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 49 | task prepareMochaChrome(dependsOn: [compileTestJsLegacy, installDependenciesMochaChrome]) { |
Roman Elizarov | f0fc770 | 2018-03-06 12:45:08 +0300 | [diff] [blame] | 50 | outputs.file(mochaChromeTestPage) |
| 51 | } |
Roman Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 52 | |
| 53 | prepareMochaChrome.doLast { |
Steve Elliott | ca095be | 2022-07-25 14:26:10 +0000 | [diff] [blame] | 54 | def nodeProjDir = node.nodeProjectDir.getAsFile().get() |
Roman Elizarov | f0fc770 | 2018-03-06 12:45:08 +0300 | [diff] [blame] | 55 | mochaChromeTestPage.text = """<!DOCTYPE html> |
| 56 | <html> |
| 57 | <head> |
| 58 | <title>Mocha Tests</title> |
| 59 | <meta charset="utf-8"> |
Steve Elliott | ca095be | 2022-07-25 14:26:10 +0000 | [diff] [blame] | 60 | <link rel="stylesheet" href="$nodeProjDir/node_modules/mocha/mocha.css"> |
Roman Elizarov | f0fc770 | 2018-03-06 12:45:08 +0300 | [diff] [blame] | 61 | </head> |
| 62 | <body> |
| 63 | <div id="mocha"></div> |
Steve Elliott | ca095be | 2022-07-25 14:26:10 +0000 | [diff] [blame] | 64 | <script src="$nodeProjDir/node_modules/mocha/mocha.js"></script> |
Roman Elizarov | f0fc770 | 2018-03-06 12:45:08 +0300 | [diff] [blame] | 65 | <script>mocha.setup('bdd');</script> |
Steve Elliott | ca095be | 2022-07-25 14:26:10 +0000 | [diff] [blame] | 66 | <script src="$nodeProjDir/node_modules/kotlin/kotlin.js"></script> |
| 67 | <script src="$nodeProjDir/node_modules/kotlin-test/kotlin-test.js"></script> |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 68 | <script src="$compileJsLegacy.outputFile"></script> |
| 69 | <script src="$compileTestJsLegacy.outputFile"></script> |
Roman Elizarov | f0fc770 | 2018-03-06 12:45:08 +0300 | [diff] [blame] | 70 | <script>mocha.run();</script> |
| 71 | </body> |
| 72 | </html> |
| 73 | """ |
Roman Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | task testMochaChrome(type: NodeTask, dependsOn: prepareMochaChrome) { |
Steve Elliott | ca095be | 2022-07-25 14:26:10 +0000 | [diff] [blame] | 77 | script = file("${node.nodeProjectDir.getAsFile().get()}/node_modules/mocha-headless-chrome/bin/start") |
| 78 | args = [compileTestJsLegacy.outputFile.path, '--file', mochaChromeTestPage] |
| 79 | if (project.hasProperty("teamcity")) args.addAll(['--reporter', 'mocha-teamcity-reporter']) |
Roman Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 80 | } |
| 81 | |
Roman Elizarov | b1dad17 | 2018-03-05 17:47:10 +0300 | [diff] [blame] | 82 | // todo: Commented out because mocha-headless-chrome does not work on TeamCity |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 83 | //jsTest.dependsOn testMochaChrome |
Roman Elizarov | 5f5107e | 2018-03-05 12:51:23 +0300 | [diff] [blame] | 84 | |
anton.sukhonosenko | bb0ad4a | 2018-11-06 19:46:00 +0300 | [diff] [blame] | 85 | // -- Testing with Mocha under jsdom |
| 86 | |
| 87 | task installDependenciesMochaJsdom(type: NpmTask, dependsOn: [npmInstall]) { |
| 88 | args = ['install', |
| 89 | "mocha@$mocha_version", |
Roman Elizarov | 738f5a2 | 2020-10-12 19:03:46 +0300 | [diff] [blame] | 90 | "jsdom@$jsdom_version", |
| 91 | "jsdom-global@$jsdom_global_version", |
anton.sukhonosenko | bb0ad4a | 2018-11-06 19:46:00 +0300 | [diff] [blame] | 92 | "source-map-support@$source_map_support_version", |
| 93 | '--no-save'] |
Steve Elliott | ca095be | 2022-07-25 14:26:10 +0000 | [diff] [blame] | 94 | if (project.hasProperty("teamcity")) args.addAll(["mocha-teamcity-reporter@$mocha_teamcity_reporter_version"]) |
anton.sukhonosenko | bb0ad4a | 2018-11-06 19:46:00 +0300 | [diff] [blame] | 95 | } |
| 96 | |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 97 | task testMochaJsdom(type: NodeTask, dependsOn: [compileTestJsLegacy, installDependenciesMochaJsdom]) { |
Steve Elliott | ca095be | 2022-07-25 14:26:10 +0000 | [diff] [blame] | 98 | script = file("${node.nodeProjectDir.getAsFile().get()}/node_modules/mocha/bin/mocha") |
| 99 | args = [compileTestJsLegacy.outputFile.path, '--require', 'source-map-support/register', '--require', 'jsdom-global/register'] |
| 100 | if (project.hasProperty("teamcity")) args.addAll(['--reporter', 'mocha-teamcity-reporter']) |
anton.sukhonosenko | bb0ad4a | 2018-11-06 19:46:00 +0300 | [diff] [blame] | 101 | } |
| 102 | |
Ilya Goncharov | 6391089 | 2020-05-28 17:58:48 +0300 | [diff] [blame] | 103 | jsLegacyTestTask.dependsOn testMochaJsdom |
anton.sukhonosenko | bb0ad4a | 2018-11-06 19:46:00 +0300 | [diff] [blame] | 104 | |