1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
/*
* 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: [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
|