Description
If you have
"jest": {
"testEnvironment": "node"
},
set in your package.json, and you run an npm command with jest in it (e.g. "test": "jest"), you'll get:
ReferenceError: AbortController is not defined
This happens despite AbortController being available in Node v16.13.0.
Running code using AbortController without Jest works fine.
It seems CRA is changing Jest's node environment somehow?
I'm aware that CRA does not allow the "testEnvironment" setting to be set in the package.json when using react-scripts test. I simply did not expect setting the "testEnvironment" setting to its default ("node") to seemingly change the environment.
Environment
CRA v4.0.3
Node v16.13.0
npm v8.1.0
Steps to reproduce
- Setup a fresh CRA project
- Delete App.test.js
- Add 2 new files to src:
// src/abortControllerCode.js
function start() {
const abortController = new AbortController();
abortController.abort();
return 'foo';
}
module.exports = { start }
and
// src/abortControllerCode.test.js
const { start } = require('./abortControllerCode');
describe('AbortController test', () => {
it('Should not throw', () => {
expect(start()).toBe('foo');
})
});
- Replace the default test command with:
"test": "jest", in your package.json
- Add
"jest": {
"testEnvironment": "node"
},
To your package.json
- Run
npm test
I get the following output from that.

Description
If you have
set in your package.json, and you run an npm command with jest in it (e.g.
"test": "jest"), you'll get:This happens despite
AbortControllerbeing available in Node v16.13.0.Running code using
AbortControllerwithout Jest works fine.It seems CRA is changing Jest's node environment somehow?
I'm aware that CRA does not allow the
"testEnvironment"setting to be set in the package.json when usingreact-scripts test. I simply did not expect setting the"testEnvironment"setting to its default ("node") to seemingly change the environment.Environment
CRA v4.0.3
Node v16.13.0
npm v8.1.0
Steps to reproduce
and
"test": "jest",in your package.jsonTo your package.json
npm testI get the following output from that.
