Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let reporter: ProtractorReporter,
protractorRunner: Runner,
serenity: Serenity;
beforeEach(() => {
protractorRunner = sinon.createStubInstance(Runner);
reporter = new ProtractorReporter(protractorRunner);
serenity = new Serenity();
serenity.setTheStage(reporter);
});
const details = new ScenarioDetails(
new Name('scenario name'),
new Category('scenario category'),
new FileSystemLocation(new Path('./some/scenario.spec.ts')),
);
/** @test {ProtractorReporter} */
it('ignores events outcomes Protractor doesn\'t care about', () => {
expect(reporter.notifyOf(new SceneFinished(details, new ExecutionSkipped()))).to.be.undefined; // tslint:disable-line:no-unused-expression
expect(reporter.report()).to.deep.equal({
failedCount: 0,
specResults: [],
});
});
/** @test {ProtractorReporter} */
it('ignores domain events Protractor doesn\'t care about', () => {
describe('SerenityBDDReporter', () => {
let stageManager: sinon.SinonStubbedInstance,
reporter: SerenityBDDReporter;
beforeEach(() => {
const env = create();
stageManager = env.stageManager;
reporter = env.reporter;
});
// see examples/cucumber/features/reporting_results/reports_scenario_outlines.feature for more context
const
category = new Category('Reporting results'),
name = new Name('Reports scenario outlines'),
path = new Path(`reporting_results/reports_scenario_outlines.feature`),
template = new Description(`
When makes a contribution of:
| value |
| time |
| talent |
| great code |
Then they help bring serenity to fellow devs
`),
sequence = new ScenarioDetails(name, category, new FileSystemLocation(
path,
7,
)),
scenario1 = new ScenarioDetails(name, category, new FileSystemLocation(
path,
describe('Photographer', () => {
const
defaultCardScenario = new ScenarioDetails(
new Name('Paying with a default card'),
new Category('Online Checkout'),
new FileSystemLocation(
new Path(`payments/checkout.feature`),
),
),
pickACard = new ActivityDetails(new Name('Pick the default credit card'));
it('complains when sent DomainEvents before getting assigned to a Stage', () => {
const photographer = new Photographer(new TakePhotosOfFailures());
expect(() => photographer.notifyOf(new SceneStarts(defaultCardScenario)))
.to.throw(LogicError, `Photographer needs to be assigned to the Stage before it can be notified of any DomainEvents`);
});
describe(`when there's no actor in the spotlight`, () => {
given(
new ExecutionSkipped(),
it('correctly recognises ambiguous steps', () => {
emitAllFrom(require('./samples/scenario-with-ambiguous-steps.json'));
const expectedScenarioDetails = new ScenarioDetails(
new Name('Ambiguous steps'),
new Category('Event Protocol'),
new FileSystemLocation(
new Path('features/ambiguous-steps.feature'),
3,
3,
),
);
return serenity.waitForNextCue().then(() => {
PickEvent.from(recorder.events)
.next(SceneStarts, e => expect(e.value).to.equal(expectedScenarioDetails))
.next(TestRunnerDetected, e => expect(e.value).to.equal(new Name('Cucumber')))
.next(SceneTagged, e => expect(e.tag).to.equal(new FeatureTag('Event Protocol')))
.next(TaskStarts, e => expect(e.value.name).to.equal(new Name('Given I have an ambiguous step definition')))
.next(TaskFinished, e => {
expect(e.value.name).to.equal(new Name('Given I have an ambiguous step definition'));
expect(e.outcome).to.be.instanceOf(ExecutionFailedWithError);
private scenarioDetailsOf(spec: SpecResult): ScenarioDetails {
return new ScenarioDetails(
new Name(this.currentScenarioNameFor(spec.description)),
new Category(this.currentFeatureName()),
FileSystemLocation.fromJSON(spec.location as any),
);
}
then(res => {
expect(res.exitCode).to.equal(1);
const
expectedScenarioName = new Name('Sample outline'),
expectedScenarioCategory = new Category('Serenity/JS recognises scenario outlines'),
outlineLine = 3,
firstScenarioLine = 12,
secondScenarioLine = 13,
expectedExamplesName = new Name('Example results'),
expectedExamplesDescription = new Description('Description of the examples');
PickEvent.from(res.events)
.next(SceneSequenceDetected, event => {
expect(event.value.name).to.equal(expectedScenarioName);
expect(event.value.category).to.equal(expectedScenarioCategory);
expect(event.value.location.line).to.equal(outlineLine);
})
.next(SceneParametersDetected, event => {
expect(event.scenario.name).to.equal(expectedScenarioName);
expect(event.scenario.category).to.equal(expectedScenarioCategory);
expect(event.value.name).to.equal(expectedExamplesName);
private detailsOf(scenario: FeatureFileNode, feature: Feature): ScenarioDetails {
return new ScenarioDetails(
scenario.name,
new Category(feature.name.value),
scenario.location,
);
}
describe('SerenityBDDReporter', () => {
const
startTime = Timestamp.fromJSON('2018-05-25T00:00:00.123Z'),
scenarioDuration = Duration.ofMilliseconds(142);
const defaultCardScenario = new ScenarioDetails(
new Name('Paying with a default card'),
new Category('Online Checkout'),
new FileSystemLocation(
new Path(`payments/checkout.feature`),
),
);
const voucherScenario = new ScenarioDetails(
new Name('Paying with a voucher'),
new Category('Online Checkout'),
new FileSystemLocation(
new Path(`payments/checkout.feature`),
),
);
let stage: Stage,
stageManager: sinon.SinonStubbedInstance,
reporter: SerenityBDDReporter;