Jest failing to run tests "unexpected token"
See original GitHub issueVersion
3.0.0-rc.10
Node and OS info
Node 10.5.0 || 8.11.3 / yarn 1.6.0 / npm 6.1.0 || 5.6.0 / Windows 10
Steps to reproduce
to reproduce this error you can clone this repo.
What is expected?
Test to pass
What is actually happening?
Test are failing with the following error:
tests/unit/HelloWorld.spec.ts
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
SyntaxError: Unexpected token ] in JSON at position 634
at JSON.parse (<anonymous>)
at parse (node_modules/tsconfig/src/tsconfig.ts:195:15)
at readFileSync (node_modules/tsconfig/src/tsconfig.ts:181:10)
at Object.loadSync (node_modules/tsconfig/src/tsconfig.ts:151:18)
at loadTypescriptConfig (node_modules/vue-jest/lib/load-typescript-config.js:39:41)
at compileTypescript (node_modules/vue-jest/lib/compilers/typescript-compiler.js:9:20)
at processScript (node_modules/vue-jest/lib/process.js:22:12)
at Object.module.exports [as process] (node_modules/vue-jest/lib/process.js:41:18)
This error is not consistent in the sense that sometimes instead of this portion of the error:
SyntaxError: Unexpected token ] in JSON at position 634
at JSON.parse (<anonymous>)
I get a syntax error about a core-js
import statement
My guess is that there is some problem with transpilation but I can’t figure out how to fix it.
another thing is that I have created a fresh new repo from vue-ui
where the tests where passing then copied my src
my tslint.config
and tsconfig
where the test was passing perfectly. then the moment I migrated the jest.config
file I got the same error but the mind-blowing thing is that I tried to revert the changes back and kept getting the same error.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (2 by maintainers)
The first error is fixed in rc.6, if your config file is generated by rc.5, please try update it. https://github.com/vuejs/vue-cli/commit/a352bdc4dae0032bcfd1f313097e73053e737d24
The second error is due to an extraneous comma in your
tsconfig.json
https://github.com/luxtagofficial/Catapult-Vue/blob/e107e35c68c0593f0cb9ddc5d4b6798dd413e2f8/tsconfig.json#L34Thanks, removeing extraneous comma in tsconfig solved my problem