-
-
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
Feature Request: Add --runInBand to package.json options #3215
Comments
I'd prefer not to do this. -i is an escape hatch. It would be better to find a way to run the tests in parallel.
…________________________________
From: James McGuigan <[email protected]>
Sent: Tuesday, March 28, 2017 6:24:32 AM
To: facebook/jest
Cc: Subscribed
Subject: [facebook/jest] Feature Request: Add --runInBand to package.json options (#3215)
This is a feature request.
I currently have a setup that involves jest tests asyncronously creating and re-aliasing elasticsearch indices and part of their setup and tear down routines.
The tests run perfectly fine if I specify jest --runInBand on the command line.
If I run them without --runInBand I get random test failures due to the inherent race conditions with running these tests asynchronously.
What I would like is an option in package.json:
{
"jest": {
"runInBand": true
}
}
Such that the flag is automatically applied to jest (like all the other package.json settings), without needing to manually specify it on the command line each time.
The lack of this feature may potentially confuse other developers on my team who attempt to run the jest tests without being explicitly aware the tests are dependent on the --runInBand flag being present, thus observing a broken test suite.
package.json is the correct place to document this configuration dependancy
Thank you.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<#3215>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AAA0KI5INcWs1BFGWPxPeoYDHKjg1uQrks5rqCkQgaJpZM4Mq2Fy>.
|
Create a npm script and don't think about it? "test:es": "jest -i" |
Just want to give my 2 cents on this one. We use jest for lots of integration tests in a project and set Yes we could maybe sandbox it out so it would run, but really, we'd rather just run the tests in serial and be done with it. I think it's a great idea to encourage developers to write tests such that they won't collide with one another, but it shouldn't be annoying to run jest without it. Anyways, this is one man's opinion. |
@dickeyxxx you can put your configuration into a JS file and set |
seems it still does the same thing: heroku/cli-engine@310aa52
|
This would be very useful for jest projects as well (if I have a runner for a e2e tests + unit tests, I want to be able to run e2e inBand, and unitTests in parallel, right now my only option to run all of them one or the other way) |
Hi, I know this issue is closed but there is a particular reason why the command options you can pass are different from the configuration options? I mean, we can always use like this: "scripts": {
"test": "jest --runInBand"
},
"jest": {
"bail": true,
"verbose": true
} Compared to this: "jest": {
"bail": true,
"verbose": true,
"runInBand": true
} It's more readable and manageable all in one place, this example is simple but can be more complex in certain projects. |
Also another valid use case is when you are in a monorepo configuration and running jest globally with a If one of your packages has to run serially, the only option is to run everything serially with In an extreme case, even if all your packages must run serially, jest should still be able to run each projects in parallel. |
The |
In the case of It's designed to be used when needed, not all the time, so adding it as config doesn't really make sense. As an aside, runners can say that they have to run serially, if that helps |
@SimenB how? |
See #5712 |
please consider reopening. Even though it has forced me to improve our test pipeline significantly(instead of passing runInBand everywhere I made sure we run each worker against his own DB), it would be very nice to have for projects which really need a serial test runner. |
If there is a CLI option there should be a config file equivalent. |
@capaj & @AntonNarkevich As pointed out it's currently possible to configure a runner to run serially. Here is a simple example:
// serial-jest-runner.js
const DefaultJestRunner = require('jest-runner');
class SerialJestRunner extends DefaultJestRunner {
constructor(...args) {
super(...args);
this.isSerial = true;
}
}
module.exports = SerialJestRunner; // jest.config.js
{
runner: './serial-jest-runner.js',
} |
So in order to configure Jest to do something it can do with a flag, you need to create a custom runner whose sole purpose at 11 lines of code is to do something a configuration like could do in 1 line? That's a bit much.
I'd recommend avoiding spiraling config value synonyms. |
This seems to be available now but undocumented as |
@danielzgtg seems like its gone - it really makes 0 sense at all why they wouldn't surface a cli feature in the config, when there's a clear reason to want to run certain tests in sequential order. Not everything is going to be parallelized, this is ridiculous. |
Why is this closed? It's a valid request that's been ignored for several years. |
Apparently the jest philosophy is that they know what we want better than we do? I find it incomprehensible that that there are options that exist on the command line, but cannot be passed in the configuration file. It's the first time I've seen it, and I imagine it was actually more work to make it like this than it would be to allow everything in both command line and config. Would a PR be accepted if I fix this? |
The think the design philosophy was to encourage/enforce junior developers to write unit tests in an asynchronous manner and prevent people from complaining that the jest framework is slow because they took the easy way out by setting synchronous as default. Though as we all become senior developers, we understand that valid edgecases do indeed exist, and the wisdom of "Learn the rules well so you know how to break them properly" becomes more apparent. |
Then apparently Jest's philosophy is that they want to make it hard for me to write end-to-end tests, which must not run in parallel for performance reasons |
Adding very handy option to config file (which is support in CLI), won't magically push junior developers to turn an asynchronous manner off. Can't understand why it's not supported in configuration file. |
For some reason, I would like to add it once in |
On ubuntu with a very decent machine (XPS 13 with 16gb RAM and SSD m2), testing a simple lambda projects (backend) with 10 tests, without --runInBand it freezes completly the machine. Would be REALLY nice to have this under config file. |
I had to laugh at this because on every machine I can find, on every project I use Jest, using A config file entry seems just mandatory to me. Even better would be |
It's so strange this is not a config option for such a long time. Will make a lot of things so much easier and reliable. |
I mean it essentially is available, just set workers to 1, it does the same thing (#3215 (comment)) |
Yes, you can set workers to 1, but it's only supported as an immediate CLI parameter, not configuration (i.e. in the config file or as an environment variable). That's the complaint in this ticket. |
How so? You can just set in your jest config
And it runs in band. Maybe this wasn’t working before? I just tested again now and it works fine. |
This does not work if {
"name": "foobar",
"version": "1.0.0",
"jest": {
"projects": [
{
"displayName": "e2e",
"maxWorkers": 1
}
]
}
} Moreover, I don't understand why this issue is closed. The |
can we reopen this please? Thanks! |
Serverless events based Functions testing case makes this issue as a catastrophic one. |
Why are maintainers of Jest taking a hard stance against adding the I think we probably all agree that if you can, run your tests in parallel and having that as the default option is the best way. I also guess most of us try to have them running in parallel and try to have more unit tests than integration tests. But then reality comes knocking, and you simply have to get stuff done, and you want to have tests, even if they are not the holy grail of tests, you still want to have them, so you got for an integration test, and since your project is maybe setup in a way, that you can't run the tests at the same time, you have to to use the dreaded Now that you have started using BUT NO: The devs that make the testing tool you're using deem this as BAD practice and want to make this as painful as they can I'm sorry, but can we have a little more understanding here and try to make this tool support the needs of the projects and developers who are using jest by reopening this issue and hopefully adding the |
In this case, I want a developer to be able to just right-click a test file in their IDE and it runs without hitch. Having a config flag would absolutely be great. |
This is a feature request.
I currently have a setup that involves jest tests asyncronously creating and re-aliasing elasticsearch indices and part of their setup and tear down routines.
The tests run perfectly fine if I specify jest --runInBand on the command line.
If I run them without --runInBand I get random test failures due to the inherent race conditions with running these tests asynchronously.
What I would like is an option in package.json:
Such that the flag is automatically applied to jest (like all the other package.json settings), without needing to manually specify it on the command line each time.
The lack of this feature may potentially confuse other developers on my team who attempt to run the jest tests without being explicitly aware the tests are dependent on the --runInBand flag being present, thus observing a broken test suite.
package.json is the correct place to document this configuration dependancy
Thank you.
The text was updated successfully, but these errors were encountered: