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)
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.
I would expect the coverage output to appear as normal and not produce a syntax error.
Please provide either a repl.it demo or a
minimal repository on GitHub.
Issues without a reproduction link are likely to stall.
npx envinfo --preset jestPaste 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
Mind setting up a repro please?
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.
Yup, but I'd need to do all the manual work, which I don't feel like. The easier you'll make your bug report to process for maintainers, the more likely it will get fixed :)
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.
Ideally, a repro is a git repository where we can checkout, run yarn and yarn test to check what's wrong with it.
It needs to be as simple as possible, so we can focus on actual bug.
I'll try making the repo.
Cool, I think I found the problem, because I'm using projects having the coverage configurations within config/jest-test.config.js but it's only 1/3 projects it seemed to get lost and try parsing the wrong files. Moving my collectCoverageFrom and coverageThreshold settings up into my main jest.config.js fixed it.
This is fine, but it wasn't a breaking thing for Jest 22. 🤷♂️
I think I was able to successfully reproduce the error in #6859.
Having this as well, but I have my jest configuration into my package.json
"jest": {
"bail": true,
"verbose": true,
"testURL": "http://localhost",
"transformIgnorePatterns": [
"!node_modules/react-runtime"
],
"setupFiles": [
"raf/polyfill"
],
"setupTestFrameworkScriptFile": "jest-extended"
},
Versions:
"enzyme": "^3.4.4",
"enzyme-adapter-react-16": "^1.2.0",
Throws:
files...Failed to collect coverage from /Users/damz/Desktop/react-router-xs/package.json
ERROR: Unexpected token, expected ; (2:10)
STACK: SyntaxError: Unexpected token, expected ; (2:10)
at Parser.pp$5.raise (/Users/damz/Desktop/react-router-xs/node_modules/babylon/lib/index.js:4454:13)
at Parser.pp.unexpected (/Users/damz/Desktop/react-router-xs/node_modules/babylon/lib/index.js:1761:8)
at Parser.pp.semicolon (/Users/damz/Desktop/react-router-xs/node_modules/babylon/lib/index.js:1742:38)
at Parser.pp$1.parseExpressionStatement (/Users/damz/Desktop/react-router-xs/node_modules/babylon/lib/index.js:2236:8)
at Parser.parseExpressionStatement (/Users/damz/Desktop/react-router-xs/node_modules/babylon/lib/index.js:5934:20)
at Parser.pp$1.parseStatement (/Users/damz/Desktop/react-router-xs/node_modules/babylon/lib/index.js:1911:17)
at Parser.parseStatement (/Users/damz/Desktop/react-router-xs/node_modules/babylon/lib/index.js:5910:22)
at Parser.pp$1.parseBlockBody (/Users/damz/Desktop/react-router-xs/node_modules/babylon/lib/index.js:2268:21)
at Parser.pp$1.parseBlock (/Users/damz/Desktop/react-router-xs/node_modules/babylon/lib/index.js:2247:8)
at Parser.pp$1.parseStatement (/Users/damz/Desktop/react-router-xs/node_modules/babylon/lib/index.js:1868:19)
@damianobarbati Does the status of the staging area matter, to produce this error? Are there any changes that are both unstaged and uncommitted? And what command are you running, jest --watch and not jest --watchAll?
@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
@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 and watch/watchAll enabled.
I was seeing the same issue, explicitly adding json files to be ignore was not helping. Committing the changes fixed it indeed for me. Thank you! This was driving me crazy.
ping @thymikee please see @garyking's comments and his issue which has repro steps
Thanks @Billy- @garyking, looks like this is the same issue. I'll close this one as duplicate of #6859, since it has repro.
Most helpful comment
@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
coverageandwatch/watchAllenabled.