You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
4.1 KiB

/*
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
// -- Testing with Mocha under Node
task installDependenciesMochaNode(type: NpmTask, dependsOn: [npmInstall]) {
args = ['install',
"mocha@$mocha_version",
"source-map-support@$source_map_support_version",
'--no-save']
if (project.hasProperty("teamcity")) args += ["mocha-teamcity-reporter@$mocha_teamcity_reporter_version"]
}
def compileJsLegacy = tasks.hasProperty("compileKotlinJsLegacy")
? compileKotlinJsLegacy
: compileKotlinJs
def compileTestJsLegacy = tasks.hasProperty("compileTestKotlinJsLegacy")
? compileTestKotlinJsLegacy
: compileTestKotlinJs
// todo: use atomicfu-transformed test files here (not critical)
task testMochaNode(type: NodeTask, dependsOn: [compileTestJsLegacy, installDependenciesMochaNode]) {
script = file("$node.nodeModulesDir/node_modules/mocha/bin/mocha")
args = [compileTestJsLegacy.outputFile, '--require', 'source-map-support/register']
if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
}
def jsLegacyTestTask = project.tasks.findByName('jsLegacyTest') ? jsLegacyTest : jsTest
jsLegacyTestTask.dependsOn testMochaNode
// -- Testing with Mocha under headless Chrome
task installDependenciesMochaChrome(type: NpmTask, dependsOn: [npmInstall]) {
args = ['install',
"mocha@$mocha_version",
"mocha-headless-chrome@$mocha_headless_chrome_version",
"kotlin@$kotlin_version",
"kotlin-test@$kotlin_version",
'--no-save']
if (project.hasProperty("teamcity")) args += [
"mocha-teamcity-reporter@$mocha_teamcity_reporter_version"]
}
def mochaChromeTestPage = file("$buildDir/test-page.html")
task prepareMochaChrome(dependsOn: [compileTestJsLegacy, installDependenciesMochaChrome]) {
outputs.file(mochaChromeTestPage)
}
prepareMochaChrome.doLast {
mochaChromeTestPage.text = """<!DOCTYPE html>
<html>
<head>
<title>Mocha Tests</title>
<meta charset="utf-8">
<link rel="stylesheet" href="$node.nodeModulesDir/node_modules/mocha/mocha.css">
</head>
<body>
<div id="mocha"></div>
<script src="$node.nodeModulesDir/node_modules/mocha/mocha.js"></script>
<script>mocha.setup('bdd');</script>
<script src="$node.nodeModulesDir/node_modules/kotlin/kotlin.js"></script>
<script src="$node.nodeModulesDir/node_modules/kotlin-test/kotlin-test.js"></script>
<script src="$compileJsLegacy.outputFile"></script>
<script src="$compileTestJsLegacy.outputFile"></script>
<script>mocha.run();</script>
</body>
</html>
"""
}
task testMochaChrome(type: NodeTask, dependsOn: prepareMochaChrome) {
script = file("$node.nodeModulesDir/node_modules/mocha-headless-chrome/bin/start")
args = [compileTestJsLegacy.outputFile, '--file', mochaChromeTestPage]
if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
}
// todo: Commented out because mocha-headless-chrome does not work on TeamCity
//jsTest.dependsOn testMochaChrome
// -- Testing with Mocha under jsdom
task installDependenciesMochaJsdom(type: NpmTask, dependsOn: [npmInstall]) {
args = ['install',
"mocha@$mocha_version",
"jsdom@$jsdom_version",
"jsdom-global@$jsdom_global_version",
"source-map-support@$source_map_support_version",
'--no-save']
if (project.hasProperty("teamcity")) args += ["mocha-teamcity-reporter@$mocha_teamcity_reporter_version"]
}
task testMochaJsdom(type: NodeTask, dependsOn: [compileTestJsLegacy, installDependenciesMochaJsdom]) {
script = file("$node.nodeModulesDir/node_modules/mocha/bin/mocha")
args = [compileTestJsLegacy.outputFile, '--require', 'source-map-support/register', '--require', 'jsdom-global/register']
if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
}
jsLegacyTestTask.dependsOn testMochaJsdom