Skip to content
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

jest --bail #6496

Closed
leontastic opened this issue Feb 22, 2019 · 6 comments
Closed

jest --bail #6496

leontastic opened this issue Feb 22, 2019 · 6 comments

Comments

@leontastic
Copy link

Is this a bug report?

No

Feature Request: Support jest --bail

I would like to override the CRA test script with --bail. I can't imagine this would break anything in CRA, but I don't want to npm run eject just because I can't bail on the first test.

@bugzpodder
Copy link

bugzpodder commented Feb 22, 2019

you can pass your own command line arguments to yarn test and it will get forwarded. So:
yarn test --watchAll=false --bail
npm test -- --watchAll=false --bail

@leontastic
Copy link
Author

@bugzpodder I tried your advice, it seems subsequent tests are still run after a test or hook fails. That's not what I expect from --bail. From jest docs:

Alias: -b. Exit the test suite immediately upon n number of failing test suite. Defaults to 1.

Maybe I'm misinterpreting the expected behavior here? Isn't supposed to --bail cause subsequent tests to be skipped when one test fails? Exit the test suite immediately?

@bugzpodder
Copy link

bugzpodder commented Feb 25, 2019

I just ran:
yarn test --watchAll=false --bail and it worked for me. The test runner stopped after the first one failed. I removed the number 2 from my previous command.

@leontastic
Copy link
Author

@bugzpodder Here is a minimal repro I prepared: https://github.com/leontastic/react-scripts-test-script-doesnt-accept-jest-bail-config

The repro was created by calling npx create-react-app to create a new project and adding two failing tests.

Here is my output running yarn test --watchAll=false --bail:

leonli@Leons-MBP:react-scripts-test-script-doesnt-accept-jest-bail-config (master)$ yarn test --watchAll=false --bail
yarn run v1.12.3
$ react-scripts test --watchAll=false --bail
 FAIL  src/App.test.js
  ✓ renders without crashing (22ms)
  ✕ should fail (4ms)
  ✕ should not run this test

  ● should fail

    fail

      10 |
      11 | it('should fail', () => {
    > 12 |   throw new Error('fail')
         |         ^
      13 | });
      14 |
      15 | it('should not run this test', () => {

      at Object.<anonymous>.it (src/App.test.js:12:9)

  ● should not run this test

    fail

      14 |
      15 | it('should not run this test', () => {
    > 16 |   throw new Error('fail')
         |         ^
      17 | });
      18 |

      at Object.<anonymous>.it (src/App.test.js:16:9)

Test Suites: 1 failed, 1 total
Tests:       2 failed, 1 passed, 3 total
Snapshots:   0 total
Time:        1.017s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Clearly the subsequent failing test is being run here, where I would expect --bail to skip the rest of the tests.

@bugzpodder
Copy link

bugzpodder commented Mar 5, 2019

Note that jest runs a small number of tests in parallel by default, you'll have to disable it using another flag: https://jestjs.io/docs/en/cli#maxconcurrency-num

@leontastic
Copy link
Author

I did more digging and it looks like this behavior is by design 😱jestjs/jest#7434

I guess this makes this issue out of CRA's control, I'll close this issue and hope someone fixes this in Jest soon or PR Jest myself if there's no progress 😕

Thank you for your time and patience looking into this @bugzpodder 😄

@lock lock bot locked and limited conversation to collaborators Mar 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants