[JS] Implement strategy with adapterTransformer on global object to mutate adapter of kotlin-test
This commit is contained in:
@@ -65,11 +65,26 @@ internal fun adapter(): FrameworkAdapter {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsName("kotlinTest")
|
||||||
|
external val kotlinTestNamespace: KotlinTestNamespace
|
||||||
|
|
||||||
internal fun detectAdapter() = when {
|
external interface KotlinTestNamespace {
|
||||||
isQUnit() -> QUnitAdapter()
|
val adapterTransformer: ((FrameworkAdapter) -> FrameworkAdapter)?
|
||||||
isJasmine() -> JasmineLikeAdapter()
|
}
|
||||||
else -> BareAdapter()
|
|
||||||
|
internal fun detectAdapter(): FrameworkAdapter {
|
||||||
|
val frameworkAdapter = when {
|
||||||
|
isQUnit() -> QUnitAdapter()
|
||||||
|
isJasmine() -> JasmineLikeAdapter()
|
||||||
|
else -> BareAdapter()
|
||||||
|
}
|
||||||
|
return if (jsTypeOf(kotlinTestNamespace) != "undefined") {
|
||||||
|
val adapterTransform = kotlinTestNamespace
|
||||||
|
.adapterTransformer
|
||||||
|
if (adapterTransform !== null) {
|
||||||
|
adapterTransform(frameworkAdapter)
|
||||||
|
} else frameworkAdapter
|
||||||
|
} else frameworkAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val NAME_TO_ADAPTER: Map<String, () -> FrameworkAdapter> = mapOf(
|
internal val NAME_TO_ADAPTER: Map<String, () -> FrameworkAdapter> = mapOf(
|
||||||
|
|||||||
@@ -5,28 +5,25 @@
|
|||||||
|
|
||||||
import {CliArgsParser, getDefaultCliDescription} from "./src/CliArgsParser";
|
import {CliArgsParser, getDefaultCliDescription} from "./src/CliArgsParser";
|
||||||
import {runWithFilteringAndConsoleAdapters} from "./src/Adapter";
|
import {runWithFilteringAndConsoleAdapters} from "./src/Adapter";
|
||||||
|
import {KotlinTestRunner} from "./src/KotlinTestRunner";
|
||||||
|
|
||||||
let kotlin_test
|
const parser = new CliArgsParser(
|
||||||
try {
|
getDefaultCliDescription(),
|
||||||
kotlin_test = require('kotlin-test');
|
(exitCode) => {
|
||||||
} catch {
|
throw new Error(`Exit with ${exitCode}`)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const untypedArgs = parser.parse(window.__karma__.config.args);
|
||||||
|
|
||||||
|
const adapterTransformer: (current: KotlinTestRunner) => KotlinTestRunner = current =>
|
||||||
|
runWithFilteringAndConsoleAdapters(current, untypedArgs);
|
||||||
|
|
||||||
|
window.kotlinTest = {
|
||||||
|
adapterTransformer: adapterTransformer
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kotlin_test) {
|
const resultFun = window.__karma__.result;
|
||||||
const parser = new CliArgsParser(
|
window.__karma__.result = function (result) {
|
||||||
getDefaultCliDescription(),
|
console.log(`--END_KOTLIN_TEST--\n${JSON.stringify(result)}`);
|
||||||
(exitCode) => {
|
resultFun(result)
|
||||||
throw new Error(`Exit with ${exitCode}`)
|
};
|
||||||
}
|
|
||||||
);
|
|
||||||
const untypedArgs = parser.parse(window.__karma__.config.args);
|
|
||||||
|
|
||||||
const initialAdapter = kotlin_test.kotlin.test.detectAdapter_8be2vx$();
|
|
||||||
kotlin_test.setAdapter(runWithFilteringAndConsoleAdapters(initialAdapter, untypedArgs));
|
|
||||||
|
|
||||||
const resultFun = window.__karma__.result;
|
|
||||||
window.__karma__.result = function (result) {
|
|
||||||
console.log(`--END_KOTLIN_TEST--\n${JSON.stringify(result)}`);
|
|
||||||
resultFun(result)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,19 +1,16 @@
|
|||||||
import {CliArgsParser, getDefaultCliDescription} from "./src/CliArgsParser";
|
import {CliArgsParser, getDefaultCliDescription} from "./src/CliArgsParser";
|
||||||
import {runWithFilteringAndConsoleAdapters} from "./src/Adapter";
|
import {runWithFilteringAndConsoleAdapters} from "./src/Adapter";
|
||||||
|
import {KotlinTestRunner} from "./src/KotlinTestRunner";
|
||||||
|
|
||||||
let kotlin_test
|
const parser = new CliArgsParser(
|
||||||
try {
|
getDefaultCliDescription(),
|
||||||
kotlin_test = require('kotlin-test');
|
process.exit
|
||||||
} catch {
|
);
|
||||||
}
|
const untypedArgs = parser.parse(process.argv);
|
||||||
|
|
||||||
if (kotlin_test) {
|
const adapterTransformer: (current: KotlinTestRunner) => KotlinTestRunner = current =>
|
||||||
const parser = new CliArgsParser(
|
runWithFilteringAndConsoleAdapters(current, untypedArgs);
|
||||||
getDefaultCliDescription(),
|
|
||||||
process.exit
|
|
||||||
);
|
|
||||||
const untypedArgs = parser.parse(process.argv);
|
|
||||||
|
|
||||||
const initialAdapter = kotlin_test.kotlin.test.detectAdapter_8be2vx$();
|
(globalThis as any).kotlinTest = {
|
||||||
kotlin_test.setAdapter(runWithFilteringAndConsoleAdapters(initialAdapter, untypedArgs));
|
adapterTransformer: adapterTransformer
|
||||||
}
|
}
|
||||||
+14
-6
@@ -3,12 +3,20 @@
|
|||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* 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 {
|
import {KotlinTestRunner} from "./src/KotlinTestRunner";
|
||||||
__karma__: {
|
|
||||||
config: {
|
declare global {
|
||||||
args: string[]
|
interface Window {
|
||||||
},
|
__karma__: {
|
||||||
result: (result: BrowserResult) => void
|
config: {
|
||||||
|
args: string[]
|
||||||
|
},
|
||||||
|
result: (result: BrowserResult) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlinTest: {
|
||||||
|
adapterTransformer: (current: KotlinTestRunner) => KotlinTestRunner
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user