question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jest failing to run tests "unexpected token"

See original GitHub issue

Version

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:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
sodateacommented, Jul 31, 2018

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#L34

2reactions
oneMoreTime1357commented, Apr 16, 2021

The first error is fixed in rc.6, if your config file is generated by rc.5, please try update it. a352bdc

The second error is due to an extraneous comma in your tsconfig.json https://github.com/luxtagofficial/Catapult-Vue/blob/e107e35c68c0593f0cb9ddc5d4b6798dd413e2f8/tsconfig.json#L34

Thanks, removeing extraneous comma in tsconfig solved my problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

jest: Test suite failed to run, SyntaxError: Unexpected token ...
Jest sets the env variable to test, so I had to add my presets to the env setting in .babelrc: { "plugins": ["syntax-dynamic-import", ......
Read more >
How I Fixed The Unexpected Token Error In Jest
Not one bit. The "issue" is that Jest only wants to process CommonJS-style code. So for the Jest tests to run, it first...
Read more >
Test suite failed to run: Jest encountered an unexpected token ...
I use updated packages in my projects, but error is the same. So, I cloned this repo, opened it in VS Code, then...
Read more >
[Solved] SyntaxError: Unexpected token '.' Jest Error for Next.js ...
Problem: Running into the following error when trying to run unit tests for a Next.js application using the jest command: ({"Object.
Read more >
Jest encountered an unexpected token - Horizon
test.js ○ Test suite failed to run Jest encountered an unexpected token This usually means that you are trying to import a file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found