Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async run(options: RunOptions): Promise {
this.setNodeEnv();
const { results } = await this.jestTestAdapter.run(
this.jestConfig,
process.cwd(),
this.enableFindRelatedTests ? options.mutatedFileName : undefined
);
// Get the non-empty errorMessages from the jest RunResult, it's safe to cast to Array here because we filter the empty error messages
const errorMessages = results.testResults
.map((testSuite: jest.TestResult) => testSuite.failureMessage)
.filter(errorMessage => errorMessage) as string[];
return {
errorMessages,
status: results.numRuntimeErrorTestSuites > 0 ? RunStatus.Error : RunStatus.Complete,
tests: this.processTestResults(results.testResults)
};
}
private determineRunState() {
// Karma will report an Error if no tests had executed.
// This is not an "error" in Stryker terms
if (this.currentRunStatus === RunStatus.Error && !this.currentErrorMessages.length && !this.currentTestResults.length) {
return RunStatus.Complete;
} else if (this.currentErrorMessages.length) {
// Karma will return Complete when there are runtime errors
return RunStatus.Error;
} else {
return this.currentRunStatus;
}
}
}
function completeResult(exitCode: number | null, timer: Timer): RunResult {
const duration = timer.elapsedMs();
if (exitCode === 0) {
return {
status: RunStatus.Complete,
tests: [
{
name: 'All tests',
status: TestStatus.Success,
timeSpentMs: duration
}
]
};
} else {
return {
status: RunStatus.Complete,
tests: [
{
failureMessages: [output.map(buf => buf.toString()).join(os.EOL)],
name: 'All tests',
status: TestStatus.Failed,
timeSpentMs: duration
}
]
};
}
}
});
return new Promise(r => r({
coverage,
status: RunStatus.Complete,
tests: [{
failureMessages: [''],
name: '',
status: TestStatus.Failed,
timeSpentMs: 23
}]
}));
}
this.runner.on('end', () => {
this.runResult.status = RunStatus.Complete;
StrykerMochaReporter.log.debug('Mocha test run completed: %s/%s passed', this.passedCount, this.runResult.tests.length);
});
}
jasmineDone() {
resolve({
errorMessages: [],
status: RunStatus.Complete,
tests
});
}
};
public async run(): Promise {
this.reporter.results = [];
try {
await steps.runTests(this.context).catch(WctTestRunner.ignoreFailedTests);
return {
status: RunStatus.Complete,
tests: this.reporter.results
};
} catch (error) {
return {
errorMessages: [error.stack],
status: RunStatus.Error,
tests: []
};
}
}
private collectRunState(runResult: karma.TestResults): RunStatus {
if (runResult.disconnected) {
return RunStatus.Timeout;
} else if (runResult.error) {
return RunStatus.Error;
} else {
return RunStatus.Complete;
}
}
}
private cleanRun() {
this.currentTestResults = [];
this.currentErrorMessages = [];
this.currentCoverageReport = undefined;
this.currentRunStatus = RunStatus.Complete;
}