Closed ai closed 7 years ago
If you have invalid JSON files in your project intentionally, you can ignore them using modulePathIgnorePatterns
in your config.
@cpojer could you provide an example? I'm not sure how modulePathIgnorePatterns
resolves those paths. I have the same test/fixtures/package.json
pattern but in my case the json file is broken intentionally. I'm getting the same SyntaxError: Unexpected token } in JSON at position 32
all the time trying multiple patterns.
Well ... digging a bit into jest-haste-map
I found they user internally an option called ignorePattern
which is being set by jest-runtime
in the following part:
const ignorePattern = new RegExp(
[config.cacheDirectory].concat(config.modulePathIgnorePatterns).join('|'),
);
This becames a huge RegEx that ignore those files/folders to be crawled
by jest-haste-map
and thus display errors or warnings. In my case, it was inteded to have some corrupted JSON files in my fixtures for testing purposes that jest
was trying to parse them causing the origin issue of this ticket.
With the following setup (be careful with the Regex otherwise will never match) it works perfectly.
modulePathIgnorePatterns: [
'<rootDir>/unit/partials/mock-store/.*/package.json',
'<rootDir>/functional/store/.*/package.json',
'<rootDir>/unit/partials/store/.*/package.json',
'<rootDir>/../coverage',
'<rootDir>/../docs',
'<rootDir>/../debug',
'<rootDir>/../scripts',
'<rootDir>/../.circleci',
'<rootDir>/../tools',
'<rootDir>/../wiki',
'<rootDir>/../systemd',
'<rootDir>/../flow-typed',
'<rootDir>unit/partials/mock-store/.*/package.json',
'<rootDir>functional/store/.*/package.json',
'<rootDir>/../build',
'<rootDir>/../.vscode/',
],
more info: https://github.com/verdaccio/verdaccio/blob/master/jest.config.unit.js
One more thing, excluding files from jest runtime execution, it seems to boost a bit since has less file to parse. https://github.com/verdaccio/verdaccio/commit/ccb73404a89bd08ba53672e735424ffa05ab924d
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
Do you want to request a feature or report a bug?
bug
What is the current behavior?
Jest raise error if it finds broken
package.json
somewhere in the project (for example, in text fixtures).If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can
yarn install
andyarn test
.test/fixtures/package.json
file with{
content.npx jest
What is the expected behavior?
Raise error only if
PROJECT/package.json
is broken.Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
I saw error only after update to Jest 21.
Stacktrace: