jest: Syntax Error Output when running `jest --coverage --watch` on Jest 23
đ 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
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 16
- Comments: 16 (1 by maintainers)
@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.
@garyking yes! I just committed everything and the error disappeared: is this a known behaviour?
Iâm using jest like this:
yarn jest --no-cache --coverage --watchAll
The instructions for how to even go about making a repro are unclear. Do you have example repos you can link to? I assume you have a test suite and fixtures. Linking to those would give people resources to even create a repro.
repl.it
wasnât able to support the kind of things needed for this.Yeah let me just scrub a 20k loc repo and share. It how do I go about that? I thought the configs would be whatâs needed since thatâs all the interface I have into Jest.