Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions integrationTests/__fixtures__/rule-error/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -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'],
},
};
1 change: 1 addition & 0 deletions integrationTests/__fixtures__/rule-error/__eslint__/one.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('one');
1 change: 1 addition & 0 deletions integrationTests/__fixtures__/rule-error/__eslint__/two.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('two');
4 changes: 4 additions & 0 deletions integrationTests/__fixtures__/rule-error/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
runner: '../../../',
testMatch: ['**/__eslint__/**/*.js'],
};
Original file line number Diff line number Diff line change
@@ -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;
},
};
},
};
16 changes: 16 additions & 0 deletions integrationTests/__snapshots__/rule-error.test.js.snap
Original file line number Diff line number Diff line change
@@ -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.
"
`;
5 changes: 5 additions & 0 deletions integrationTests/rule-error.test.js
Original file line number Diff line number Diff line change
@@ -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();
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 14 additions & 1 deletion src/runner/runESLint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down