babel-jest is erroring out every time I try to transform some of my TypeScript files. The specific error is:
ReferenceError: [BABEL] redacted\accelerator-core\config\testing\setupTests.ts: Unknown option: redacted\accelerator-core\node_modules\babel-preset-react-app\index.js.overrides. Check out http://babeljs.io/docs/usage/options/ for more information about options.
A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:
Invalid:
`{ presets: [{option: value}] }`
Valid:
`{ presets: [['presetName', {option: value}]] }`
For more detailed information on preset configuration, please see https://babeljs.io/docs/en/plugins#pluginpresets-options. (While processing preset: "redacted\\accelerator-core\\node_modules\\babel-preset-react-app\\index.js")
The specific failure seems to be that OptionManager.prototype.mergeOptions in babel-jest expects to see an overrides property in babel-core/lib/transformation/file/optionsconfig.js. When this is not found, it throws.
Steps to reproduce the behavior:
dev branch.npm installnpm t.I expect the files to be transformed correctly and for babel-jest not to throw an error.
https://github.com/furkleindustries/accelerator-core
npx envinfo --preset jestSystem:
OS: Windows 10
CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
Binaries:
Node: 8.9.4 - C:\Program Files\nodejs\node.EXE
npm: 6.5.0 - C:\Program Files\nodejs\npm.CMD
I don't get an error when running your reproduction
$ npm t -- --dontWatch
> [email protected] test /Users/simen/Development/accelerator-core
> node scripts/test.js --env=jsdom "--dontWatch"
PASS src/components/App/App.test.tsx
โ Renders shallowly without crashing. (5ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.745s, estimated 2s
Ran all test suites.
Thank you for taking a look. The version (and results) you are seeing are for the master branch. The error is on the dev branch at https://github.com/furkleindustries/accelerator-core/tree/dev.
Ah right! ๐
I keep getting [Error: ENOENT: no such file or directory, open '/Users/simen/repos/accelerator-core/passages/passages-manifest.ts'], btw.
Beyond that though, your error is due to jest locating the wrong babel-jest. Either running npm dedupe will fix it, or this diff to your config:
diff --git i/config/testing/jest.config.js w/config/testing/jest.config.js
index 46bccb0..fb75f43 100644
--- i/config/testing/jest.config.js
+++ w/config/testing/jest.config.js
@@ -20,7 +20,7 @@ module.exports = {
],
transform: {
- '^.+\\.[jt]sx?$': 'babel-jest',
+ '^.+\\.[jt]sx?$': require.resolve('babel-jest'),
'^.+\\.css$': '<rootDir>/config/testing/cssTransform.js',
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '<rootDir>/config/testing/fileTransform.js',
},
You can see babel-jest is not deduped by running npm ls babel-jest. Rerun that command after npm dedupe to see it's now deduped, and it works correctly
I'm almost positive that error is because the globalSetup wasn't being transpiled, and it is responsible for generating that file pre-testing. Anyway, this works perfectly! Thanks so much for your time.
globalSetup (and globalTeardown) is transpiled in Jest 24, fwiw ๐ But I doubt that's the reason, as jest would throw if globalSetup contained invalid syntax. Anyways, that's off topic, glad it worked for you!
Most helpful comment
Ah right! ๐
I keep getting
[Error: ENOENT: no such file or directory, open '/Users/simen/repos/accelerator-core/passages/passages-manifest.ts'], btw.Beyond that though, your error is due to jest locating the wrong
babel-jest. Either runningnpm dedupewill fix it, or this diff to your config: