-
Notifications
You must be signed in to change notification settings - Fork 45
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
Question: global before/after support #121
Comments
Yes, you can do this with |
In general it'll work but I'm not sure how to achieve the following. in the global before I can asynchronously get the token and set global request defaults
with mocha --require i'll have to resolve the token in every describe file. Is there any better option to achieve the former behavior? essentially get the tests wait on async call complete to be able to use global values |
If I understand you correct, this is what you need: CLI:
describe('suite', () => { it('case', () => {
|
That's right. |
Gotcha. Double checked that, mocha doesn't wait until --require'd file finishes its execution, so in your case the quick way to get things done is this hack:
|
That will work. The only inconvenience we'll have to have before for each describe but seems like there is no any other easy way. What about global after? Any suggestions how to achieve that? |
Nope, no easy way for now. I think it would be better to leave this issue open so that we can think of a better solution when we have time for that. |
So... I have the distinct impression that if you have 2 test files, your |
@erwinw I'm not 100% sure but this sounds like an expected behaviour of |
Thanks for the reply, @1999 . It’s a bit unfortunate since it’s leaves only hacky solutions; I’m trying to share some info between the processes and I guess the only thing we might have is the ID of the parent process (process.ppid — haven’t tested if that is correct in this case, and a file on disk based on this ID. Cleanup after running is a whole different kettle of fish... |
@erwinw right. Maybe that's a good area for |
Well, you have the ipc channel you can use, @1999? |
What I'm thinking is that a mechanism to run some code exclusively before all tests are run, and after all test are run. Maybe you could have an event emitter exposed on the |
Does this lib support global before and after hooks?
In regular mocha if before and after are outside the describe block they becoming global hooks means they run before and after all the tests in all the suites.
This seems doesn't work for this library. Is there anyway to achieve this behavior? I need to setup tokens in before hook to use them in all the test cases.
The text was updated successfully, but these errors were encountered: