diff --git a/.travis.yml b/.travis.yml index 1264e52..5d04291 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ language: node_js node_js: - '8' -script: npm t \ No newline at end of file +script: make ci \ No newline at end of file diff --git a/Makefile b/Makefile index c031279..624507b 100644 --- a/Makefile +++ b/Makefile @@ -16,4 +16,7 @@ dogfood: compile rm -rf ./.perturb node ./lib/cli -s lib +ci: compile + node ./lib/cli -s lib -k 85 + .PHONY: test example diff --git a/src/cli.ts b/src/cli.ts index abe0a9e..4394a3d 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -22,7 +22,7 @@ program .option("-x, --testGlob ", "glob for selecting files in test directory") .option("-y, --sourceGlob ", "glob for selecting files in source directory") .option("-c, --testCmd ", "test command") - .option("-k, --killRate", "minimum kill rate to exit with code 0") + .option("-k, --killRateMin ", "minimum kill rate to exit with code 0", parseInt) .option("-u, --runner ", "name of runner or runner plugin") .parse(process.argv); @@ -40,6 +40,7 @@ const args: OptionalPerturbConfig = R.pickBy(R.complement(R.isNil), { sourceGlob: program.sourceGlob, testCmd: program.testCmd, runner: program.runner, + killRateMin: program.killRateMin, }); // sync errors inside perturb don't seem to properly cause a non-zero exit w/o this @@ -55,6 +56,16 @@ process.on("unhandledRejection", (err) => { // start! (async function main() { - const results = await perturb(args); + const { results, config } = await perturb(args); console.log("DONE -- COUNT:", results.length); + + const killed = results.filter(r => r.error); + const killRate = Number((killed.length / results.length).toFixed(4)) * 100; + + if (killRate < config.killRateMin) { + console.error(`❌ Mutant kill rate was ${killRate} which is below minimum acceptable value ${config.killRateMin}`) + process.exitCode = 1; + } else { + console.log(`✅ Mutant kill rate was ${killRate} which is above minimum acceptable value ${config.killRateMin}`) + } })(); \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index b30c50c..0c195fc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,22 +30,22 @@ export default async function perturb(inputCfg: OptionalPerturbConfig) { "*********************************************************\n", ); - const cfg = makeConfig(inputCfg); + const config = makeConfig(inputCfg); - console.log("init with config\n", cfg); + console.log("init with config\n", config); - const { setup, teardown, paths } = fileSystem(cfg); + const { setup, teardown, paths } = fileSystem(config); - const matcher = getMatcher(cfg); - const runner = getRunner(cfg.runner); - const reporter = getReporter(cfg.reporter); + const matcher = getMatcher(config); + const runner = getRunner(config.runner); + const reporter = getReporter(config.reporter); const handler = makeMutantHandler(runner, reporter); const locator = locateMutants(mutators.getMutatorsForNode); - // const testRun: Promise = process.env.SKIP_TEST ? Promise.resolve() : runTest(cfg); + // const testRun: Promise = process.env.SKIP_TEST ? Promise.resolve() : runTest(config); // first run the tests, otherwise why bother at all? - await spawnP(cfg.testCmd); + await spawnP(config.testCmd); try { // then, set up the "shadow" file system that we'll work against @@ -109,7 +109,7 @@ export default async function perturb(inputCfg: OptionalPerturbConfig) { const metadata = { duration }; if (reporter.onFinish) { - reporter.onFinish(results, cfg, metadata); + reporter.onFinish(results, config, metadata); } // TODO -- provide some run metadata here: @@ -117,7 +117,7 @@ export default async function perturb(inputCfg: OptionalPerturbConfig) { // runner: string // sourceCount: number - return results; + return { results, config }; } finally { await teardown(); } diff --git a/src/make-config.ts b/src/make-config.ts index d3e093d..db4b301 100644 --- a/src/make-config.ts +++ b/src/make-config.ts @@ -21,6 +21,8 @@ const defaultConfig: PerturbConfig = { reporter: "diff", matcher: DEFAULT_MATCHER, runner: DEFAULT_RUNNER, + + killRateMin: 0, }; export default function makeConfig(userConfig: OptionalPerturbConfig = {}): PerturbConfig { diff --git a/src/types.ts b/src/types.ts index 45fac65..8e7e030 100644 --- a/src/types.ts +++ b/src/types.ts @@ -91,6 +91,8 @@ export interface PerturbConfig { sourceGlob: string; testGlob: string; + + killRateMin: number; } export type OptionalPerturbConfig = Partial;