What is the problem this feature will solve?
It's common to apply some logic before or after each test or a test suite. For example to add a property to the global, to always mock a certain module or to always restore mocks after each test.
When --test-global-setup is used along with --test-isolation=none, this feature works quite nicely. We can add before, beforeEach, after and afterEach in the global setup and the callbacks will be correctly called. The only thing that I found to be unexpected, is that the before callback passed in the global setup gets called before globalSetup function.
When --test-isolation is process, which is the default, things start to get weird. First the before in the global setup module gets called, then globalSetup function, then beforeEach in the global setup. Now all the tests run in separate processes, so whatever we assign in the global setup doesn't affect them. When the tests finish, callbacks in the global setup are run in the following order: afterEach, globalTeardown, after.
What is the feature you are proposing to solve the problem?
I would propose:
- callback passed to the
before function should be called after the globalSetup
- global setup module should be loaded in each test sub process
- Callbacks passed to the
before, beforeEach, afterEach & after in the global setup module should be called in each test subprocess. Methods globalSetup and globalTeardown should not be called in each subprocess (current behaviour).
What alternatives have you considered?
No response
What is the problem this feature will solve?
It's common to apply some logic before or after each test or a test suite. For example to add a property to the global, to always mock a certain module or to always restore mocks after each test.
When --test-global-setup is used along with --test-isolation=none, this feature works quite nicely. We can add
before,beforeEach,afterandafterEachin the global setup and the callbacks will be correctly called. The only thing that I found to be unexpected, is that thebeforecallback passed in the global setup gets called beforeglobalSetupfunction.When --test-isolation is process, which is the default, things start to get weird. First the
beforein the global setup module gets called, thenglobalSetupfunction, thenbeforeEachin the global setup. Now all the tests run in separate processes, so whatever we assign in the global setup doesn't affect them. When the tests finish, callbacks in the global setup are run in the following order: afterEach, globalTeardown, after.What is the feature you are proposing to solve the problem?
I would propose:
beforefunction should be called after theglobalSetupbefore,beforeEach,afterEach&afterin the global setup module should be called in each test subprocess. MethodsglobalSetupandglobalTeardownshould not be called in each subprocess (current behaviour).What alternatives have you considered?
No response