Description
What is the problem this feature will solve?
Currently beforeEach and afterEach hooks are run even for tests that are skipped.
This becomes problematic when there are many hooks that are expensive to run and one wants to run only a few tests.
Consider case:
beforeEach(() => {
expensiveSetup();
});
afterEach(() => {
expensiveTeardown();
});
test('test1', () => {
expensiveTest1();
});
test('test2', () => {
expensiveTest2();
});
Now --test-name-pattern test1
will run both hooks twice or even if no test is run (both skipped) they will still be run twice.
It would be logical to assume that if the test is skipped, then before/afterEach hook is also skipped for that test. This is in fact the behavior in other popular js test runners such as mocha and jest.
Also, current documentation says that:
The --test-name-pattern command-line option can be used to only run tests whose name matches the provided pattern. (...)
For each test that is executed, any corresponding test hooks, such as beforeEach(), are also run.
Even though it is not explicitly said that beforeEach() would be skipped if test is not executed, I think this implies that, because otherwise that statement would be useless, if test hooks are ran regardless of whether test is filtered in or out.
What is the feature you are proposing to solve the problem?
If test case is skipped, beforeEach and afterEach hooks for that case should also be skipped.
What alternatives have you considered?
No response