vuejs / vue-jest

Jest Vue transformer
MIT License
748 stars 156 forks source link

SyntaxError: Unexpected token } in JSON at position 1097 #322

Closed asolopovas closed 3 years ago

asolopovas commented 3 years ago

Hi,

npm -v ;yarn -v; node -v 7.5.3 1.22.10 v15.9.0

vue-jest: 3.0.7

I am receiving the following error when testing the typescript class-based Vue component. It was working fine when I used the standard Vue component as soon as I migrated to typescript things started to fall apart. I have created a test repo, you can see it at https://github.com/asolopovas/vue-jest-test-repo, typescript tests are fine the error is thrown only when using Compoment.vue with lang="ts" attribute

Here is the error that I get:

 FAIL  specs/components/Products.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:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
     • 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 1097
        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 find (node_modules/vue-jest/lib/load-typescript-config.js:33:39)
      at loadTypescriptConfig (node_modules/vue-jest/lib/load-typescript-config.js:73:26)
      at compileTypescript (node_modules/vue-jest/lib/compilers/typescript-compiler.js:9:20)
      at processScript (node_modules/vue-jest/lib/process.js:23:12)
      at Object.module.exports [as process] (node_modules/vue-jest/lib/process.js:42:18)
      at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:464:35)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.988 s
Ran all test suites.
error Command failed with exit code 1.
asolopovas commented 3 years ago

update to 4.01 fixed the problem...

eytienne commented 3 years ago

Why my search engine ditn't return that? ... It is surely linked to #190