13

I am trying to run my Jest unit tests in Team City but I always end up getting the prompt as shown below.

No tests found related to files changed since last commit.
Press `a` to run all tests, or run Jest with `--watchAll`.

Watch Usage
 › Press a to run all tests.
 › Press f to run only failed tests.
 › Press p to filter by a filename regex pattern.
 › Press t to filter by a test name regex pattern.
 › Press q to quit watch mode.
 › Press Enter to trigger a test run.

I tried running yarn test a to run all the tests. But once the tests have completed execution, I'm still getting the same prompt. I tried yarn test a q but that doesn't work. I also tried yarn test a --forceExit and yarn test a --bail but nothing happens, I still get the prompt. How can I run all my Jest tests without getting this prompt as there will be no interaction when running through Team City? Any help would be much appreciated.

tk421
  • 5,775
  • 6
  • 23
  • 34
AnOldSoul
  • 4,017
  • 12
  • 57
  • 118

4 Answers4

12
--ci

When this option is provided, Jest will assume it is running in a CI environment. This changes the behavior when a new snapshot is encountered. Instead of the regular behavior of storing a new snapshot automatically, it will fail the test and require Jest to be run with --updateSnapshot. link

Also, you can change package.json to:

"test": "CI=true react-scripts test --env=jsdom",

which works great.

Your other option is to set CI in the command like any variable:

CI=true yarn test
Senior Pomidor
  • 1,823
  • 1
  • 14
  • 23
  • 5
    I tried "yarn test --ci" and "yarn test a --ci". But I'm still getting the same prompt. Is there another way that'd work without making any changes to the package json? – AnOldSoul Jul 31 '18 at 09:56
4

In TeamCity, edit the setting for your configuration, then select Parameters on the side.

Click Add a new Parameter, and in the dialog popup that appears, under Kind: select Environment variable (env.).

Set the name to env.CI and set the value to true. Click Save.

Next time you run your build, your build should auto-run the tests and move on.

For bonus points (and if you are the administrator) go to Administration then under Projects edit the <Root project>. Click Parameters on the side and set the env.CI parameter to true so you don't have to set this for future projects.

somoso
  • 238
  • 2
  • 7
2
yarn test --coverage

Will run only once (with coverage) and returns 0 on success and 1 on failure.

Edan Chetrit
  • 4,713
  • 2
  • 20
  • 20
2

The following command worked for me.

  • CI=true yarn test
ouflak
  • 2,458
  • 10
  • 44
  • 49