Skip to content
New issue

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

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

Already on GitHub? # to your account

require() makes jest plugin crash #114

Closed
jacekkopecky opened this issue May 25, 2018 · 2 comments · Fixed by #115 or severest/retrobot#132
Closed

require() makes jest plugin crash #114

jacekkopecky opened this issue May 25, 2018 · 2 comments · Fixed by #115 or severest/retrobot#132

Comments

@jacekkopecky
Copy link
Contributor

Hi, as I was working, I had a stray require() in my code and it made ESlint crash badly; that probably shouldn't happen. Here's the most trivial example that illustrates that:

simple.test.js

describe('simple test', () => {
  test('should not fail', () => {
      require()
  });
});

.eslintrc.js

module.exports = {
    "env": {
        "es6": true
    },
    "extends": ["eslint:recommended","plugin:jest/recommended"]
};

package.json

{
  "name": "jest-issue",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "eslint": "^4.19.1",
    "eslint-plugin-jest": "^21.15.2",
    "jest": "^23.0.0"
  }
}

Stack trace:

TypeError: Cannot read property 'value' of undefined
    at CallExpression (/Users/kopeckyj/tmp/jest/node_modules/eslint-plugin-jest/rules/no-jest-import.js:25:59)
    at listeners.(anonymous function).forEach.listener (/Users/kopeckyj/tmp/jest/node_modules/eslint/lib/util/safe-emitter.js:47:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/kopeckyj/tmp/jest/node_modules/eslint/lib/util/safe-emitter.js:47:38)
    at NodeEventGenerator.applySelector (/Users/kopeckyj/tmp/jest/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (/Users/kopeckyj/tmp/jest/node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (/Users/kopeckyj/tmp/jest/node_modules/eslint/lib/util/node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (/Users/kopeckyj/tmp/jest/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:608:23)
    at Traverser.enter [as _enter] (/Users/kopeckyj/tmp/jest/node_modules/eslint/lib/linter.js:865:28)
    at Traverser._traverse (/Users/kopeckyj/tmp/jest/node_modules/eslint/lib/util/traverser.js:132:14)
@SimenB
Copy link
Member

SimenB commented May 25, 2018

Oh, that's bad. Wanna fix it? It's just a matter of safe-guarding

if (calleeName === 'require' && node.arguments[0].value === 'jest') {

@SimenB
Copy link
Member

SimenB commented May 27, 2018

🎉 This issue has been resolved in version 21.15.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

# for free to join this conversation on GitHub. Already have an account? # to comment