Skip to content

Commit

Permalink
feat: Split results to work with github-actions reporter (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
cprussin committed Jan 24, 2023
1 parent 8fd7b20 commit 6e957ec
Show file tree
Hide file tree
Showing 18 changed files with 296 additions and 49 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/
**/coverage/
integrationTests/__fixtures__/skipped/__eslint__/file.js
integrationTests/__fixtures__/github-actions/__eslint__/skipped.js
**/node_modules/**
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const a = 1;

if (a === 2) {
hello();
bye();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const hello = () => {
/* no-op */
};

const a = 1;

if (a === 2) {
hello();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const a = 1;

if (a === 2) {
hello();
bye();
}
5 changes: 5 additions & 0 deletions integrationTests/__fixtures__/github-actions/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
runner: '../../../',
testMatch: ['**/__eslint__/**/*.js'],
reporters: ['github-actions'],
};
55 changes: 51 additions & 4 deletions integrationTests/__snapshots__/custom-parser.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,75 @@
exports[`Doesn't override parser when not set [ESLint<6] 1`] = `
"FAIL integrationTests/__fixtures__/custom-parser/__eslint__/file.js
● Test suite failed to run
Cannot find module 'this-parser-does-not-exist'
at mocked-stack-trace
at ModuleResolver.resolve (../../../node_modules/eslint/lib/util/module-resolver.js:72:19)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time:
Time:
Ran all test suites.
"
`;

exports[`Doesn't override parser when not set [ESLint=6] 1`] = `
"FAIL integrationTests/__fixtures__/custom-parser/__eslint__/file.js
● Test suite failed to run
Failed to load parser 'this-parser-does-not-exist' declared in 'integrationTests/__fixtures__/custom-parser/.eslintrc.json': Cannot find module 'this-parser-does-not-exist'
Require stack:
- /mocked-path-to-jest-runner-mocha/integrationTests/__fixtures__/custom-parser/.eslintrc.json
at Object.resolve (../../../node_modules/eslint/lib/shared/relative-module-resolver.js:44:50)
at _normalizeObjectConfigDataBody.next (<anonymous>)
at _normalizeObjectConfigData.next (<anonymous>)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time:
Ran all test suites.
"
`;
exports[`Doesn't override parser when not set [ESLint=7] 1`] = `
"FAIL integrationTests/__fixtures__/custom-parser/__eslint__/file.js
● Test suite failed to run
Failed to load parser 'this-parser-does-not-exist' declared in 'integrationTests/__fixtures__/custom-parser/.eslintrc.json': Cannot find module 'this-parser-does-not-exist'
Require stack:
- /mocked-path-to-jest-runner-mocha/integrationTests/__fixtures__/custom-parser/.eslintrc.json
at Object.resolve (../../../node_modules/@eslint/eslintrc/lib/shared/relative-module-resolver.js:28:50)
at _normalizeObjectConfigDataBody.next (<anonymous>)
at _normalizeObjectConfigData.next (<anonymous>)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time:
Ran all test suites.
"
`;
exports[`Doesn't override parser when not set 1`] = `
"FAIL integrationTests/__fixtures__/custom-parser/__eslint__/file.js
● Test suite failed to run
Failed to load parser 'this-parser-does-not-exist' declared in 'integrationTests/__fixtures__/custom-parser/.eslintrc.json': Cannot find module 'this-parser-does-not-exist'
Require stack:
- /mocked-path-to-jest-runner-mocha/integrationTests/__fixtures__/custom-parser/.eslintrc.json
at mocked-stack-trace
at Object.resolve (../../../node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2325:46)
at _normalizeObjectConfigDataBody.next (<anonymous>)
at _normalizeObjectConfigData.next (<anonymous>)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time:
Time:
Ran all test suites.
"
`;
11 changes: 8 additions & 3 deletions integrationTests/__snapshots__/failing.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

exports[`Works when it has failing tests 1`] = `
"FAIL integrationTests/__fixtures__/failing/__eslint__/file.js
✕ ESLint
✕ no-undef
✕ no-undef
/mocked-path-to-jest-runner-mocha/integrationTests/__fixtures__/failing/__eslint__/file.js
4:3 error 'hello' is not defined no-undef
5:3 error 'bye' is not defined no-undef
✖ 2 problems (2 errors, 0 warnings)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Tests: 2 failed, 2 total
Snapshots: 0 total
Time:
Time:
Ran all test suites.
"
`;
22 changes: 15 additions & 7 deletions integrationTests/__snapshots__/format.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,33 @@

exports[`Applies custom formatter 1`] = `
"FAIL integrationTests/__fixtures__/format/__eslint__/file.js
✕ ESLint
at mocked-stack-trace 2 |
✕ no-undef
✕ no-undef
error: 'hello' is not defined (no-undef) at integrationTests/__fixtures__/format/__eslint__/file.js:4:3:
2 |
3 | if (a === 2) {
> 4 | hello();
| ^
5 | bye();
6 | }
7 |
mocked-stack-trace 3 | if (a === 2) {
7 |
error: 'bye' is not defined (no-undef) at integrationTests/__fixtures__/format/__eslint__/file.js:5:3:
3 | if (a === 2) {
4 | hello();
> 5 | bye();
| ^
6 | }
7 |
7 |
2 errors found.
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Tests: 2 failed, 2 total
Snapshots: 0 total
Time:
Time:
Ran all test suites.
"
`;
9 changes: 9 additions & 0 deletions integrationTests/__snapshots__/github-actions.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Reports with the github actions reporter 1`] = `
"
::error file=/mocked-path-to-jest-runner-mocha/integrationTests/__fixtures__/github-actions/__eslint__/failing.js,line=4,title=no-undef::'hello' is not defined.%0A%0A at __eslint__/failing.js:4:3
::error file=/mocked-path-to-jest-runner-mocha/integrationTests/__fixtures__/github-actions/__eslint__/failing.js,line=5,title=no-undef::'bye' is not defined.%0A%0A at __eslint__/failing.js:5:3
"
`;
9 changes: 7 additions & 2 deletions integrationTests/__snapshots__/loud.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
exports[`Outputs warnings as console messages 1`] = `
"PASS integrationTests/__fixtures__/loud/__eslint__/file.js
● Console
console.warn
/mocked-path-to-jest-runner-mocha/integrationTests/__fixtures__/loud/__eslint__/file.js
3:1 warning Unexpected console statement no-console
✖ 1 problem (0 errors, 1 warning)
✓ ESLint
✓ ESLint
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time:
Time:
Ran all test suites.
"
`;
10 changes: 8 additions & 2 deletions integrationTests/__snapshots__/max-warnings.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

exports[`Fails if more than max warnings 1`] = `
"FAIL integrationTests/__fixtures__/max-warnings/__eslint__/file.js
✕ ESLint
✕ no-console
✕ no-console
✕ no-console
/mocked-path-to-jest-runner-mocha/integrationTests/__fixtures__/max-warnings/__eslint__/file.js
3:1 warning Unexpected console statement no-console
4:1 warning Unexpected console statement no-console
5:1 warning Unexpected console statement no-console
✖ 3 problems (0 errors, 3 warnings)
ESLint found too many warnings (maximum: 2).
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time:
Time:
Ran all test suites.
"
`;
5 changes: 3 additions & 2 deletions integrationTests/__snapshots__/passing.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

exports[`Works when it has only passing tests 1`] = `
"PASS integrationTests/__fixtures__/passing/__eslint__/file.js
✓ ESLint
✓ ESLint
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time:
Time:
Ran all test suites.
"
`;
4 changes: 2 additions & 2 deletions integrationTests/__snapshots__/skipped.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

exports[`Works when it has failing tests 1`] = `
"Test Suites: 1 skipped, 0 of 1 total
Tests: 1 skipped, 1 total
Tests: 0 total
Snapshots: 0 total
Time:
Time:
Ran all test suites.
"
`;
30 changes: 23 additions & 7 deletions integrationTests/custom-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,36 @@ const { version } = require('eslint/package.json');
const semver = require('semver');
const runJest = require('./runJest');

const isBelow6 = semver.satisfies(version, '<6');

// Note: ESLint versions <6 have a different error message for this test. The
// snapshot file contains both messages so we can test across both versions.
// Without the skipped tests for the "other" version, the tests will always fail
// with `1 snapshot obsolete`.
if (isBelow6) {
// Note: ESLint versions <6, 6, 7, >7 each have a different error message or
// stack for this test. The snapshot file contains all messages so we can test
// across versions. Without the skipped tests for the other versions, the tests
// will always fail with `1 snapshot obsolete`.
if (semver.satisfies(version, '<6')) {
it.skip("Doesn't override parser when not set", () => {});
it.skip("Doesn't override parser when not set [ESLint=6]", () => {});
it.skip("Doesn't override parser when not set [ESLint=7]", () => {});
it("Doesn't override parser when not set [ESLint<6]", async () => {
expect(await runJest('custom-parser')).toMatchSnapshot();
});
} else if (semver.satisfies(version, '6')) {
it.skip("Doesn't override parser when not set", () => {});
it.skip("Doesn't override parser when not set [ESLint<6]", () => {});
it.skip("Doesn't override parser when not set [ESLint=7]", () => {});
it("Doesn't override parser when not set [ESLint=6]", async () => {
expect(await runJest('custom-parser')).toMatchSnapshot();
});
} else if (semver.satisfies(version, '7')) {
it.skip("Doesn't override parser when not set", () => {});
it.skip("Doesn't override parser when not set [ESLint<6]", () => {});
it.skip("Doesn't override parser when not set [ESLint=6]", () => {});
it("Doesn't override parser when not set [ESLint=7]", async () => {
expect(await runJest('custom-parser')).toMatchSnapshot();
});
} else {
it("Doesn't override parser when not set", async () => {
expect(await runJest('custom-parser')).toMatchSnapshot();
});
it.skip("Doesn't override parser when not set [ESLint<6]", () => {});
it.skip("Doesn't override parser when not set [ESLint=6]", () => {});
it.skip("Doesn't override parser when not set [ESLint=7]", () => {});
}
16 changes: 16 additions & 0 deletions integrationTests/github-actions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { version } = require('jest/package.json');
const semver = require('semver');
const runJest = require('./runJest');

// NOTE: Jest versions <28 don't have a github action reporter, so this test is
// not valid.
if (semver.satisfies(version, '<28')) {
it.skip('Reports with the github actions reporter', () => {});
} else {
it('Reports with the github actions reporter', async () => {
const priorActionsConfig = process.env.GITHUB_ACTIONS;
process.env.GITHUB_ACTIONS = true;
expect(await runJest('github-actions')).toMatchSnapshot();
process.env.GITHUB_ACTIONS = priorActionsConfig;
});
}
8 changes: 2 additions & 6 deletions integrationTests/runJest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ const rootDir = path.join(__dirname, '..');

const normalize = output =>
output
.replace(/\(?\d*\.?\d+ ?m?s\b\)?/g, '')
.replace(/, estimated/g, '')
.replace(/((✕|✓) .* )\(\d*(\.\d+)? ?m?s\)/g, '$1')
.replace(new RegExp(rootDir, 'g'), '/mocked-path-to-jest-runner-mocha')
.replace(new RegExp('.*at .*\\n', 'g'), 'mocked-stack-trace')
.replace(/.*at .*\\n/g, 'mocked-stack-trace')
.replace(/(mocked-stack-trace)+/, ' at mocked-stack-trace')
.replace(/\s+\n/g, '\n');
.replace(/(Time: {8})\d*(\.\d+)? ?m?s/, '$1');

const runJest = (project, options = []) => {
jest.setTimeout(30000);
Expand Down
2 changes: 1 addition & 1 deletion src/runner/__tests__/runESLint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ it('Returns "skipped" when the test path is ignored', async () => {
expect(result).toMatchObject({
numFailingTests: 0,
numPassingTests: 0,
numPendingTests: 1,
numPendingTests: 0,
skipped: true,
});
});
Expand Down

0 comments on commit 6e957ec

Please sign in to comment.