Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function serenityResultFrom(stepStatus: string, error?: Error): Result {
const timeOut = (e: Error) => e && /timed out/.test(e.message);
const results = {
undefined: Result.PENDING,
ambiguous: Result.ERROR,
failed: Result.FAILURE,
pending: Result.PENDING,
passed: Result.SUCCESS,
skipped: Result.SKIPPED,
};
if (! results[stepStatus]) {
throw new Error(`Couldn't map '${ stepStatus }' to a Serenity Result`);
}
return timeOut(error)
? Result.ERROR
: results[stepStatus];
}
const timeOut = (e: Error) => e && /timed out/.test(e.message);
const results = {
undefined: Result.PENDING,
failed: Result.FAILURE,
pending: Result.PENDING,
passed: Result.SUCCESS,
skipped: Result.SKIPPED,
};
if (! results[stepStatus]) {
throw new Error(`Couldn't map the '${ stepStatus }' to a Serenity Result`);
}
return timeOut(error)
? Result.ERROR
: results[stepStatus];
}
function finalStateOf(scenario: ExecutedScenario): Result {
if (scenario.pending) {
return Result.PENDING;
}
if (scenario.state === 'passed') {
return Result.SUCCESS;
}
if (timedOut(scenario) || hasErrors(scenario)) {
return Result.ERROR;
}
if (scenario.state === 'failed') {
return Result.FAILURE;
}
return Result.COMPROMISED;
}
return expect(spawned.result).to.be.eventually.rejected.then(() => {
expect(spawned.messages).to.have.length.greaterThan(2);
const event = lastOf(SceneFinished, spawned.messages);
expect(Result[event.value.result]).to.equal(Result[Result.ERROR]);
expect(event.value.error.message).to.match(/Timeout of 5ms exceeded./);
});
});
return expect(spawned.result).to.be.eventually.rejected.then(() => {
expect(spawned.messages).to.have.lengthOf(2);
const event = lastOf(SceneFinished, spawned.messages);
expect(Result[event.value.result]).to.equal(Result[Result.ERROR]);
expect(event.value.error.message).to.match(/Timeout of 5ms exceeded./);
});
});
const results = {
undefined: Result.PENDING,
ambiguous: Result.ERROR,
failed: Result.FAILURE,
pending: Result.PENDING,
passed: Result.SUCCESS,
skipped: Result.SKIPPED,
};
if (! results[stepStatus]) {
throw new Error(`Couldn't map '${ stepStatus }' to a Serenity Result`);
}
return timeOut(error)
? Result.ERROR
: results[stepStatus];
}