-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat: support parallel in before/afterAll hooks #2140
Conversation
@davidjgoss I noticed that the errors from the workers' I recall we've discussed this elsewhere, that those worker errors should be printed in the main Cucumber console output. Should we maybe deal with that first? |
I think that's a different and harder problem than the scope of this PR. It gets back to cucumber/messages#66 - we want to factor global hook failures into the formatter output so that it doesn't hide the failures, but we can't because formatters rely on the supply of messages, and global hooks are not represented in any messages. I'll comment on that issue and see if it goes anywhere. @tim-yao sorry for the delay - I'll get you some feedback on this shortly. |
Hi @davidjgoss any plan for 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.
A dropped a couple of comments inline which might be helpful for implementing this, plus here's a couple of links to relevant code:
- https://github.com/cucumber/cucumber-js/blob/main/src/support_code_library_builder/index.ts#L276-L297 handles where the global hooks are defined - see also the
IDefineTestRunHookOptions
andITestRunHookDefinitionConfig
types which will need adding to - https://github.com/cucumber/cucumber-js/blob/main/src/runtime/parallel/worker.ts#L86-L95 where hooks are currently invoked at the worker level
If you need any pointers give me a nudge!
AfterAll({ parallelMode: HookParallelMode.WORKER_ONLY }, function() { | ||
counter ++ | ||
console.log('worker: ', counter) | ||
expect(counter).to.eql(2) |
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'm not sure this will work once we implement the changes - because the workers are in different Node.js processes, they won't be acting on the same counter
variable, so I think it will always be 1
assuming the workers take one scenario each.
What might be worth pursuing instead is having each flavour of the hook console.log
a string with the some of environment variables that Cucumber sets for the parallel runtime e.g CUCUMBER_WORKER_ID
and then assert on that being in the output with a Then the output contains the text:
step (see other features) - a bit messy but should work.
@@ -49,6 +49,10 @@ export { | |||
} from './support_code_library_builder/world' | |||
export { parallelCanAssignHelpers } | |||
|
|||
export const HookParallelMode = { |
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 could be a TS enum
I've put a comment on the original discussion thread @tim-yao - essentially suggesting we won't fix this. If you want to continue and go ahead that's fine. But in essence this would be something JS-specific. It's not something I would evangelise porting to other languages, and the very nature of JS' async behaviour maybe lends itself to something that could be used here. However in practicality (I won't copy my post from the issue), I just think this over-engineers a problem that could (and should), be solved in a different way. I'll let @davidjgoss maybe provide more JS-specific information as he's the subject expert in cucumberJS. |
That makes sense to me. I don't have the original issue anymore. It was from the HTML report plugin which requires after all hooks. It was broken in parallel. Since I move to use the default HTML formatter, I don't have the issue anymore. I will leave this PR to @davidjgoss. Feel free to close this or continue. Thanks. |
🤔 What's changed?
⚡️ What's your motivation?
Fix #1153
🏷️ What kind of change is this?
♻️ Anything particular you want feedback on?
📋 Checklist:
This text was originally generated from a template, then edited by hand. You can modify the template here.