Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax Error Output when running jest --coverage --watch on Jest 23 #6258

Closed
wldcordeiro opened this issue May 25, 2018 · 16 comments
Closed

Comments

@wldcordeiro
Copy link

🐛 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
@thymikee
Copy link
Collaborator

Mind setting up a repro please?

@wldcordeiro
Copy link
Author

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.

@thymikee
Copy link
Collaborator

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 :)

@wldcordeiro
Copy link
Author

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.

@thymikee
Copy link
Collaborator

Ideally, a repro is a git repository where we can checkout, run yarn and yarn test to check what's wrong with it.

@thymikee
Copy link
Collaborator

It needs to be as simple as possible, so we can focus on actual bug.

@wldcordeiro
Copy link
Author

wldcordeiro commented May 25, 2018

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. 🤷‍♂️

@garyking
Copy link

I think I was able to successfully reproduce the error in #6859.

@damianobarbati
Copy link

damianobarbati commented Aug 18, 2018

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)

@garyking
Copy link

@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?

@damianobarbati
Copy link

@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

@garyking
Copy link

garyking commented Aug 19, 2018

@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.

@DutchRican
Copy link

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.

@Billy-
Copy link
Contributor

Billy- commented Nov 17, 2018

ping @thymikee please see @garyking's comments and his issue which has repro steps

@thymikee
Copy link
Collaborator

Thanks @Billy- @garyking, looks like this is the same issue. I'll close this one as duplicate of #6859, since it has repro.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants