Add karma input for kotlin-test-nodejs-runner

- To set custom adapter for kotlin-test, it is necessary to inject adapting
code to webpack's input, so then it is executed inside browser and set
custom adapter
This code will be injected to webpack's input
This commit is contained in:
Ilya Goncharov
2019-09-18 15:50:33 +03:00
parent e242856124
commit e750bd302d
6 changed files with 98 additions and 40 deletions
@@ -45,6 +45,7 @@ tasks {
inputs.dir("src")
inputs.files(
"cli.ts",
"karma.ts",
"nodejs-source-map-support.js",
"package.json",
"rollup.config.js",
+25
View File
@@ -0,0 +1,25 @@
/*
* 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.
*/
import {CliArgsParser, getDefaultCliDescription} from "./src/CliArgsParser";
import {getAdapter} from "./src/Adapter";
const kotlin_test = require('kotlin-test');
process.hrtime = require('browser-process-hrtime');
process.exit = (exitCode) => {
throw new Error(`Exit with ${exitCode}`)
};
const processArgs = window.__karma__.config.args;
const cliDescription = getDefaultCliDescription();
cliDescription.freeArgsTitle = null;
const parser = new CliArgsParser(cliDescription);
const untypedArgs = parser.parse(processArgs);
const initialAdapter = kotlin_test.kotlin.test.detectAdapter_8be2vx$();
kotlin_test.setAdapter(getAdapter(initialAdapter, untypedArgs));
@@ -15,7 +15,8 @@
},
"dependencies": {
"@types/node": "^10.12.21",
"source-map-support": "^0.5.11"
"source-map-support": "^0.5.11",
"browser-process-hrtime": "^1.0.0"
},
"devDependencies": {
"copyfiles": "^2.1.0",
@@ -14,44 +14,7 @@ export default [
banner: '#!/usr/bin/env node',
sourcemap: true
},
plugins: [
nodeResolve({
jsnext: true,
main: true
}),
commonjs(),
typescript({
tsconfig: "tsconfig.json"
}),
uglify({
sourcemap: true,
compress: {
// hoist_funs: true,
// hoist_vars: true,
toplevel: true,
unsafe: true,
dead_code: true,
global_defs: {
DEBUG: false,
VERSION: pckg.version,
BIN: Object.keys(pckg.bin)[0],
DESCRIPTION: pckg.description
}
},
mangle: {
properties: {
keep_quoted: true,
reserved: [
"argv", "hrtime",
"kotlin_test", "kotlin", "setAdapter", "setAssertHook_4duqou$",
"suite", "test",
"stack"
]
},
toplevel: true,
}
})
]
plugins: plugins()
},
{
input: './nodejs-source-map-support.js',
@@ -72,5 +35,56 @@ export default [
sourcemap: true
})
]
},
{
input: './karma.ts',
output: {
file: 'lib/kotlin-test-karma-runner.js',
format: 'cjs',
sourcemap: true
},
plugins: plugins()
}
]
]
function plugins() {
return [
nodeResolve({
jsnext: true,
main: true
}),
commonjs(),
typescript({
tsconfig: "tsconfig.json"
}),
uglify({
sourcemap: true,
compress: {
// hoist_funs: true,
// hoist_vars: true,
toplevel: true,
unsafe: true,
dead_code: true,
global_defs: {
DEBUG: false,
VERSION: pckg.version,
BIN: Object.keys(pckg.bin)[0],
DESCRIPTION: pckg.description
}
},
mangle: {
properties: {
keep_quoted: true,
reserved: [
"argv", "hrtime",
"kotlin_test", "kotlin", "setAdapter", "setAssertHook_4duqou$", "detectAdapter_8be2vx$",
"__karma__", "config", "args",
"suite", "test",
"stack"
]
},
toplevel: true,
}
})
]
}
+12
View File
@@ -0,0 +1,12 @@
/*
* 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.
*/
interface Window {
__karma__: {
config: {
args: string[]
}
}
}
@@ -101,6 +101,11 @@ braces@^1.8.2:
preserve "^0.2.0"
repeat-element "^1.1.2"
browser-process-hrtime@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/browser-process-hrtime/-/browser-process-hrtime-1.0.0.tgz#3c9b4b7d782c8121e56f10106d84c0d0ffc94626"
integrity sha512-9o5UecI3GhkpM6DrXr69PblIuWxPKk9Y0jHBRhdocZ2y7YECBFCsHm79Pr3OyR2AvjhDkabFJaDJMYRazHgsow==
buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"