How to get Jest to ignore package.json files?

Viewed 252

I have a project with yeoman generators. The generators contain package.json template files that are used to generate actual package.json files in the generated project. As they are templates, they are not valid JSON.

Even though I don't run any tests in the generator sub-directories and there is no reason for Jest to open these files, it does visit them and throw invalid JSON errors. I've tried all the combinations I can find of the various Jest ignore options and Jest won't ignore these files.

I wonder if anyone knows how to persuade Jest not to visit these files.

The error looks like this:

Error: Cannot parse .../generator-terraform/generators/crud-api/templates/api/package.json as JSON: Unexpected token < in JSON at position 193
    at Object.worker (.../generator-terraform/node_modules/jest-haste-map/build/worker.js:146:13)
    at execFunction (.../generator-terraform/node_modules/jest-worker/build/workers/processChild.js:140:17)
    at execHelper (.../generator-terraform/node_modules/jest-worker/build/workers/processChild.js:124:5)
    at execMethod (.../generator-terraform/node_modules/jest-worker/build/workers/processChild.js:128:5)
    at process.messageListener (.../generator-terraform/node_modules/jest-worker/build/workers/processChild.js:46:7)
    at process.emit (events.js:314:20)                      
    at emit (internal/child_process.js:902:12)                             
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
1 Answers

I solved it this way jest --modulePathIgnorePatterns='./template'

Related