-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
test.concurrent ignores beforeEach and afterEach #7997
Comments
#4281 dupliacted issue |
Think this is the RCA
|
@SimenB It seems easy to change the workflow in |
But not sure if |
@Mark1626 |
@SimenB bump |
This comment has been minimized.
This comment has been minimized.
Looks like adding an empty not concurrent test before concurrent ones fixes the issue. At least with UPD: no, this doesn't work :/ |
How did you set up your test suite? I have something like the following which is not working: describe('...', () => {
beforeAll(async () => {
// do some setup
});
afterAll(async () => {
// do teardown
});
it('noop', () => {
expect(2+2).toBe(4);
});
it.concurrent('...', async () => {
// runs before beforeAll
});
it.concurrent('...', async () => {
// runs before beforeAll
});
}); |
I ended up just running the async preparation code in the test file before Another workaround is to make a promise which resolves after setup is ready and await for it in every concurrent test: let beforeAllResolve;
const beforeAllPromise = new Promise((resolve) => {
beforeAllResolve = resolve;
});
describe('...', () => {
beforeAll(async () => {
// do some setup
// RESOLVE
beforeAllResolve()
});
afterAll(async () => {
// do teardown
});
it.concurrent('...', async () => {
await beforeAllPromise;
// do stuff
});
it.concurrent('...', async () => {
await beforeAllPromise;
// do stuff
});
}); |
Has there been any progress on this? Would prefer not to rework hundreds of lines of tests 😅 |
The issue still persists. I regret I recommended our team to use Jest when |
I found some workaround to execute let str;
beforeAll(() => {
str = 'Some str with number 3';
});
describe('describe description', () => {
test.concurrent('concurrent tests', () => {
expect(str).toBe(`Some str with number ${Math.floor(Math.random() * 5) + 1}`);
});
}); But |
Allows test.concurrent to function without beforeEach known issue at jestjs/jest#7997
|
I spawn in BeforeEach my testcontainer and stop it in after each. Sure i could put it inside everytest, but i would love something so i dont have to write the same thing in 30 tests each file if there would be something like beforeEach ... |
🐛 Bug Report
When using test.concurrent with tests, all the scenarios run first and then the beforeEach and afterEach blocks run next.
To Reproduce
Write a simple test suite with a beforeEach , 3 tests using test.concurrent, and afterEach.
Expected behavior
I expect runner to execute beforeEach block, then the test, then afterEach block.
Link to repl or repo (highly encouraged)
test-concurrent bug demo
Issues without a reproduction link are likely to stall.
Run
npx envinfo --preset jest
Paste the results here:
Jest v22.1.2 node v7.4.0 linux/amd64 PASS ./concurrent-test.js try running parallel by scenario level ✓ First Test (3ms) ✓ Second Test ✓ Third Test (1ms) console.log concurrent-test.js:8 Test 1 console.log concurrent-test.js:12 Test 2 console.log concurrent-test.js:16 Test 3 console.log concurrent-test.js:4 BEFORE console.log concurrent-test.js:20 AFTER console.log concurrent-test.js:4 BEFORE console.log concurrent-test.js:20 AFTER console.log concurrent-test.js:4 BEFORE console.log concurrent-test.js:20 AFTER Test Suites: 1 passed, 1 total Tests: 3 passed, 3 total Snapshots: 0 total Time: 0.993s, estimated 1s Ran all test suites.
The text was updated successfully, but these errors were encountered: