diff --git a/integrationTests/__fixtures__/rule-error/.eslintrc.js b/integrationTests/__fixtures__/rule-error/.eslintrc.js new file mode 100644 index 0000000..4c8bb00 --- /dev/null +++ b/integrationTests/__fixtures__/rule-error/.eslintrc.js @@ -0,0 +1,12 @@ +const path = require('path'); +const rulesDirPlugin = require('eslint-plugin-rulesdir'); + +rulesDirPlugin.RULES_DIR = path.join(__dirname, 'rules'); + +module.exports = { + plugins: ['rulesdir'], + rules: { + quotes: ['error', 'double'], + 'rulesdir/intentional-error': ['error'], + }, +}; diff --git a/integrationTests/__fixtures__/rule-error/__eslint__/one.js b/integrationTests/__fixtures__/rule-error/__eslint__/one.js new file mode 100644 index 0000000..ac442d0 --- /dev/null +++ b/integrationTests/__fixtures__/rule-error/__eslint__/one.js @@ -0,0 +1 @@ +console.log('one'); diff --git a/integrationTests/__fixtures__/rule-error/__eslint__/two.js b/integrationTests/__fixtures__/rule-error/__eslint__/two.js new file mode 100644 index 0000000..6ae4bac --- /dev/null +++ b/integrationTests/__fixtures__/rule-error/__eslint__/two.js @@ -0,0 +1 @@ +console.log('two'); diff --git a/integrationTests/__fixtures__/rule-error/jest.config.js b/integrationTests/__fixtures__/rule-error/jest.config.js new file mode 100644 index 0000000..94f5944 --- /dev/null +++ b/integrationTests/__fixtures__/rule-error/jest.config.js @@ -0,0 +1,4 @@ +module.exports = { + runner: '../../../', + testMatch: ['**/__eslint__/**/*.js'], +}; diff --git a/integrationTests/__fixtures__/rule-error/rules/intentional-error.js b/integrationTests/__fixtures__/rule-error/rules/intentional-error.js new file mode 100644 index 0000000..0a55d79 --- /dev/null +++ b/integrationTests/__fixtures__/rule-error/rules/intentional-error.js @@ -0,0 +1,17 @@ +// Intentional create an error from eslint +module.exports = { + meta: { + docs: { + description: 'Cause an intentional error at rule evalutation time', + }, + schema: [], + }, + create(context) { + return { + Identifier(node) { + const obj = {}; + obj.will.cause.an.error.here; + }, + }; + }, +}; diff --git a/integrationTests/__snapshots__/rule-error.test.js.snap b/integrationTests/__snapshots__/rule-error.test.js.snap new file mode 100644 index 0000000..12c06fb --- /dev/null +++ b/integrationTests/__snapshots__/rule-error.test.js.snap @@ -0,0 +1,16 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Correctly prints the error message from a failing ESLint rule 1`] = ` +"FAIL integrationTests/__fixtures__/rule-error/__eslint__/one.js +Cannot read property 'cause' of undefined +Occurred while linting /mocked-path-to-jest-runner-mocha/integrationTests/__fixtures__/rule-error/__eslint__/one.js:1 +FAIL integrationTests/__fixtures__/rule-error/__eslint__/two.js +Cannot read property 'cause' of undefined +Occurred while linting /mocked-path-to-jest-runner-mocha/integrationTests/__fixtures__/rule-error/__eslint__/two.js:1 +Test Suites: 2 failed, 2 total +Tests: 2 failed, 2 total +Snapshots: 0 total +Time: +Ran all test suites. +" +`; diff --git a/integrationTests/rule-error.test.js b/integrationTests/rule-error.test.js new file mode 100644 index 0000000..1fc4a89 --- /dev/null +++ b/integrationTests/rule-error.test.js @@ -0,0 +1,5 @@ +const runJest = require('./runJest'); + +it('Correctly prints the error message from a failing ESLint rule', async () => { + expect(await runJest('rule-error')).toMatchSnapshot(); +}); diff --git a/package.json b/package.json index d2e01c5..374e650 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "eslint-plugin-import": "^2.22.0", "eslint-plugin-jest": "^26.9.0", "eslint-plugin-prettier": "^4.0.0", + "eslint-plugin-rulesdir": "^0.2.1", "execa": "^5.1.1", "jest": "^27 || ^28 || ^29", "jest-watch-select-projects": "^2.0.0", diff --git a/src/runner/runESLint.js b/src/runner/runESLint.js index dfb84d9..4c527cd 100644 --- a/src/runner/runESLint.js +++ b/src/runner/runESLint.js @@ -226,7 +226,20 @@ const runESLint = async ({ testPath, config, extraOptions }) => { }); } - const report = await lintFiles([testPath]); + let report; + try { + report = await lintFiles([testPath]); + } catch (e) { + return fail({ + start, + end: Date.now(), + test: { + path: testPath, + title: 'ESLint execution error', + errorMessage: e.message, + }, + }); + } if (cliOptions.fix && !cliOptions.fixDryRun) { await ESLintConstructor.outputFixes(report); diff --git a/yarn.lock b/yarn.lock index d23d0a0..b9e4339 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2254,6 +2254,11 @@ eslint-plugin-prettier@^4.0.0: dependencies: prettier-linter-helpers "^1.0.0" +eslint-plugin-rulesdir@^0.2.1: + version "0.2.2" + resolved "https://registry.yarnpkg.com/eslint-plugin-rulesdir/-/eslint-plugin-rulesdir-0.2.2.tgz#84756ec39cd8503b1fe8af6a02a5da361e2bd076" + integrity sha512-qhBtmrWgehAIQeMDJ+Q+PnOz1DWUZMPeVrI0wE9NZtnpIMFUfh3aPKFYt2saeMSemZRrvUtjWfYwepsC8X+mjQ== + eslint-scope@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c"