blob: 006864ba1cf3a29a594853917aefb8a3d658c646 [file] [log] [blame]
/*
* Copyright 2016-2018 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"]
}
// todo: use atomicfu-transformed test files here (not critical)
task testMochaNode(type: NodeTask, dependsOn: [compileTestKotlinJs, installDependenciesMochaNode]) {
script = file("$node.nodeModulesDir/node_modules/mocha/bin/mocha")
args = [compileTestKotlinJs.outputFile, '--require', 'source-map-support/register']
if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
}
jsTest.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: [compileTestKotlinJs, 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="$compileKotlinJs.outputFile"></script>
<script src="$compileTestKotlinJs.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 = [compileTestKotlinJs.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-global',
"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: [compileTestKotlinJs, installDependenciesMochaJsdom]) {
script = file("$node.nodeModulesDir/node_modules/mocha/bin/mocha")
args = [compileTestKotlinJs.outputFile, '--require', 'source-map-support/register', '--require', 'jsdom-global/register']
if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
}
jsTest.dependsOn testMochaJsdom