Parse error with Jest with Sails.js

I am trying to set up some unit tests using Jest for a new project using sails.js

Unfortunately Jest seems to be scanning and parsing in the sails project's node_modules directory where it gets a parse error in the package.json file. This file is not actually a valid package.json file, it is the template from which the package.json package files for sails are generated.

Is this a bug that needs to be fixed in Jest, or can I use a config option to make it ignore this file / directory?

Play 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)

      

+3


source to share


2 answers


It turned out to be pretty straightforward - for anyone else having 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"]
}

      

+6


source


Deeper explanation if anyone is interested: "package.json" inside this adapter generator is not package.json, but ejs template for one. sails have a lot of them, so if you are using multiple add-ons you will need to add things to this list. sidenote, you won't have this problem if you have the client code in a separate project (repo).



+1


source







All Articles