@stryker-mutator/core
Version:
The extendable JavaScript mutation testing framework
58 lines • 1.96 kB
JavaScript
import os from 'os';
import fs from 'fs';
import { CheckStatus } from '@stryker-mutator/api/check';
import { declareClassPlugin, PluginKind } from '@stryker-mutator/api/plugin';
import { factory } from '@stryker-mutator/test-helpers';
class HealthyChecker {
async init() {
// Init
}
async check([mutant]) {
return { [mutant.id]: mutant.id === '1' ? { status: CheckStatus.Passed } : { status: CheckStatus.CompileError, reason: 'Id is not 1 🤷♂️' } };
}
}
class CrashingChecker {
async init() {
// Init
}
async check(_) {
throw new Error('Always crashing');
}
}
export class TwoTimesTheCharm {
async init() {
// Init
}
async check(mutants) {
let count = +(await fs.promises.readFile(TwoTimesTheCharm.COUNTER_FILE, 'utf-8'));
count++;
await fs.promises.writeFile(TwoTimesTheCharm.COUNTER_FILE, count.toString(), 'utf-8');
if (count >= 2) {
return { [mutants[0].id]: { status: CheckStatus.Passed } };
}
else {
process.exit(count);
}
}
}
TwoTimesTheCharm.COUNTER_FILE = `${os.tmpdir()}/stryker-js-two-times-the-charm-checker-file`;
export class VerifyTitle {
async init() {
// Init
}
async check([mutant]) {
if (mutant.fileName === process.title) {
return { [mutant.id]: factory.checkResult({ status: CheckStatus.Passed }) };
}
else {
return { [mutant.id]: factory.checkResult({ status: CheckStatus.CompileError }) };
}
}
}
export const strykerPlugins = [
declareClassPlugin(PluginKind.Checker, 'healthy', HealthyChecker),
declareClassPlugin(PluginKind.Checker, 'crashing', CrashingChecker),
declareClassPlugin(PluginKind.Checker, 'two-times-the-charm', TwoTimesTheCharm),
declareClassPlugin(PluginKind.Checker, 'verify-title', VerifyTitle),
];
//# sourceMappingURL=additional-checkers.js.map