[Gradle, JS] Add karma debugger by timeout
This commit is contained in:
+13
-5
@@ -238,6 +238,8 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
|
|||||||
val adapterJs = npmProject.dir.resolve("adapter-browser.js")
|
val adapterJs = npmProject.dir.resolve("adapter-browser.js")
|
||||||
adapterJs.printWriter().use { writer ->
|
adapterJs.printWriter().use { writer ->
|
||||||
val karmaRunner = npmProject.require("kotlin-test-js-runner/kotlin-test-karma-runner.js")
|
val karmaRunner = npmProject.require("kotlin-test-js-runner/kotlin-test-karma-runner.js")
|
||||||
|
// It is necessary for debugger attaching (--inspect-brk analogue)
|
||||||
|
writer.println("debugger;")
|
||||||
writer.println("require(${karmaRunner.jsQuoted()})")
|
writer.println("require(${karmaRunner.jsQuoted()})")
|
||||||
|
|
||||||
writer.println("module.exports = require(${file.jsQuoted()})")
|
writer.println("module.exports = require(${file.jsQuoted()})")
|
||||||
@@ -253,6 +255,11 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
|
|||||||
nodeJsArgs: MutableList<String>,
|
nodeJsArgs: MutableList<String>,
|
||||||
debug: Boolean
|
debug: Boolean
|
||||||
): TCServiceMessagesTestExecutionSpec {
|
): TCServiceMessagesTestExecutionSpec {
|
||||||
|
if (debug) {
|
||||||
|
config.client.mocha.timeout = "0"
|
||||||
|
config.singleRun = false
|
||||||
|
}
|
||||||
|
|
||||||
if (config.browsers.isEmpty()) {
|
if (config.browsers.isEmpty()) {
|
||||||
error("No browsers configured for $task")
|
error("No browsers configured for $task")
|
||||||
}
|
}
|
||||||
@@ -306,15 +313,16 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
|
|||||||
|
|
||||||
val nodeModules = listOf("karma/bin/karma")
|
val nodeModules = listOf("karma/bin/karma")
|
||||||
|
|
||||||
|
val karmaConfigAbsolutePath = karmaConfJs.absolutePath
|
||||||
val args = if (debug) {
|
val args = if (debug) {
|
||||||
config.client.mocha.timeout = "0"
|
listOf(
|
||||||
|
npmProject.require("kotlin-test-js-runner/karma-debug.js"),
|
||||||
//TODO need generate it
|
karmaConfigAbsolutePath
|
||||||
listOf("./debugRunner.js")
|
)
|
||||||
} else {
|
} else {
|
||||||
nodeJsArgs +
|
nodeJsArgs +
|
||||||
nodeModules.map { npmProject.require(it) } +
|
nodeModules.map { npmProject.require(it) } +
|
||||||
listOf("start", karmaConfJs.absolutePath)
|
listOf("start", karmaConfigAbsolutePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
return object : JSServiceMessagesTestExecutionSpec(
|
return object : JSServiceMessagesTestExecutionSpec(
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ tasks {
|
|||||||
"nodejs.ts",
|
"nodejs.ts",
|
||||||
"karma.ts",
|
"karma.ts",
|
||||||
"karma-kotlin-reporter.js",
|
"karma-kotlin-reporter.js",
|
||||||
|
"karma-debug.js",
|
||||||
"mocha-kotlin-reporter.js",
|
"mocha-kotlin-reporter.js",
|
||||||
"package.json",
|
"package.json",
|
||||||
"rollup.config.js",
|
"rollup.config.js",
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const karma = require('karma');
|
||||||
|
|
||||||
|
const cfg = karma.config;
|
||||||
|
|
||||||
|
const karmaConfig = cfg.parseConfig(process.argv[2]);
|
||||||
|
|
||||||
|
const Server = karma.Server;
|
||||||
|
const server = new Server(karmaConfig, function (exitCode) {
|
||||||
|
console.log('Karma has exited with ' + exitCode);
|
||||||
|
});
|
||||||
|
|
||||||
|
server.on('browsers_ready', function () {
|
||||||
|
// It is unreliable decision, but we need some delay for debugger attaching
|
||||||
|
setTimeout(function () {
|
||||||
|
karma.runner.run(karmaConfig, function (exitCode) {
|
||||||
|
console.log('Runner has exited with ' + exitCode);
|
||||||
|
karma.stopper.stop(karmaConfig, function (exitCode) {
|
||||||
|
console.log('Stopper has exited with ' + exitCode);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}, 1000)
|
||||||
|
});
|
||||||
|
|
||||||
|
server.start();
|
||||||
@@ -25,6 +25,13 @@ export default [
|
|||||||
},
|
},
|
||||||
plugins: plugins()
|
plugins: plugins()
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: './karma-debug.js',
|
||||||
|
output: {
|
||||||
|
file: 'lib/karma-debug.js',
|
||||||
|
format: 'cjs'
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
input: './karma-kotlin-reporter.js',
|
input: './karma-kotlin-reporter.js',
|
||||||
external: ['path', 'util'],
|
external: ['path', 'util'],
|
||||||
|
|||||||
@@ -4,8 +4,7 @@
|
|||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true
|
||||||
"inlineSourceMap": true
|
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"**/*Debug.ts"
|
"**/*Debug.ts"
|
||||||
|
|||||||
Reference in New Issue
Block a user