blob: f8a4d4800dfbc5eba3e6a9e61e935b64df053489 [file] [log] [blame]
// -- 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"]
}
task testMochaNode(type: NodeTask, dependsOn: [compileTestKotlin2Js, installDependenciesMochaNode]) {
script = file("$node.nodeModulesDir/node_modules/mocha/bin/mocha")
args = [compileTestKotlin2Js.outputFile, '--require', 'source-map-support/register']
if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
if (project.hasProperty("mochaTests")) args += ['--grep', "$mochaTests"]
}
test.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: [compileTestKotlin2Js, 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="$compileKotlin2Js.outputFile"></script>
<script src="$compileTestKotlin2Js.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 = [compileTestKotlin2Js.outputFile, '--file', mochaChromeTestPage]
if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
if (project.hasProperty("mochaTests")) args += ['--grep', "$mochaTests"]
}
// todo: Commented out because mocha-headless-chrome does not work on TeamCity
//test.dependsOn testMochaChrome