Skip to content

Commit

Permalink
fix before-after, todo add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmisty committed Nov 5, 2023
1 parent 159804c commit e37f405
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
13 changes: 12 additions & 1 deletion integration/cucumber/first.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,15 @@ Feature: test cucumber
@P1
@failOnPurpose
Scenario: 04 visiting the frontpage
Then This step should fail
Then This step should fail


@P1
@fail-after
Scenario: 05 fails in after
Then I should see a search bar "hello"

@P1
@fail-before
Scenario: 05 fails in before
Then I should see a search bar "hello"
10 changes: 9 additions & 1 deletion integration/cucumber/first.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { Then } from '@badeball/cypress-cucumber-preprocessor';
import { After, Before, Then } from '@badeball/cypress-cucumber-preprocessor';

Then('This step should fail', () => {
cy.wrap({ a: 1 }).then(t => {
expect(t).eq(2);
});
});

After({ tags: '@fail-after' }, () => {
expect(true, 'failed in after each hook').to.be.false;
});

Before({ tags: '@fail-before' }, () => {
expect(true, 'failed in before each hook').to.be.false;
});
7 changes: 6 additions & 1 deletion src/setup/cypress-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,17 @@ export const handleCyLogEvents = (
}

const isGherkin = (logName: string) => {
return logName && ['When', 'Given', 'Then', 'And'].some(t => logName.startsWith(t));
return logName && ['When', 'Given', 'Then', 'And', 'After', 'Before'].some(t => logName.startsWith(t));
};

const failed: { name: string; message: string }[] = [];
const gherkinLog: { current: string | undefined } = { current: undefined };

Cypress.Allure.on('test:started', () => {
failed.splice(0, failed.length);
gherkinLog.current = undefined;
});

Cypress.on('log:changed', async log => {
if (!allureLogCyCommands()) {
return;
Expand Down

0 comments on commit e37f405

Please sign in to comment.