Syntax Error Output when running `jest --coverage --watch` on Jest 23
See original GitHub issue🐛 Bug Report
Somehow the coverage generator is trying to parse the package.json and outputs this error.
Running coverage on untested files...Failed to collect coverage from /Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/package.json
ERROR: Unexpected token, expected ; (2:8)
STACK: SyntaxError: Unexpected token, expected ; (2:8)
at Parser.pp$5.raise (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:4454:13)
at Parser.pp.unexpected (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:1761:8)
at Parser.pp.semicolon (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:1742:38)
at Parser.pp$1.parseExpressionStatement (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:2236:8)
at Parser.parseExpressionStatement (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:5934:20)
at Parser.pp$1.parseStatement (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:1911:17)
at Parser.parseStatement (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:5910:22)
at Parser.pp$1.parseBlockBody (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:2268:21)
at Parser.pp$1.parseBlock (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:2247:8)
at Parser.pp$1.parseStatement (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:1868:19)
Failed to collect coverage from /Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/package.json
ERROR: /Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/package.json: Unexpected token, expected ; (2:8)
STACK: SyntaxError: /Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/package.json: Unexpected token, expected ; (2:8)
1 | {
> 2 | "name": "@inferno/aqueduct",
| ^
3 | "version": "0.1.4-0",
4 | "description": "The front end interface for the DAM product",
5 | "homepage": "http://github.slc.us.workfront.net/inferno/aqueduct",
at Parser.pp$5.raise (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:4454:13)
at Parser.pp.unexpected (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:1761:8)
at Parser.pp.semicolon (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:1742:38)
at Parser.pp$1.parseExpressionStatement (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:2236:8)
at Parser.parseExpressionStatement (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:5934:20)
at Parser.pp$1.parseStatement (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:1911:17)
at Parser.parseStatement (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:5910:22)
at Parser.pp$1.parseBlockBody (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:2268:21)
at Parser.pp$1.parseBlock (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:2247:8)
at Parser.pp$1.parseStatement (/Users/wellingtoncordeiro/Documents/projects/inferno-parent/aqueduct/node_modules/babylon/lib/index.js:1868:19)
To Reproduce
Steps to reproduce the behavior:
This may be affected by my usage of projects. I have the following configs.
// configs/jest-test.config.js
const { resolve } = require('path')
const root = resolve(__dirname, '..')
module.exports = {
rootDir: root,
displayName: 'test',
testPathIgnorePatterns: ['/node_modules/', '/cypress/'],
collectCoverageFrom: [
'src/**/*.js',
'!src/index.js',
'!**/fixtures/**/*.js',
'!**/**/test-setup.js',
'!**/**/*.spec.js',
'!**/**/*.mock.js',
'!**/**/*.test.js',
],
coverageThreshold: {
global: {
statements: 90,
branches: 75,
functions: 85,
lines: 90,
},
},
setupTestFrameworkScriptFile: '<rootDir>/jest-setup.js',
testEnvironment: 'jest-environment-jsdom-global',
transform: {
'^.+\\.jsx?$': 'babel-jest',
'.*': '@brimstone/jest-static-assets-mocker',
},
snapshotSerializers: [
'jest-glamor-react',
'enzyme-to-json/serializer',
'snapshot-diff-serializer',
],
transformIgnorePatterns: [
'node_modules/(?!(css-wipe|@wf-titan/kashyyyk-theme|@inferno/effigy))',
],
testURL: 'https://example.com/',
}
// configs/jest-eslint.config.js
const { resolve } = require('path')
const root = resolve(__dirname, '..')
module.exports = {
rootDir: root,
displayName: 'eslint',
runner: 'jest-runner-eslint',
testMatch: ['<rootDir>/src/**/*.js', '<rootDir>/config/*.js'],
}
// configs/jest-prettier.config.js
const { resolve } = require('path')
const root = resolve(__dirname, '..')
module.exports = {
rootDir: root,
displayName: 'prettier',
runner: 'jest-runner-write-prettier',
testMatch: ['<rootDir>/src/**/*.js', '<rootDir>/config/*.js', '*.js'],
moduleFileExtensions: ['js'],
}
// jest.config.js
module.exports = {
projects: [
'<rootDir>/config/jest-test.config.js',
'<rootDir>/config/jest-eslint.config.js',
'<rootDir>/config/jest-prettier.config.js',
],
}
// jest-lint.config.js
module.exports = {
projects: [
'<rootDir>/config/jest-eslint.config.js',
'<rootDir>/config/jest-prettier.config.js',
],
}
So I assume that when I run yarn test --watch
which is jest --coverage
it would run with the jest.config.js
as its configuration.
Expected behavior
I would expect the coverage output to appear as normal and not produce a syntax error.
Link to repl or repo (highly encouraged)
Please provide either a repl.it demo or a minimal repository on GitHub.
Issues without a reproduction link are likely to stall.
Run npx envinfo --preset jest
Paste the results here:
System:
OS: macOS High Sierra 10.13.1
CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Binaries:
Node: 9.11.1 - ~/.nvm/versions/node/v9.11.1/bin/node
Yarn: 1.7.0 - ~/.yarn/bin/yarn
npm: 5.7.0 - ~/.nvm/versions/node/v9.11.1/bin/npm
Issue Analytics
- State:
- Created 5 years ago
- Reactions:16
- Comments:16 (1 by maintainers)
Top Results From Across the Web
Jest CLI Options
The jest command line runner has a number of useful options. You can run jest --help to view all available options. Many of...
Read more >Jest finds tests but doesn't collect coverage - Stack Overflow
I found that when upgrading jest (from 23 to 26) that i had this issue, and the resolution was to run with the...
Read more >Jest | WebStorm Documentation - JetBrains
Jest is a testing platform for client-side JavaScript applications and React ... You can run and debug tests with Jest right in WebStorm....
Read more >Testing Angular 2 and Continuous Integration with Jest
Cut down on test run time by testing Angular 2 and continuous integration with Jest. In this article, using a toy application you'll...
Read more >Testing Angular Faster with Jest - Xfive
The watch mode runs only tests affected by git file changes – it also runs failed tests first and is able to bail...
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
@damianobarbati I reported my own findings at #6859. It isn’t “known behavior”, in that a Jest contributor hasn’t responded to my other issue yet. They’ve acknowledged the issue here, but there hadn’t otherwise been any other activity on it since May.
I personally encounter this issue about once a day. It seems to happen when you have a non-.js file that has uncommitted changes, and you have
coverage
andwatch/watchAll
enabled.Thanks @Billy- @garyking, looks like this is the same issue. I’ll close this one as duplicate of #6859, since it has repro.