Skip to content

Commit 0a4b833

Browse files
committed
test: add case to improve coverage
1 parent 332d491 commit 0a4b833

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

src/rules/utils.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,11 @@ const tryParseAsInvalidConfigError = (
225225
const [, reason] =
226226
/ESLint configuration (?:.+) is invalid:(.+)/isu.exec(
227227
error.message.trim()
228-
) ?? /* istanbul ignore next */ [];
228+
) ?? [];
229229

230230
return reason //
231231
? { type: ESLintErrorType.InvalidConfig, reason }
232-
: /* istanbul ignore next */
233-
null;
232+
: null;
234233
};
235234

236235
const errorParsers: ESLintErrorParser[] = [
@@ -250,10 +249,8 @@ const parseESLintError = (error: Error): ESLintError => {
250249
}
251250
}
252251

253-
/* istanbul ignore next */
254252
error.message = `Unable to parse error from ESLint: ${error.message}`;
255253

256-
/* istanbul ignore next */
257254
throw error;
258255
};
259256

test/helpers.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ export const mockEslintPluginPrettier = (): void => {
9292
create() {
9393
return {};
9494
}
95+
}),
96+
'erroneous-rule': ESLintUtils.RuleCreator(name => name)({
97+
name: __filename,
98+
meta: {
99+
type: 'problem',
100+
docs: {
101+
description: 'Fake rule that always throws, for use in testing',
102+
category: 'Best Practices',
103+
recommended: 'warn'
104+
},
105+
messages: {},
106+
schema: []
107+
},
108+
defaultOptions: [],
109+
create() {
110+
throw new Error('explosions!');
111+
}
95112
})
96113
}
97114
};

test/src/rules/no-invalid-config.spec.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { TSESLint } from '@typescript-eslint/experimental-utils';
22
import dedent from 'dedent';
33
import rule from '../../../src/rules/no-invalid-config';
44
import { ESLintError, ESLintErrorType } from '../../../src/rules/utils';
5-
import { RuleTester } from '../../helpers';
5+
import { RuleTester, mockEslintPluginPrettier } from '../../helpers';
66

77
const ruleTester = new RuleTester();
88

9+
mockEslintPluginPrettier();
10+
911
const expectedError = ({
1012
line,
1113
column,
@@ -20,7 +22,7 @@ const expectedError = ({
2022
column
2123
});
2224

23-
ruleTester.run('no-invalid-configs', rule, {
25+
ruleTester.run('no-invalid-config', rule, {
2426
valid: [
2527
'module.exports = undefined;',
2628
'module.exports = "";',
@@ -75,6 +77,27 @@ ruleTester.run('no-invalid-configs', rule, {
7577
column: 1
7678
}
7779
]
80+
},
81+
{
82+
code: dedent`
83+
module.exports = {
84+
plugins: ['prettier'],
85+
rules: { 'prettier/erroneous-rule': 'error' }
86+
}
87+
`,
88+
errors: [
89+
{
90+
messageId: 'UnknownError',
91+
data: {
92+
message: dedent`
93+
Unable to parse error from ESLint: Error while loading rule 'prettier/erroneous-rule': explosions!
94+
Occurred while linting <text>
95+
`.trim()
96+
},
97+
line: 1,
98+
column: 1
99+
}
100+
]
78101
}
79102
]
80103
});

0 commit comments

Comments
 (0)