7

My package.json contains

    "scripts": {
        "test": "CI=true react-scripts test --env=jsdom"
       }

What is the difference if I rewrite the code as

    "scripts": {
      "test": "react-scripts test --env=jsdom CI=true"
    }

Will the unit test fail when built?

monica-bobby
  • 71
  • 1
  • 2
  • I'm also interested. – holms Jun 29 '21 at 18:31
  • 2
    I believe CI=true is added so the tests aren't interactive and complete automatically. If you add CI=true to the end, your automated build will likely be stuck waiting for the test run to finish. – user2966445 Aug 24 '21 at 20:16

1 Answers1

0

The CI=true at the beginning of the line is a way to set environment variables only for the command on the same line.

If you run this on the CLI, this would also work:

export CI=true
react-scripts test

But all following commands will also have the "CI" environment variable set. To avoid this, you can write it in the same line:

CI=true react-scripts test

But if you put the CI=true at the end, it will be passed to the react-scripts command as a parameter, which is most likely ignored.

In all these examples, react-scripts is the command which is executed, even when it's not the first word in the line!

Ken Schumacher
  • 58
  • 1
  • 3
  • 7