Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public failTestCase(test: Mocha.Test, error: Error) {
if (this.currentTest === null) {
this.startCase(test);
} else {
const latestStatus = this.currentTest.status;
// if test already has a failed state, we should not overwrite it
if (latestStatus === Status.FAILED || latestStatus === Status.BROKEN) {
return;
}
}
const status = error.name === "AssertionError" ? Status.FAILED : Status.BROKEN;
this.endTest(status, { message: error.message, trace: error.stack });
}
public failTestCase(test: Mocha.Test, error: Error) {
if (this.currentTest === null) {
this.startCase(test);
} else {
const latestStatus = this.currentTest.status;
// if test already has a failed state, we should not overwrite it
if (latestStatus === Status.FAILED || latestStatus === Status.BROKEN) {
return;
}
}
const status = error.name === "AssertionError" ? Status.FAILED : Status.BROKEN;
this.endTest(status, { message: error.message, trace: error.stack });
}
if (spec.status === SpecStatus.PENDING || spec.status === SpecStatus.DISABLED
|| spec.status === SpecStatus.EXCLUDED) {
currentTest.status = Status.SKIPPED;
currentTest.stage = Stage.PENDING;
currentTest.detailsMessage = spec.pendingReason || "Suite disabled";
}
currentTest.stage = Stage.FINISHED;
if (spec.status === SpecStatus.PASSED) {
currentTest.status = Status.PASSED;
}
if (spec.status === SpecStatus.BROKEN) {
currentTest.status = Status.BROKEN;
}
if (spec.status === SpecStatus.FAILED) {
currentTest.status = Status.FAILED;
}
const exceptionInfo = this.findMessageAboutThrow(spec.failedExpectations)
|| this.findAnyError(spec.failedExpectations);
if (exceptionInfo !== null) {
currentTest.detailsMessage = exceptionInfo.message;
currentTest.detailsTrace = exceptionInfo.stack;
}
currentTest.endTest();
this.runningTest = null;
this.currentGroup.endGroup(); // popping the test wrapper
this.groupStack.pop();
}
export function statusTextToAllure(status?: string): Status {
if (status === "passed") return Status.PASSED;
if (status === "skipped") return Status.SKIPPED;
if (status === "failed") return Status.FAILED;
return Status.BROKEN;
}