Linked Questions

Popular Questions

set NODE_ENV=test causes jest unit test to fail

Asked by At

In my package.json I added "test": "set NODE_ENV=test && jest --watch" to set up my unit tests.

After troubleshooting for a long time to find out why I get this error message:

{import { configure } from 'enzyme';
        ^
SyntaxError: Unexpected token {

I found that by removing set NODE_ENV=test && I resolve the issue. I am now thinking that it must have something to do with the test config instead:

"babel": {
    "env": {
      "test": {
        "presets": [
          [
            "next/babel",
            {
              "preset-env": {
                "modules": "commonjs"
              }
            }
          ],
          "@babel/preset-env"
        ],
        "plugins": [
          "transform-es2015-modules-commonjs"
        ]
      }
    }
  }

Adding "transform-es2015-modules-commonjs" and @babel/preset-env has been suggested in similar posts, but I am not confident it is related to the issue.

I installed cross-env and added it: "test": "cross-env NODE_ENV=test jest --watch" which works perfectly. I am on a windows machine, by the way.

How is cross-env compiling my commands differently than set NODE_ENV=test && jest --watch ??

Related Questions