Skip to content

Commit

Permalink
Run BeforeAll & AfterAll hooks in order
Browse files Browse the repository at this point in the history
This prevents a mangled command log, as seen in #1250 [1].

[1] #1250
  • Loading branch information
badeball committed Nov 14, 2024
1 parent c6e8874 commit 598f968
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## Unreleased

- Correctly represent consecutive BeforeAll & AfterAll hooks in the command log, relates to [#1250](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1250).

## v21.0.2

- Cache requested source maps, fixes [#1245](https://github.com/badeball/cypress-cucumber-preprocessor/discussions/1245).
Expand Down
34 changes: 22 additions & 12 deletions lib/browser-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -889,12 +889,17 @@ function beforeHandler(this: Mocha.Context, context: CompositionContext) {

const { registry } = context;

for (const hook of registry.resolveBeforeAllHooks()) {
runStepWithLogGroup({
fn: context.dryRun ? noopFn : () => registry.runRunHook(this, hook),
keyword: "BeforeAll",
});
}
registry.resolveBeforeAllHooks().reduce(
(chain, hook) => {
return chain.then(() =>
runStepWithLogGroup({
fn: context.dryRun ? noopFn : () => registry.runRunHook(this, hook),
keyword: "BeforeAll",
}),
);
},
cy.wrap({} as unknown, { log: false }),
);

taskSpecEnvelopes(context);

Expand Down Expand Up @@ -1151,12 +1156,17 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
function afterHandler(this: Mocha.Context, context: CompositionContext) {
const { registry } = context;

for (const hook of registry.resolveAfterAllHooks()) {
runStepWithLogGroup({
fn: context.dryRun ? noopFn : () => registry.runRunHook(this, hook),
keyword: "AfterAll",
});
}
registry.resolveAfterAllHooks().reduce(
(chain, hook) => {
return chain.then(() =>
runStepWithLogGroup({
fn: context.dryRun ? noopFn : () => registry.runRunHook(this, hook),
keyword: "AfterAll",
}),
);
},
cy.wrap({} as unknown, { log: false }),
);
}

export default function createTests(
Expand Down

0 comments on commit 598f968

Please sign in to comment.