It seems its failing on the tsconfig file? but I even tried to ignore tsconfig and it still fails parsing the tsconfig.json
Running jest
` FAIL src/components/__tests__/StartPage.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 142
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:479:35)`
``0 info it worked if it ends with ok
1 verbose cli [ 'D:\\nodejs\\node.exe',
1 verbose cli 'D:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'test' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle [email protected]~pretest: [email protected]
6 info lifecycle [email protected]~test: [email protected]
7 verbose lifecycle [email protected]~test: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~test: PATH: D:\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\CarryAlex\Desktop\VueWebsite\createagame\node_modules\.bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;D:\nodejs\;C:\Program Files\PostgreSQL\11\lib;C:\OpenSSL-Win64\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\TortoiseHg\;C:\Program Files\PuTTY\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;D:\VirtualBox;C:\Users\CarryAlex\AppData\Local\Android\Sdk\tools\bin;C:\Users\CarryAlex\AppData\Local\Android\Sdk\platform-tools;C:\Users\CarryAlex\AppData\Local\Android\Sdk\emulator;C:\Android;D:\wamp\bin\php\php7.3.5;D:\wamp\bin\php\php7.3.5\ext;C:\ProgramData\ComposerSetup\bin;C:\Users\CarryAlex\AppData\Local\Microsoft\WindowsApps;D:\Microsoft VS Code\Microsoft VS Code\bin;C:\Users\CarryAlex\AppData\Roaming\npm;D:\Program Files (x86)\heroku\bin;D:\wamp\www\heroku\bin;C:\Users\CarryAlex\AppData\Roaming\Composer\vendor\bin;
9 verbose lifecycle [email protected]~test: CWD: C:\Users\CarryAlex\Desktop\VueWebsite\createagame
10 silly lifecycle [email protected]~test: Args: [ '/d /s /c', 'jest' ]
11 silly lifecycle [email protected]~test: Returned: code: 1 signal: null
12 info lifecycle [email protected]~test: Failed to exec test script
13 verbose stack Error: [email protected] test:jest
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (D:\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack at EventEmitter.emit (events.js:198:13)
13 verbose stack at ChildProcess.<anonymous> (D:\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:198:13)
13 verbose stack at maybeClose (internal/child_process.js:982:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid [email protected]
15 verbose cwd C:\Users\CarryAlex\Desktop\VueWebsite\createagame
16 verbose Windows_NT 10.0.18362
17 verbose argv "D:\\nodejs\\node.exe" "D:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
18 verbose node v10.16.3
19 verbose npm v6.9.0
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] test:jest`
22 error Exit status 1
23 error Failed at the [email protected] test script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
## ts-jest.log
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","version":"25.4.0"},"message":"creating Importer singleton","sequence":1,"time":"2020-04-22T10:30:36.689Z"}
{"context":{"allowJs":false,"logLevel":20,"namespace":"jest-preset","package":"ts-jest","version":"25.4.0"},"message":"creating jest presets not handling JavaScript files","sequence":2,"time":"2020-04-22T10:30:36.696Z"}
{"context":{"actualVersion":"25.4.0","expectedVersion":">=25 <26","logLevel":20,"namespace":"versions","package":"ts-jest","version":"25.4.0"},"message":"checking version of jest: OK","sequence":3,"time":"2020-04-22T10:30:36.699Z"}
{"context":{"baseOptions":{},"logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformerId":1,"version":"25.4.0"},"message":"created new transformer","sequence":4,"time":"2020-04-22T10:30:36.699Z"}
{"context":{"fileName":"C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame\\src\\components\\__tests__\\StartPage.spec.ts","logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformOptions":{"config":{"automock":false,"browser":false,"cache":true,"cacheDirectory":"C:\\Users\\CarryAlex\\AppData\\Local\\Temp\\jest","clearMocks":false,"coveragePathIgnorePatterns":["\\\\node_modules\\\\"],"cwd":"C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{},"haste":{"computeSha1":false,"providesModuleNodeModules":[],"throwOnModuleCollision":false},"moduleDirectories":["node_modules"],"moduleFileExtensions":["js","ts","json","vue"],"moduleNameMapper":[],"modulePathIgnorePatterns":[],"name":"7ae6edb01373c74b3d65f5f4ee39af8a","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame","roots":["C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame"],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"snapshotSerializers":[],"testEnvironment":"C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame\\node_modules\\jest-environment-jsdom\\build\\index.js","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":[],"testPathIgnorePatterns":["\\\\node_modules\\\\"],"testRegex":["(\\\\__tests__\\\\.*|(\\.|\\\\)(test|spec))\\.(jsx?|tsx?)$"],"testRunner":"C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame\\node_modules\\jest-jasmine2\\build\\index.js","testURL":"http://localhost/","timers":"real","transform":[[".*\\.(vue)$","C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame\\node_modules\\vue-jest\\vue-jest.js",{}],["^.+\\.tsx?$","C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame\\node_modules\\ts-jest\\dist\\index.js",{}]],"transformIgnorePatterns":["\\\\node_modules\\\\"],"watchPathIgnorePatterns":[]},"instrument":false,"rootDir":"C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame","supportsDynamicImport":false,"supportsStaticESM":false},"transformerId":1,"version":"25.4.0"},"message":"computing cache key for C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame\\src\\components\\__tests__\\StartPage.spec.ts","sequence":5,"time":"2020-04-22T10:30:36.700Z"}
{"context":{"logLevel":30,"namespace":"jest-transformer","package":"ts-jest","transformerId":1,"version":"25.4.0"},"message":"no matching config-set found, creating a new one","sequence":6,"time":"2020-04-22T10:30:36.700Z"}
{"context":{"config":{"automock":false,"browser":false,"cache":true,"cacheDirectory":"C:\\Users\\CarryAlex\\AppData\\Local\\Temp\\jest","clearMocks":false,"coveragePathIgnorePatterns":["\\\\node_modules\\\\"],"cwd":"C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{},"haste":{"computeSha1":false,"providesModuleNodeModules":[],"throwOnModuleCollision":false},"moduleDirectories":["node_modules"],"moduleFileExtensions":["js","ts","json","vue"],"moduleNameMapper":[],"modulePathIgnorePatterns":[],"name":"7ae6edb01373c74b3d65f5f4ee39af8a","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame","roots":["C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame"],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"snapshotSerializers":[],"testEnvironment":"C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame\\node_modules\\jest-environment-jsdom\\build\\index.js","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":[],"testPathIgnorePatterns":["\\\\node_modules\\\\"],"testRegex":["(\\\\__tests__\\\\.*|(\\.|\\\\)(test|spec))\\.(jsx?|tsx?)$"],"testRunner":"C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame\\node_modules\\jest-jasmine2\\build\\index.js","testURL":"http://localhost/","timers":"real","transform":[[".*\\.(vue)$","C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame\\node_modules\\vue-jest\\vue-jest.js",{}],["^.+\\.tsx?$","C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame\\node_modules\\ts-jest\\dist\\index.js",{}]],"transformIgnorePatterns":["\\\\node_modules\\\\"],"watchPathIgnorePatterns":[]},"logLevel":20,"namespace":"backports","package":"ts-jest","transformerId":1,"version":"25.4.0"},"message":"backporting config","sequence":7,"time":"2020-04-22T10:30:36.701Z"}
{"context":{"jestConfig":{"automock":false,"browser":false,"cache":true,"cacheDirectory":"C:\\Users\\CarryAlex\\AppData\\Local\\Temp\\jest","clearMocks":false,"coveragePathIgnorePatterns":["\\\\node_modules\\\\"],"cwd":"C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{"ts-jest":{}},"haste":{"computeSha1":false,"providesModuleNodeModules":[],"throwOnModuleCollision":false},"moduleDirectories":["node_modules"],"moduleFileExtensions":["js","ts","json","vue"],"moduleNameMapper":[],"modulePathIgnorePatterns":[],"name":"7ae6edb01373c74b3d65f5f4ee39af8a","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame","roots":["C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame"],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"snapshotSerializers":[],"testEnvironment":"C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame\\node_modules\\jest-environment-jsdom\\build\\index.js","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":[],"testPathIgnorePatterns":["\\\\node_modules\\\\"],"testRegex":["(\\\\__tests__\\\\.*|(\\.|\\\\)(test|spec))\\.(jsx?|tsx?)$"],"testRunner":"C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame\\node_modules\\jest-jasmine2\\build\\index.js","testURL":"http://localhost/","timers":"real","transform":[[".*\\.(vue)$","C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame\\node_modules\\vue-jest\\vue-jest.js",{}],["^.+\\.tsx?$","C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame\\node_modules\\ts-jest\\dist\\index.js",{}]],"transformIgnorePatterns":["\\\\node_modules\\\\"],"watchPathIgnorePatterns":[]},"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"version":"25.4.0"},"message":"normalized jest config","sequence":8,"time":"2020-04-22T10:30:36.701Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"tsJestConfig":{"compiler":"typescript","compilerHost":false,"diagnostics":{"ignoreCodes":[6059,18002,18003],"pretty":true,"throws":true},"incremental":true,"isolatedModules":false,"packageJson":{"kind":"file"},"transformers":[],"tsConfig":{"kind":"file"}},"version":"25.4.0"},"message":"normalized ts-jest config","sequence":9,"time":"2020-04-22T10:30:36.702Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"version":"25.4.0"},"message":"babel is disabled","sequence":10,"time":"2020-04-22T10:30:36.730Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","requireResult":{"exists":true,"given":"typescript","path":"C:\\Users\\CarryAlex\\Desktop\\VueWebsite\\createagame\\node_modules\\typescript\\lib\\typescript.js"},"version":"25.4.0"},"message":"loaded module typescript","sequence":11,"time":"2020-04-22T10:30:36.732Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","version":"25.4.0"},"message":"patching typescript","sequence":12,"time":"2020-04-22T10:30:36.732Z"}
{"context":{"actualVersion":"3.8.3","expectedVersion":">=3.4 <4","logLevel":20,"namespace":"versions","package":"ts-jest","version":"25.4.0"},"message":"checking version of typescript: OK","sequence":13,"time":"2020-04-22T10:30:36.733Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"tsConfigFileName":"C:/Users/CarryAlex/Desktop/VueWebsite/createagame/tsconfig.json","version":"25.4.0"},"message":"readTsConfig(): reading C:/Users/CarryAlex/Desktop/VueWebsite/createagame/tsconfig.json","sequence":14,"time":"2020-04-22T10:30:36.733Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"tsconfig":{"input":{"compilerOptions":{"experimentalDecorators":true},"exclude":["node_modules"],"include":["src//.ts","src//.vue"]},"resolved":{"compileOnSave":false,"configFileSpecs":{"excludeSpecs":["node_modules"],"includeSpecs":["src//.ts","src//.vue"],"validatedExcludeSpecs":["node_modules"],"validatedIncludeSpecs":["src//.ts","src//.vue"],"wildcardDirectories":{"c:/users/carryalex/desktop/vuewebsite/createagame/src":1}},"errors":[],"fileNames":["C:/Users/CarryAlex/Desktop/VueWebsite/createagame/src/main.ts","C:/Users/CarryAlex/Desktop/VueWebsite/createagame/src/shims-vue.d.ts","C:/Users/CarryAlex/Desktop/VueWebsite/createagame/src/components/__tests__/StartPage.spec.ts","C:/Users/CarryAlex/Desktop/VueWebsite/createagame/src/dataservice/dataService.ts","C:/Users/CarryAlex/Desktop/VueWebsite/createagame/src/store/index.ts"],"options":{"configFilePath":"C:/Users/CarryAlex/Desktop/VueWebsite/createagame/tsconfig.json","declaration":false,"experimentalDecorators":true,"inlineSourceMap":false,"inlineSources":true,"module":1,"noEmit":false,"removeComments":false,"sourceMap":true,"target":1},"raw":{"compileOnSave":false,"compilerOptions":{"experimentalDecorators":true},"exclude":["node_modules"],"include":["src//.ts","src//.vue"]},"typeAcquisition":{"enable":false,"exclude":[],"include":[]},"wildcardDirectories":{"c:/users/carryalex/desktop/vuewebsite/createagame/src":1}}},"version":"25.4.0"},"message":"normalized typescript config","sequence":15,"time":"2020-04-22T10:30:36.750Z"}
## envinfo
System:
OS: Windows 10
Npm packages:
jest
ts-jest
typescript
vue-jest
vue-cli
webpack
tsconfig.json
```{
"compilerOptions": {
"experimentalDecorators": true
},
"include": [
"src/**/*.ts",
"src/**/*.vue",
],
"exclude": [
"node_modules"
]
}```
package.json:
"jest": {
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": ["js", "ts", "json", "vue"],
"transform": {
".*\\.(vue)$": "vue-jest",
"^.+\\.tsx?$": "ts-jest"
},
"testURL": "http://localhost/"
}
you can't ignore tsconfig because ts-jest needs to load tsconfig in your project to be able to use TypeScript compiler. I'd suggest you to check your tsconfig.
Besides, please following the bug template and fill in all necessary information so we can easily help.
I see your tsconfig contains invalid character at the end, you should correct it to have the correct json format
If you're a dumbass like me and you're getting this error this is most likely - as ahnpnl said above - you have a syntax error in your tsconfig.json.
In my case, this was
//tsconfig.json
...
"experimentalDecorators": true,
"incremental": true, // <-- trailing comma that JSON doesn't support
},
"include": [
Note that VSCODE WILL NOT REPORT A SYNTAX ERROR IN TSCONFIG.JSON IF YOU MAKE THIS MISTAKE. You will need to check the file manually for errors
If you're a dumbass like me and you're getting this error this is most likely - as ahnpnl said above - you have a syntax error in your
tsconfig.json.In my case, this was
//tsconfig.json ... "experimentalDecorators": true, "incremental": true, // <-- trailing comma that JSON doesn't support }, "include": [Note that VSCODE WILL NOT REPORT A SYNTAX ERROR IN TSCONFIG.JSON IF YOU MAKE THIS MISTAKE. You will need to check the file manually for errors
Yup this was it lol. Thank you.
Most helpful comment
If you're a dumbass like me and you're getting this error this is most likely - as ahnpnl said above - you have a syntax error in your
tsconfig.json.In my case, this was
Note that VSCODE WILL NOT REPORT A SYNTAX ERROR IN TSCONFIG.JSON IF YOU MAKE THIS MISTAKE. You will need to check the file manually for errors