Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
scene_2 = new RecordedScene(
scenario_2,
feature,
{ path: featureFile },
),
scene_2_duration = 7,
logsIn = new RecordedActivity('Logs in'),
logsIn_duration = 10,
entersUsername = new RecordedActivity('Enters username'),
entersUsername_duration = 6,
entersPassword = new RecordedActivity('Enters password'),
entersPassword_duration = 4,
selectsAProduct = new RecordedActivity('Selects a product');
const examplesOfSuccess = [ Result.SUCCESS, Result.PENDING, Result.IGNORED, Result.SKIPPED ],
examplesOfFailure = [ Result.FAILURE, Result.COMPROMISED, Result.ERROR ];
let protractor: Runner,
reporter: ProtractorReporter,
stage: Stage;
beforeEach(() => {
stage = new Stage(new StageManager(new Journal()));
protractor = sinon.createStubInstance(Runner) as any;
reporter = new ProtractorReporter(protractor);
reporter.assignTo(stage);
});
describe('complies with the Protractor Framework specification:', () => {
// Protractor Framework spec:
it('finished with a Failure', () => {
const failure = new Error('Expected the list of items to contain 5 items but it only had 4');
fileSystem.store.withArgs(photoName, imageBuffer).returns(photoPath);
thePhotographer.notifyOf(new ActivityFinished(new Outcome(activity, Result.FAILURE, failure), now));
const photoAttempted = stageManager.readTheJournal().pop();
expect(photoAttempted).to.be.instanceOf(PhotoAttempted);
expect(photoAttempted.timestamp).to.equal(now);
expect(photoAttempted.value).to.be.instanceOf(PhotoReceipt);
expect(photoAttempted.value.activity).to.deep.equal(activity);
return expect(photoAttempted.value.photo).to.eventually.deep.equal(new Photo(photoPath));
});
static from = (result: StepResult | ScenarioResult) => {
const isTimeOut = (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[ result.status ]) {
throw new Error(`Couldn't map the '${ result.status }' to a Serenity Result`);
}
return isTimeOut(realErrorFrom(result.failureException))
? Result.ERROR
: results[ result.status ];
}
}
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];
}
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.lengthOf(2);
const event = lastOf(SceneFinished, spawned.messages);
expect(Result[event.value.result]).to.equal(Result[Result.FAILURE]);
expect(event.value.error).to.deep.equal({
actual: 'async pass',
expected: 'async fail',
message: 'expected \'async pass\' to equal \'async fail\'',
name: 'AssertionError',
showDiff: true,
});
});
});
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.FAILURE]);
});
});
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.FAILURE]);
expect(event.value.error).to.deep.equal({
actual: 'async pass',
expected: 'async fail',
message: 'expected \'async pass\' to equal \'async fail\'',
name: 'AssertionError',
showDiff: true,
});
});
});
return expect(spawned.result).to.be.eventually.rejected.then(() => {
expect(spawned.messages).to.have.lengthOf(4);
expect(spawned.messages).to.have.lengthOf(4);
expect(spawned.messages[0].value.name).to.equal(scenario);
expect(spawned.messages[1].value.name).to.equal(step);
expect(spawned.messages[2].value.subject.name).to.equal(step);
expect(Result[spawned.messages[3].value.result]).to.equal(Result[Result.FAILURE]);
expect(spawned.messages[3].value.subject.name).to.equal(scenario);
expect(Result[spawned.messages[3].value.result]).to.equal(Result[Result.FAILURE]);
});
});
return expect(spawned.result).to.be.eventually.rejected.then(() => {
expect(spawned.messages).to.have.lengthOf(4);
expect(spawned.messages).to.have.lengthOf(4);
expect(spawned.messages[0].value.name).to.equal(scenario);
expect(spawned.messages[1].value.name).to.equal(step);
expect(spawned.messages[2].value.subject.name).to.equal(step);
expect(Result[spawned.messages[3].value.result]).to.equal(Result[Result.FAILURE]);
expect(spawned.messages[3].value.subject.name).to.equal(scenario);
expect(Result[spawned.messages[3].value.result]).to.equal(Result[Result.FAILURE]);
});
});