Reputation: 4728
I'm trying to make Jest work again on a project developped 1 year ago and not maintained.
I have an error with path of setupFilesAfterEnv
or transform
.
the error i get when i run "yarn test"
$ jest __testsv2__ --config=./jest.config.js
● Validation Error:
Module <rootDir>/jest/setup.js in the setupFilesAfterEnv option was not found.
<rootDir> is: /Users/alain/dev/ddf/release
Configuration Documentation:
https://jestjs.io/docs/configuration.html
error Command failed with exit code 1.
my filesystem, in /Users/alain/dev/ddf/release/ i have
babel.config.js
jest.config.js
/jest
/setup
setup.js ( so full path is : /Users/alain/dev/ddf/release/jest/setup.js )
staticFileAssetTransform.js ( so full path is : /Users/alain/dev/ddf/release/jest/staticFileAssetTransform.js )
My package.json
{ ...
"scripts": {
"test": "jest __testsv2__ --config=./jest.config.js"
...
}
}
babel.config.js
module.exports = function(api) {
api.cache(false);
const presets = ['@babel/preset-env', '@babel/preset-react'];
const plugins = [['@babel/proposal-object-rest-spread'],];
return {
presets, plugins, sourceMaps: "inline",
ignore: [(process.env.NODE_ENV !== 'test' ? "**/*.test.js" : null) ].filter(n => n)
};
};
jest.config.js
module.exports = {
resolver: 'browser-resolve',
clearMocks: true,
moduleNameMapper: { '\\.(css|less|styl|md)$': 'identity-obj-proxy' },
// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: ['./jest/setup.js'], // don't work too
setupFilesAfterEnv: ['<rootDir>/jest/setup.js'],
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
testPathIgnorePatterns: ['/node_modules/', '/__gql_mocks__/'],
// A map from regular expressions to paths to transformers
transform: {
'^.+\\.js$': './jest/babelRootModeUpwardTransform.js',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/jest/staticFileAssetTransform.js',
},
};
Upvotes: 29
Views: 43231
Reputation: 31
It's incorrect setup in the IDE (webstorm is in my case). Go to Edit configuration and then edit working directory
Upvotes: 3
Reputation: 11
I was struggling with this issue too, after cracking my head around I discovered we can load the setup file using the command line arg itself. Run jest --setupFilesAfterEnv=<rootDir>/jest/setup.js
and it will get discovered and loaded. Hope this helps.
Upvotes: 0
Reputation: 33193
I got this error when I had cd
ed into a test folder and run ng test
and I thought I was going to have to revert a lot of work. But it appears I was in the wrong folder.
So ng test
isn't expected to run anywhere but root of yoru project and if you do, you get an unintelligible error message.
Upvotes: 2
Reputation: 1442
For those coming here, make sure you prefix the path with <rootDir>
Like this:
setupFilesAfterEnv: ['<rootDir>/node_modules/@hirez_io/observer-spy/dist/setup-auto-unsubscribe.js']
Upvotes: 8
Reputation: 101
You might want to delete your node modules, package-lock.json and run npm i
again, I had a similar issue and that was a fix for me. Also try npm cache clean --force
Upvotes: 3