Reputation: 442
I am trying to set up some unit tests using Jest for a new project using sails.js
Unfortunately Jest appears to be scanning and parsing into the node_modules directory of the sails project, where it gets a parse error on a package.json file. This file is not actually a valid package.json file, it is a template from which sails project's package.json files are generated.
Is this a bug that needs to be fixed in Jest, or can I use a configuration option to get it to ignore this file/directory?
Reproduction instructions:
npm install -g sails jest-cli
sails new jesttest
cd jesttest
npm install
jest
Error message:
Using Jest CLI v0.2.1
Error parsing `c:\work\jesttest\node_modules\sails\node_modules\sails-generate\node_modules\sails-generate-adapter\templates\boilerplate\package.json`!
c:\Users\USERNAME\AppData\Roaming\npm\node_modules\jest-cli\node_modules\node-haste\lib\loader\ProjectConfigurationLoader.js:64
throw e;
^
SyntaxError: Unexpected token <
at Object.parse (native)
at ProjectConfigurationLoader.loadFromSource (c:\Users\USERNAME\AppData\Roaming\npm\node_modules\jest-cli\node_modules\node-haste\lib\loader\ProjectConfigurationLoader.js:61:46)
at c:\Users\USERNAME\AppData\Roaming\npm\node_modules\jest-cli\node_modules\node-haste\lib\loader\ResourceLoader.js:90:10
at fs.js:266:14
at c:\Users\USERNAME\AppData\Roaming\npm\node_modules\jest-cli\node_modules\graceful-fs\graceful-fs.js:104:5
at Object.oncomplete (fs.js:107:15)
Upvotes: 3
Views: 915
Reputation: 15028
Deeper explanation if anyone's interested: the "package.json" inside of that adapter generator is not a package.json, but an ejs template for one. sails has a lot of those, so if you use more than one add-on, you'll have to keep adding things to that list. sidenote, you won't have this problem if you have your client code in a separate project (repo).
Upvotes: 1
Reputation: 442
It turned out to be fairly easy - for anyone else who has the same problem just add the following to your package.json file:
"scripts": {
"start": "node app.js",
"debug": "node debug app.js",
"test": "jest"
},
"jest": {
"modulePathIgnorePatterns": ["sails-generate-adapter"]
}
Upvotes: 6