Skip to content

Commit

Permalink
Do not report warnings as errors in quiet mode (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-kenware committed Sep 18, 2023
1 parent 4e66b53 commit ffc5c0d
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 6 deletions.
5 changes: 5 additions & 0 deletions integrationTests/__fixtures__/quiet-mode/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-console": "warn"
}
}
6 changes: 6 additions & 0 deletions integrationTests/__fixtures__/quiet-mode/__eslint__/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const a = 1;

console.log('a', a);
if (a === 2) {
hello();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
cliOptions: {
quiet: true,
},
};
4 changes: 4 additions & 0 deletions integrationTests/__fixtures__/quiet-mode/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
runner: '../../../',
testMatch: ['**/__eslint__/**/*.js'],
};
19 changes: 19 additions & 0 deletions integrationTests/__snapshots__/quiet-mode.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`does not log warnings as errors in quiet mode 1`] = `
"FAIL __eslint__/file.js
✕ no-undef
/mocked-path-to-jest-runner-mocha/integrationTests/__fixtures__/quiet-mode/__eslint__/file.js
5:3 error 'hello' is not defined no-undef
✖ 1 problem (1 error, 0 warnings)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time:
Ran all test suites.
"
`;
5 changes: 5 additions & 0 deletions integrationTests/quiet-mode.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const runJest = require('./runJest');

it('does not log warnings as errors in quiet mode', async () => {
expect(await runJest('quiet-mode')).toMatchSnapshot();
});
13 changes: 7 additions & 6 deletions src/runner/runESLint.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,20 @@ const runESLint = async ({ testPath, config, extraOptions }) => {

const end = Date.now();

const message = await formatter(
cliOptions.quiet ? ESLintConstructor.getErrorResults(report) : report,
);
const eslintReport = cliOptions.quiet
? ESLintConstructor.getErrorResults(report)
: report;
const message = await formatter(eslintReport);

if (report[0]?.errorCount > 0) {
if (eslintReport[0]?.errorCount > 0) {
return mkTestResults({
message,
start,
end,
testPath,
numFailingTests: report[0].errorCount,
numFailingTests: eslintReport[0].errorCount,
numPassingTests: 0,
assertionResults: mkAssertionResults(testPath, report),
assertionResults: mkAssertionResults(testPath, eslintReport),
cliOptions,
});
}
Expand Down

0 comments on commit ffc5c0d

Please sign in to comment.