Closed goldbergyoni closed 5 years ago
Thanks!
We're adding you now as a new best practice, see if you feel comfortable with the text or want to add some example
Not sure which text you're referring to.
As for multi-process approach it's the same as for the other tests runners. The before hook if specified for some file will be executed for this file only. As for the file logic: yep, will be executed for this file only in a separate independent process.
As for specific scenarios where tests might fail there's a page with the limitations. The most common issue is when developers are trying to use some global object between the test files (i.e. their files are dependent on some state between them).
Oh, forgot to include a link: https://github.com/i0natan/nodebestpractices/pull/273
Ensuring I got this straight - if someone feeds the DB with seed data on the 'before' hook, it will run in all processes and potentially override/duplicate the same data, correct?
If this "before" hook is in the --require
then yes, it will be required and executed for each test suite. Currently, I can't think of any option mocha
has that would allow running the code before running test suites. Maybe --file
is a good candidate?
@1999 To my understanding, "before" can be nested within a "describe" === suite level hook. Isn't it?
I might miss something basic about how this great lib works, are you parallelizing files (e.g. file1 -> process1, file2 -> process2) or able to split a single file suite tests between processes?
"before" can be nested within a "describe" === suite level hook. Isn't it?
Yes, that's the most common usage of before/after hooks.
are you parallelizing files (e.g. file1 -> process1, file2 -> process2) or able to split a single file suite tests between processes?
Yes, every file is executed in a separate process. Technically we're able to split test suites from one file and run them separately, but what we discovered is that developers often find this behaviour confusing because they rely on some variables being set in the previously executed suite from the same file etc. So parallelizing the files was a safer option and we decided to go with it.
Closing as non-active for more than a week.
First, thanks for the great work. We're adding you now as a new best practice, see if you feel comfortable with the text or want to add some example
Question - how does the multi-process approach might affect the test structure? will the 'before' hook run on all processes? file level variable & logic (not inside hooks, hanging on the test file top for example) will get executed also? appreciate few words on scenario where tests might fail due to parallelization