Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('FeatureFileMapper', () => {
const fixtures = new Path(__dirname).join(new Path('fixtures'));
describe('when mapping names and descriptions', () => {
it('maps a feature', parse('names_and_descriptions.feature', map => {
expect(map.get(Feature).onLine(1)).to.equal(new Feature(
new FileSystemLocation(fixtures.join(new Path('names_and_descriptions.feature')),
1,
1,
),
new Name('Names and descriptions'),
new Description('A multi-line\n\ndescription\nof a feature'),
));
}));
it('maps a scenario with a single-line description', parse('names_and_descriptions.feature', map => {
const scenario = map.get(Scenario).onLine(8);
it('recognises DataTable argument', parse('step_arguments.feature', map => {
const scenario = map.get(Scenario).onLine(12);
expect(scenario.steps).to.deep.equal([
new Step(
new FileSystemLocation(fixtures.join(new Path('step_arguments.feature')), 14, 5),
new Name('Given a step with a DataTable argument:\n| first name | last name |\n| Jan | Molak |'),
),
]);
}));
});
it('correctly recognises errors thrown in steps', () => {
emitAllFrom(require('./samples/scenario-with-errors.json'));
const expectedScenarioDetails = new ScenarioDetails(
new Name('Errors in steps'),
new Category('Event Protocol'),
new FileSystemLocation(
new Path('features/errors-in-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 a step that throws an error')))
.next(TaskFinished, e => {
expect(e.value.name).to.equal(new Name('Given I have a step that throws an error'));
expect(e.outcome).to.be.instanceOf(ExecutionFailedWithError);
expect((e.outcome as ExecutionFailedWithError).error).to.be.instanceOf(Error);
it('records the order of test steps so that the Serenity BDD reporter can display the reportData in the correct context', () => {
const
pickACard = new ActivityDetails(new Name('Pick a credit card')),
makePayment = new ActivityDetails(new Name('Make a payment'));
given(reporter).isNotifiedOfFollowingEvents(
new SceneStarts(defaultCardScenario),
new TaskStarts(pickACard),
new ArtifactGenerated(new Name('pick a card message'), JSONData.fromJSON({ card: 'default' })),
new ArtifactArchived(new Name('pick a card message'), JSONData, new Path('target/site/serenity/pick-a-card-message-md5hash.json')),
new TaskFinished(pickACard, new ExecutionSuccessful()),
new TaskStarts(makePayment),
new ArtifactGenerated(new Name('make a payment message'), JSONData.fromJSON({ amount: '£42' })),
new ArtifactArchived(new Name('make a payment message'), JSONData, new Path('target/site/serenity/make-a-payment-message-md5hash.json')),
new ArtifactGenerated(new Name('server log'), TextData.fromJSON({ contentType: 'text/plain', data: 'received payment request' })),
new TaskFinished(makePayment, new ExecutionSuccessful()),
new SceneFinished(defaultCardScenario, new ExecutionSuccessful()),
new TestRunFinished(),
);
const report: SerenityBDDReport = stageManager.notifyOf.firstCall.lastArg.artifact.map(_ => _);
expect(report.testSteps).to.have.lengthOf(2);
expect(report.testSteps[0].number).to.equal(1);
expect(report.testSteps[0].reportData[0].title).to.equal('pick a card message');
expect(report.testSteps[0].reportData[0].contents).to.equal('{\n "card": "default"\n}');
it('correctly recognises Cucumber Event Protocol events', () => {
emitAllFrom(require('./samples/scenario-with-hooks.json'));
const expectedScenarioDetails = new ScenarioDetails(
new Name('Hooks'),
new Category('Event Protocol'),
new FileSystemLocation(
new Path('features/tasty-cucumber.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 a tasty cucumber in my belly')))
.next(TaskFinished, e => {
expect(e.value.name).to.equal(new Name('Given I have a tasty cucumber in my belly'));
expect(e.outcome).to.equal(new ExecutionSuccessful());
})
.next(TaskStarts, e => expect(e.value.name).to.equal(new Name(`Then I'm very happy`)))
describe('FeatureFileParser', () => {
const
sampleFeature = new Path(__dirname).join(new Path('fixtures')).join(new Path('sample.feature')),
brokenFeature = new Path(__dirname).join(new Path('fixtures')).join(new Path('broken.feature'));
it('loads a GherkinDocument from a file', () => {
const loader = new FeatureFileParser(new Gherkin.Parser());
return loader.parse(sampleFeature)
.then(document => {
expect(document).to.deep.equal({
type: 'GherkinDocument',
feature: {
type: 'Feature',
tags: [],
location: { line: 1, column: 1 },
language: 'en',
keyword: 'Feature',
name: 'Sample feature',
export function bootstrap(argv: string[], interceptor?: Interceptor) {
yargs()
.version(require('../../package.json').version)
.demand(1)
.usage('Usage: $0 [options]')
.example('$0 update [options]', 'updates the Serenity jar to the latest version')
.example('$0 remove [options]', 'removes the cache directory and downloaded jars')
.example('$0 run [options]', 'generates the HTML report from JSON reports produced by Serenity/JS')
.example('$0 --help', 'shows the available parameters')
.epilog(`copyright (C) 2016-${ new Date().getFullYear() } ${ pkg.author.name } <${ pkg.author.email }>`)
.commandDir('./commands')
.alias('h', 'help').help()
.parse(argv, {
stage: serenity.callToStageFor(new Actors(new Path(process.cwd()))),
}, interceptor);
}
.then(() => {
const crew = (serenity as any).stage.manager.subscribers;
const archiver = pickOne(ArtifactArchiver, crew);
expect((archiver as any).fileSystem.root)
.to.equal(new Path(process.cwd() + '/target/site/serenity'));
});
});
.then(() => {
const crew = (serenity as any).stage.manager.subscribers;
const archiver = pickOne(ArtifactArchiver, crew);
expect((archiver as any).fileSystem.root)
.to.equal(new Path(`./custom/output/path`));
});
});