Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
}
}
public async run({ testHooks }: { testHooks?: string }): Promise {
this.testHooksMiddleware.currentTestHooks = testHooks || '';
if (this.currentRunStatus !== RunStatus.Error) {
// Only run when there was no compile error
// An compile error can happen in case of angular-cli
await this.runServer();
}
const runResult = this.collectRunResult();
this.cleanRun();
return runResult;
}
if (attemptsLeft > 0) {
try {
return await this.innerRunner.run(options);
} catch (error) {
if (error instanceof OutOfMemoryError) {
this.log.info(
"Test runner process [%s] ran out of memory. You probably have a memory leak in your tests. Don't worry, Stryker will restart the process, but you might want to investigate this later, because this decreases performance.",
error.pid
);
}
await this.recover();
return this.run(options, attemptsLeft - 1, error);
}
} else {
await this.recover();
return { status: RunStatus.Error, errorMessages: [`${ERROR_MESSAGE}${errorToString(lastError)}`], tests: [] };
}
}
private collectRunState(runResult: karma.TestResults): RunStatus {
if (runResult.disconnected) {
return RunStatus.Timeout;
} else if (runResult.error) {
return RunStatus.Error;
} else {
return RunStatus.Complete;
}
}
}
}).catch(error => ({
errorMessages: [`An error occurred while loading your jasmine specs${EOL}${errorToString(error)}`],
status: RunStatus.Error,
tests: []
}));
}
private determineMutantState(runResult: RunResult): MutantStatus {
switch (runResult.status) {
case RunStatus.Timeout:
return MutantStatus.TimedOut;
case RunStatus.Error:
return MutantStatus.RuntimeError;
case RunStatus.Complete:
if (runResult.tests.some(t => t.status === TestStatus.Failed)) {
return MutantStatus.Killed;
} else {
return MutantStatus.Survived;
}
}
}
mocha.run(() => {
const reporter = StrykerMochaReporter.currentInstance;
if (reporter) {
const result: RunResult = reporter.runResult;
resolve(result);
} else {
const errorMsg = 'The StrykerMochaReporter was not instantiated properly. Could not retrieve the RunResult.';
this.log.error(errorMsg);
resolve({
errorMessages: [errorMsg],
status: RunStatus.Error,
tests: []
});
}
});
} catch (error) {