@stryker-mutator/jest-runner
Version:
A plugin to use the jest test runner and framework in Stryker, the JavaScript mutation testing framework
53 lines • 2.42 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.mixinJestEnvironment = mixinJestEnvironment;
const messaging_cjs_1 = require("./messaging.cjs");
function fullNameDescribeBlock(describe) {
if (describe.parent) {
const parentName = fullNameDescribeBlock(describe.parent);
return `${parentName} ${describe.name}`.trimStart();
}
else {
return ''; // describe.name === "ROOT_DESCRIBE_BLOCK"
}
}
function fullName(test) {
const suiteName = fullNameDescribeBlock(test.parent);
return `${suiteName} ${test.name}`.trimStart();
}
const STRYKER_JEST_ENV = Symbol('StrykerJestEnvironment');
function mixinJestEnvironment(JestEnvironmentClass) {
if (JestEnvironmentClass[STRYKER_JEST_ENV]) {
return JestEnvironmentClass;
}
else {
class StrykerJestEnvironment extends JestEnvironmentClass {
/**
* The shared instrumenter context with the test environment (the `__stryker__` global variable)
*/
#strykerContext;
#innerHandleTestEvent;
static [STRYKER_JEST_ENV] = true;
constructor(config, context) {
super(config, context);
this.#innerHandleTestEvent = this.handleTestEvent; // grab the "handle test event", since it might be a class property
this.#strykerContext = this.global[this.global.__strykerGlobalNamespace__ ?? '__stryker__'] = messaging_cjs_1.state.instrumenterContext;
messaging_cjs_1.state.testFilesWithStrykerEnvironment.add(context.testPath);
this.handleTestEvent = (async (event, eventState) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
await this.#innerHandleTestEvent?.(event, eventState);
if (messaging_cjs_1.state.coverageAnalysis === 'perTest') {
if (event.name === 'test_start') {
this.#strykerContext.currentTestId = fullName(event.test);
}
else if (event.name === 'test_done') {
this.#strykerContext.currentTestId = undefined;
}
}
});
}
}
return StrykerJestEnvironment;
}
}
//# sourceMappingURL=mixin-jest-environment.cjs.map
;