@stryker-mutator/core
Version:
The extendable JavaScript mutation testing framework
77 lines • 2.6 kB
JavaScript
import { PlanKind, } from '@stryker-mutator/api/core';
import { Timer } from '../utils/timer.js';
export class ProgressKeeper {
timer;
timing;
capabilities;
ticksByMutantId;
progress = {
survived: 0,
timedOut: 0,
tested: 0,
mutants: 0,
total: 0,
ticks: 0,
};
onDryRunCompleted({ timing, capabilities, }) {
this.timing = timing;
this.capabilities = capabilities;
}
/**
* An event emitted when the mutant test plan is calculated.
* @param event The mutant test plan ready event
*/
onMutationTestingPlanReady({ mutantPlans, }) {
this.timer = new Timer();
this.ticksByMutantId = new Map(mutantPlans.filter(isRunPlan).map(({ netTime, mutant, runOptions }) => {
let ticks = netTime;
if (!this.capabilities.reloadEnvironment &&
runOptions.reloadEnvironment) {
ticks += this.timing.overhead;
}
return [mutant.id, ticks];
}));
this.progress.mutants = this.ticksByMutantId.size;
this.progress.total = [...this.ticksByMutantId.values()].reduce((acc, n) => acc + n, 0);
}
onMutantTested(result) {
const ticks = this.ticksByMutantId.get(result.id);
if (ticks !== undefined) {
this.progress.tested++;
this.progress.ticks += this.ticksByMutantId.get(result.id) ?? 0;
if (result.status === 'Survived') {
this.progress.survived++;
}
if (result.status === 'Timeout') {
this.progress.timedOut++;
}
}
return ticks ?? 0;
}
getElapsedTime() {
return this.formatTime(this.timer.elapsedSeconds());
}
getEtc() {
const totalSecondsLeft = Math.floor((this.timer.elapsedSeconds() / this.progress.ticks) *
(this.progress.total - this.progress.ticks));
if (isFinite(totalSecondsLeft) && totalSecondsLeft > 0) {
return this.formatTime(totalSecondsLeft);
}
else {
return 'n/a';
}
}
formatTime(timeInSeconds) {
const hours = Math.floor(timeInSeconds / 3600);
const minutes = Math.floor((timeInSeconds % 3600) / 60);
return hours > 0 // conditional time formatting
? `~${hours}h ${minutes}m`
: minutes > 0
? `~${minutes}m`
: '<1m';
}
}
function isRunPlan(mutantPlan) {
return mutantPlan.plan === PlanKind.Run;
}
//# sourceMappingURL=progress-keeper.js.map