Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private readonly retrieveEarlyResult = (transpiledMutant: TranspiledMutant): MutantResult | null => {
if (transpiledMutant.transpileResult.error) {
if (this.log.isDebugEnabled()) {
this.log.debug(
`Transpile error occurred: "${transpiledMutant.transpileResult.error}" during transpiling of mutant ${transpiledMutant.mutant.toString()}`
);
}
const result = transpiledMutant.mutant.createResult(MutantStatus.TranspileError, []);
return result;
} else if (!transpiledMutant.mutant.runAllTests && !transpiledMutant.mutant.selectedTests.length) {
const result = transpiledMutant.mutant.createResult(MutantStatus.NoCoverage, []);
return result;
} else if (!transpiledMutant.changedAnyTranspiledFiles) {
const result = transpiledMutant.mutant.createResult(MutantStatus.Survived, []);
return result;
} else {
// No early result possible, need to run in the sandbox later
return null;
}
};
case MutantStatus.TimedOut:
this.log.debug(chalk.bold.yellow('Mutant timed out!'));
this.logMutantResult(result, index, logDebugFn);
break;
case MutantStatus.RuntimeError:
this.log.debug(chalk.bold.yellow('Mutant caused a runtime error!'));
this.logMutantResult(result, index, logDebugFn);
break;
case MutantStatus.TranspileError:
this.log.debug(chalk.bold.yellow('Mutant caused a transpile error!'));
this.logMutantResult(result, index, logDebugFn);
break;
case MutantStatus.Survived:
this.logMutantResult(result, index, writeLineFn);
break;
case MutantStatus.NoCoverage:
this.logMutantResult(result, index, writeLineFn);
break;
}
});
this.writeLine(`Ran ${(totalTests / mutantResults.length).toFixed(2)} tests per mutant on average.`);
function getContextClassForStatus(status: MutantStatus) {
switch (status) {
case MutantStatus.Killed:
return 'success';
case MutantStatus.NoCoverage:
case MutantStatus.Survived:
return 'danger';
case MutantStatus.TimedOut:
return 'warning';
case MutantStatus.RuntimeError:
case MutantStatus.TranspileError:
return 'secondary';
}
}
private countNumbers(mutantResults: MutantResult[]) {
const count = (mutantResult: MutantStatus) => mutantResults.filter(_ => _.status === mutantResult).length;
const killed = count(MutantStatus.Killed);
const timedOut = count(MutantStatus.TimedOut);
const survived = count(MutantStatus.Survived);
const noCoverage = count(MutantStatus.NoCoverage);
const runtimeErrors = count(MutantStatus.RuntimeError);
const transpileErrors = count(MutantStatus.TranspileError);
const totalDetected = timedOut + killed;
const totalUndetected = survived + noCoverage;
const totalCovered = totalDetected + survived;
const totalValid = totalUndetected + totalDetected;
const totalInvalid = runtimeErrors + transpileErrors;
const totalMutants = totalValid + totalInvalid;
const mutationScore = totalValid > 0 ? (totalDetected / totalValid) * 100 : defaultScoreIfNoValidMutants;
const mutationScoreBasedOnCoveredCode = totalValid > 0 ? (totalDetected / totalCovered) * 100 || 0 : defaultScoreIfNoValidMutants;
return {
killed,
mutationScore,
mutationScoreBasedOnCoveredCode,
noCoverage,
runtimeErrors,
private toStatus(status: MutantStatus): mutationTestReportSchema.MutantStatus {
switch (status) {
case MutantStatus.Killed:
return mutationTestReportSchema.MutantStatus.Killed;
case MutantStatus.NoCoverage:
return mutationTestReportSchema.MutantStatus.NoCoverage;
case MutantStatus.RuntimeError:
return mutationTestReportSchema.MutantStatus.RuntimeError;
case MutantStatus.Survived:
return mutationTestReportSchema.MutantStatus.Survived;
case MutantStatus.TimedOut:
return mutationTestReportSchema.MutantStatus.Timeout;
case MutantStatus.TranspileError:
return mutationTestReportSchema.MutantStatus.CompileError;
default:
this.logUnsupportedMutantStatus(status);
return mutationTestReportSchema.MutantStatus.RuntimeError;
}
}
const filtered = mutants.filter(mutant => mutant.status === state);
if (filtered.length) {
return <div class="form-check form-check-inline">
<label class="form-check-label">
<input type="checkbox" value="{state.toString()}" checked="{isChecked}" class="form-check-input stryker-display">
{MutantStatus[state]} {`(${filtered.length})`}
</label>
</div>;
} else {
return '';
}
}
return <div class="row legend">
<form novalidate="novalidate" class="col-md-12">
{displayCheckbox(MutantStatus.NoCoverage, true)}
{displayCheckbox(MutantStatus.Survived, true)}
{displayCheckbox(MutantStatus.Killed, false)}
{displayCheckbox(MutantStatus.TimedOut, false)}
{displayCheckbox(MutantStatus.RuntimeError, false)}
{displayCheckbox(MutantStatus.TranspileError, false)}
<a class="stryker-collapse-expand-all" href="#">Expand all</a>
</form>
</div>;
}