-
-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding BeforeAll and AfterAll hooks #1114
Conversation
features/issues/758.feature
Outdated
}) | ||
""" | ||
When I run cypress | ||
Then it passes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test can be moved and incorperated into features/hooks_ordering.feature
. Issue-specific tests are only for behavior that is otherwise hard to describe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
lib/browser-runtime.ts
Outdated
@@ -18,7 +18,7 @@ import DataTable from "./data_table"; | |||
|
|||
import { | |||
assignRegistry, | |||
freeRegistry, | |||
freeRegistry, getRegistry, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should run all tests, this will reveal this as a problem (unused variable and incorrect formatting).
$ npm run test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, will remove this
lib/browser-runtime.ts
Outdated
@@ -775,6 +780,31 @@ function beforeHandler(context: CompositionContext) { | |||
taskSpecEnvelopes(context); | |||
} | |||
|
|||
function beforeAllHandler(this: Mocha.Context, context: CompositionContext) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method's content can be moved into beforeHandler(..)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored it
lib/browser-runtime.ts
Outdated
const { registry } = context; | ||
let beforeAllHooks = registry.resolveBeforeAllHooks(); | ||
for(const beforeAllHook of beforeAllHooks) { | ||
if (beforeAllHook) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check seems unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's redundant. Removing it
lib/browser-runtime.ts
Outdated
.then((start) => { | ||
const end = createTimestamp(); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrapping runStepWithLogGroup
in order to obtain start- & end-time is only necessary when these values are actually used for something and this isn't the case here. Thus, you can replace
cy.then(() => {
const start = createTimestamp();
return cy.wrap(start, { log: false });
})
.then((start) => {
runStepWithLogGroup({
fn: () => registry.runHook(this, hook),
keyword: "BeforeAll"
});
return cy.wrap(start, { log: false });
})
.then((start) => {
const end = createTimestamp();
});
.. with
runStepWithLogGroup({
fn: () => registry.runHook(this, hook),
keyword: "BeforeAll"
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Made this change
lib/browser-runtime.ts
Outdated
.then((start) => { | ||
const end = createTimestamp(); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes for here.
lib/entrypoint-browser.ts
Outdated
@@ -127,6 +127,28 @@ function defineAfterStep( | |||
} | |||
} | |||
|
|||
function defineBeforeAll(fn: IHookBody): void; | |||
function defineBeforeAll( | |||
maybeFn?: IHookBody |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The optionality and function overloading here is unecessary, as there's only one way to invoke this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, I'll change this here and in other places too
lib/entrypoint-browser.ts
Outdated
|
||
function defineAfterAll(fn: IHookBody): void; | ||
function defineAfterAll( | ||
maybeFn?: IHookBody |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes for here.
lib/entrypoint-node.ts
Outdated
export function BeforeAll(fn: IStepHookBody): void; | ||
export function BeforeAll( | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
maybeFn?: IStepHookBody |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
lib/entrypoint-node.ts
Outdated
export function AfterAll(fn: IStepHookBody): void; | ||
export function AfterAll( | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
maybeFn?: IStepHookBody |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the change
lib/registry.ts
Outdated
@@ -101,7 +101,6 @@ export class Registry { | |||
this.runStepDefininition = this.runStepDefininition.bind(this); | |||
this.defineParameterType = this.defineParameterType.bind(this); | |||
this.defineBefore = this.defineBefore.bind(this); | |||
this.defineAfter = this.defineAfter.bind(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably not right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted this by mistake, reverting it back
@@ -25,6 +25,8 @@ import { | |||
After, | |||
BeforeStep, | |||
AfterStep, | |||
BeforeAll, | |||
AfterAll, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add the same tests here, as you have in test-d/entrypoint-browser.test-d.ts
.
This primarily renames a bunch of stuff to more clearly differentiate between the three types of hooks that exists now, namely: - run hooks (BeforeAll, AfterAll) - case hooks (Before, After) - step hooks (BeforeStep, AfterStep) The naming convention comes from cucumber-js [1]. Additionally, the order of AfterAll is reversed before execution. Lastly, documentation has been updated. [1] https://github.com/cucumber/cucumber-js/blob/v10.0.0/src/support_code_library_builder/index.ts#L72-L77
This primarily renames a bunch of stuff to more clearly differentiate between the three types of hooks that exists now, namely: - run hooks (BeforeAll, AfterAll) - case hooks (Before, After) - step hooks (BeforeStep, AfterStep) The naming convention comes from cucumber-js [1]. Additionally, the order of AfterAll is reversed before execution. Lastly, documentation has been updated. [1] https://github.com/cucumber/cucumber-js/blob/v10.0.0/src/support_code_library_builder/index.ts#L72-L77
Excellent, thank you. I did some clean up in 61623bc, some of that stuff was just easier to do myself than to explain. |
Thank you, @badeball! |
This PR adds
BeforeAll(..)
andAfterAll(..)
hooks, fixes #758