Typescript Jest failing
See original GitHub issueš Bug Report
It seems its failing on the tsconfig file? but I even tried to ignore tsconfig and it still fails parsing the tsconfig.json
To Reproduce
Running jest
Error:
` 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)`
Debug log:
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 npm@6.9.0
3 info using node@v10.16.3
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle client@1.0.0~pretest: client@1.0.0
6 info lifecycle client@1.0.0~test: client@1.0.0
7 verbose lifecycle client@1.0.0~test: unsafe-perm in lifecycle true
8 verbose lifecycle client@1.0.0~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 client@1.0.0~test: CWD: C:\Users\CarryAlex\Desktop\VueWebsite\createagame
10 silly lifecycle client@1.0.0~test: Args: [ '/d /s /c', 'jest' ]
11 silly lifecycle client@1.0.0~test: Returned: code: 1 signal: null
12 info lifecycle client@1.0.0~test: Failed to exec test script
13 verbose stack Error: client@1.0.0 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 client@1.0.0
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 client@1.0.0 test: `jest`
22 error Exit status 1
23 error Failed at the client@1.0.0 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/"
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
Running tests with Jest: getting an error with TypeScript config ...
I'm using NodeJS, TypeORM with TypeScript. I'm getting this error when running yarn test : Error: Jest: Failed to parse the TypeScript configĀ ......
Read more >Forge bundling errors on Typescript jest tests
I've started adding typescript modules to my Forge app - this seems to deploy and run just fine. I also am using jest...
Read more >Diagnostics option | ts-jest - GitHub Pages
If a diagnostic is not filtered out, ts-jest will fail the compilation and your test. Disabling/enablingā. By default all diagnostics areĀ ...
Read more >Debugging jest tests in javascript/typescript projects when ...
Debugging jest tests in javascript/typescript projects when running specific test fails if test has " or ` or ' characters in its name....
Read more >Configuring Jest
To read TypeScript configuration files Jest requires ts-node . ... option can be used here to have Jest stop running tests after n...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
3 hours looking, and the problem was a comma. Thanks, it could be 3 days.