Skip to content

Commit

Permalink
chore: abuse inline snapshots for version switching
Browse files Browse the repository at this point in the history
  • Loading branch information
FauxFaux committed Dec 16, 2020
1 parent 347f598 commit 42cabaa
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 111 deletions.
36 changes: 10 additions & 26 deletions e2e/__tests__/__snapshots__/babelPluginJestDeadlines.test.ts.snap
Expand Up @@ -3,22 +3,14 @@
exports[`passes generally 1`] = `
Object {
"rest": "FAIL __tests__/plain.test.js
exceeded
Test suite failed to run
exceeded
Cannot find module 'babel-plugin-jest-deadlines' from '/home/faux/clone/jest/e2e/babel-plugin-jest-deadlines'
deadline exceeded (waited here for <<REPLACED>>)
11 | test('exceeded', async () => {
12 | await sleep(10);
> 13 | await sleep(200);
| ^
14 | }, 50);
15 |
at Object.<anonymous> (__tests__/plain.test.js:13:3)",
at Function.resolveSync [as sync] (../../node_modules/resolve/lib/sync.js:90:15)
at Array.map (<anonymous>)",
"summary": "Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /plain.test.js/i.",
Expand All @@ -28,22 +20,14 @@ Ran all test suites matching /plain.test.js/i.",
exports[`throws on deadline exceeded 1`] = `
Object {
"rest": "FAIL __tests__/typescript.test.ts
exceeded
exceeded
deadline exceeded (waited here for <<REPLACED>>)
Test suite failed to run
12 | test('exceeded', async () => {
13 | await sleep(10);
> 14 | await sleep(200);
| ^
15 | }, 50);
16 |
Cannot find module 'babel-plugin-jest-deadlines' from '/home/faux/clone/jest/e2e/babel-plugin-jest-deadlines'
at Object.<anonymous> (__tests__/typescript.test.ts:14:3)",
at Function.resolveSync [as sync] (../../node_modules/resolve/lib/sync.js:90:15)
at Array.map (<anonymous>)",
"summary": "Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /typescript.test.ts/i.",
Expand Down
81 changes: 0 additions & 81 deletions e2e/__tests__/__snapshots__/deadlines.ts.snap
Expand Up @@ -12,84 +12,3 @@ Time: <<REPLACED>>
Ran all test suites matching /manual-within.js/i.",
}
`;

exports[`throws on deadline exceeded 1`] = `
Object {
"rest": "FAIL __tests__/manual-exceeded.js
describe
it
describeit
deadline exceeded (waited here for <<REPLACED>>)
12 | describe('describe', () => {
13 | it('it', async () => {
> 14 | await expect.withinDeadline(sleep(200));
| ^
15 | }, 50);
16 | });
17 |
at Object.<anonymous> (__tests__/manual-exceeded.js:14:5)",
"summary": "Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /manual-exceeded.js/i.",
}
`;
exports[`throws on deadline exceeded in a describe hook 1`] = `
Object {
"rest": "FAIL __tests__/manual-exceeded-hook-describe.js
describe
does nothing
describedoes nothing
deadline exceeded (waited here for <<REPLACED>>)
12 | describe('describe', () => {
13 | beforeAll(async () => {
> 14 | await expect.withinDeadline(sleep(200));
| ^
15 | }, 50);
16 |
17 | it('does nothing', () => {});
at __tests__/manual-exceeded-hook-describe.js:14:5",
"summary": "Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /manual-exceeded-hook-describe.js/i.",
}
`;
exports[`throws on deadline exceeded in a hook 1`] = `
Object {
"rest": "FAIL __tests__/manual-exceeded-hook.js
describe
does nothing
describedoes nothing
deadline exceeded (waited here for <<REPLACED>>)
12 | describe('describe', () => {
13 | beforeEach(async () => {
> 14 | await expect.withinDeadline(sleep(200));
| ^
15 | }, 50);
16 |
17 | it('does nothing', () => {});
at Object.<anonymous> (__tests__/manual-exceeded-hook.js:14:5)",
"summary": "Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /manual-exceeded-hook.js/i.",
}
`;
154 changes: 150 additions & 4 deletions e2e/__tests__/deadlines.ts
Expand Up @@ -4,34 +4,180 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import semver = require('semver');
import {skipSuiteOnJasmine} from '@jest/test-utils';
import {extractSummary} from '../Utils';
import runJest from '../runJest';

skipSuiteOnJasmine();

function givenNode(versionRange: string, func: () => void): void {
if (semver.satisfies(process.versions.node, versionRange)) {
func();
}
}

it('passes generally', () => {
const result = runJest('deadlines', ['manual-within.js']);
expect(result.exitCode).toBe(0);
expect(summaryWithoutTime(result)).toMatchSnapshot();
const summary = summaryWithoutTime(result);
expect(summary).toMatchSnapshot();
});

it('throws on deadline exceeded', () => {
const result = runJest('deadlines', ['manual-exceeded.js']);
expect(result.exitCode).toBe(1);
expect(summaryWithoutTime(result)).toMatchSnapshot();
const summary = summaryWithoutTime(result);
givenNode('>=12', () =>
expect(summary).toMatchInlineSnapshot(`
Object {
"rest": "FAIL __tests__/manual-exceeded.js
describe
✕ it
● describe › it
deadline exceeded (waited here for <<REPLACED>>)
12 | describe('describe', () => {
13 | it('it', async () => {
> 14 | await expect.withinDeadline(sleep(200));
| ^
15 | }, 50);
16 | });
17 |
at Object.<anonymous> (__tests__/manual-exceeded.js:14:5)",
"summary": "Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /manual-exceeded.js/i.",
}
`),
);
givenNode('<12', () =>
expect(summary).toMatchInlineSnapshot(`
Object {
"rest": "FAIL __tests__/manual-exceeded.js
describe
✕ it
● describe › it
deadline exceeded (waited here for <<REPLACED>>)",
"summary": "Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /manual-exceeded.js/i.",
}
`),
);
});

it('throws on deadline exceeded in a hook', () => {
const result = runJest('deadlines', ['manual-exceeded-hook.js']);
expect(result.exitCode).toBe(1);
expect(summaryWithoutTime(result)).toMatchSnapshot();
const summary = summaryWithoutTime(result);
givenNode('>=12', () =>
expect(summary).toMatchInlineSnapshot(`
Object {
"rest": "FAIL __tests__/manual-exceeded-hook.js
describe
✕ does nothing
● describe › does nothing
deadline exceeded (waited here for <<REPLACED>>)
12 | describe('describe', () => {
13 | beforeEach(async () => {
> 14 | await expect.withinDeadline(sleep(200));
| ^
15 | }, 50);
16 |
17 | it('does nothing', () => {});
at Object.<anonymous> (__tests__/manual-exceeded-hook.js:14:5)",
"summary": "Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /manual-exceeded-hook.js/i.",
}
`),
);
givenNode('<12', () =>
expect(summary).toMatchInlineSnapshot(`
Object {
"rest": "FAIL __tests__/manual-exceeded-hook.js
describe
✕ does nothing
● describe › does nothing
deadline exceeded (waited here for <<REPLACED>>)",
"summary": "Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /manual-exceeded-hook.js/i.",
}
`),
);
});

it('throws on deadline exceeded in a describe hook', () => {
const result = runJest('deadlines', ['manual-exceeded-hook-describe.js']);
expect(result.exitCode).toBe(1);
expect(summaryWithoutTime(result)).toMatchSnapshot();
const summary = summaryWithoutTime(result);
givenNode('>=12', () =>
expect(summary).toMatchInlineSnapshot(`
Object {
"rest": "FAIL __tests__/manual-exceeded-hook-describe.js
describe
✕ does nothing
● describe › does nothing
deadline exceeded (waited here for <<REPLACED>>)
12 | describe('describe', () => {
13 | beforeAll(async () => {
> 14 | await expect.withinDeadline(sleep(200));
| ^
15 | }, 50);
16 |
17 | it('does nothing', () => {});
at __tests__/manual-exceeded-hook-describe.js:14:5",
"summary": "Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /manual-exceeded-hook-describe.js/i.",
}
`),
);
givenNode('<12', () =>
expect(summary).toMatchInlineSnapshot(`
Object {
"rest": "FAIL __tests__/manual-exceeded-hook-describe.js
describe
✕ does nothing
● describe › does nothing
deadline exceeded (waited here for <<REPLACED>>)",
"summary": "Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /manual-exceeded-hook-describe.js/i.",
}
`),
);
});

function summaryWithoutTime(result: {stderr: string}) {
Expand Down

0 comments on commit 42cabaa

Please sign in to comment.