-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
feat(test_runner): Provide a proper way to run side effects #49994
Comments
Thanks for opening a report! I'm not sure how you expect concurrency to work? Like, these suites are in different files and you run with concurrency so they will be executed in parallel (that's the feature!). In order for them to run in parallel they need to be written in a way where each suite does not impact other suites. In your example that'd likely be each suite getting its own database instead of resetting shared tables. I'm pretty sure Jest will also do this in your above example and you just didn't run into a race condition. If you parallelize... stuff will run in parallel. |
Is this covered by #49487? If so, can we close this? |
you can probably use // test1.test.js
beforeEach(async () => {
await truncateTables()
})
describe('test1', () => {
// test1 code
})
// test2.test.js
describe('test1', () => {
// test2 code
}) |
Hey @benjamingr 👋🏼
What I did was converting a codebase with all Jest tests to Node. Looking also at the documentation, what I think is that the |
Hi @cjihrig 😊
Mmm, I'd say nope 'cause what I'm referring to is that the current behaviour of |
Hello @MoLow 👋🏼 Nope, I can confirm this code will have side effects, because when the |
Maybe I'm still missing something, but it seems like the problem is that with Node's test runner, I proposed looking at #49487, which is a request to run |
Yes, I already looked at it. The thing is that disabling concurrency makes tests way slower than Jest too. And apparently, Jest is able to run side effect code (with the |
Basically what we're saying is that your Jest test s flakey and the fact Jest is kind of slow saved you from running into that edge case. I'm happy to find questions from StackOverflow or a Jest issue if that helps. This is actually worse since it means when your tests fail it will be even harder to debug. You need to redesign your test suites to not interfere with each other :] |
Nope @benjamingr, I'm saying something different 😉
So, even with concurrency, when there is a To be honest, if Node will not support such feature, it will be really hard to migrate existing and legacy codebases from Jest to Node |
Node's test runner also waits for promises returned from |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. For more information on how the project manages feature requests, please consult the feature request management document. |
What is the problem this feature will solve?
Hey 👋🏼
I've not found a proper way to run side effects (f.e. truncating tables in between different tests).
In Jest I was able to do something like that:
while keeping
truncateTables
running only before every other testing code.In the Node test runner instead, I found that
before
actions can run at the same time ontest1
whiletest2
is executing (apart of course whenconcurrency
isfalse
).This cause the impossibility of running anything that cause side effects to other tests, since the
before
code is not really isolated when running inconcurrency
mode.What is the feature you are proposing to solve the problem?
Propose a way (a new method, an existing one, whatever), so that I can have the same behavior as in Jest: running a
beforeAll
asyncronous code can't affect in any way other tests.What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered: