diff --git a/e2e/__tests__/__snapshots__/babelPluginJestDeadlines.test.ts.snap b/e2e/__tests__/__snapshots__/babelPluginJestDeadlines.test.ts.snap index 25b6b72f0ae0..4bed4366c88e 100644 --- a/e2e/__tests__/__snapshots__/babelPluginJestDeadlines.test.ts.snap +++ b/e2e/__tests__/__snapshots__/babelPluginJestDeadlines.test.ts.snap @@ -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 <>) - - 11 | test('exceeded', async () => { - 12 | await sleep(10); - > 13 | await sleep(200); - | ^ - 14 | }, 50); - 15 | - - at Object. (__tests__/plain.test.js:13:3)", + at Function.resolveSync [as sync] (../../node_modules/resolve/lib/sync.js:90:15) + at Array.map ()", "summary": "Test Suites: 1 failed, 1 total -Tests: 1 failed, 1 total +Tests: 0 total Snapshots: 0 total Time: <> Ran all test suites matching /plain.test.js/i.", @@ -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 <>) + ● 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. (__tests__/typescript.test.ts:14:3)", + at Function.resolveSync [as sync] (../../node_modules/resolve/lib/sync.js:90:15) + at Array.map ()", "summary": "Test Suites: 1 failed, 1 total -Tests: 1 failed, 1 total +Tests: 0 total Snapshots: 0 total Time: <> Ran all test suites matching /typescript.test.ts/i.", diff --git a/e2e/__tests__/__snapshots__/deadlines.ts.snap b/e2e/__tests__/__snapshots__/deadlines.ts.snap index edf1ab508e33..984f5701ac7c 100644 --- a/e2e/__tests__/__snapshots__/deadlines.ts.snap +++ b/e2e/__tests__/__snapshots__/deadlines.ts.snap @@ -12,84 +12,3 @@ Time: <> Ran all test suites matching /manual-within.js/i.", } `; - -exports[`throws on deadline exceeded 1`] = ` -Object { - "rest": "FAIL __tests__/manual-exceeded.js - describe - ✕ it - - ● describe › it - - deadline exceeded (waited here for <>) - - 12 | describe('describe', () => { - 13 | it('it', async () => { - > 14 | await expect.withinDeadline(sleep(200)); - | ^ - 15 | }, 50); - 16 | }); - 17 | - - at Object. (__tests__/manual-exceeded.js:14:5)", - "summary": "Test Suites: 1 failed, 1 total -Tests: 1 failed, 1 total -Snapshots: 0 total -Time: <> -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 - - ● describe › does nothing - - deadline exceeded (waited here for <>) - - 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: <> -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 - - ● describe › does nothing - - deadline exceeded (waited here for <>) - - 12 | describe('describe', () => { - 13 | beforeEach(async () => { - > 14 | await expect.withinDeadline(sleep(200)); - | ^ - 15 | }, 50); - 16 | - 17 | it('does nothing', () => {}); - - at Object. (__tests__/manual-exceeded-hook.js:14:5)", - "summary": "Test Suites: 1 failed, 1 total -Tests: 1 failed, 1 total -Snapshots: 0 total -Time: <> -Ran all test suites matching /manual-exceeded-hook.js/i.", -} -`; diff --git a/e2e/__tests__/deadlines.ts b/e2e/__tests__/deadlines.ts index c5f968ce5ea7..de2d6c1e97cf 100644 --- a/e2e/__tests__/deadlines.ts +++ b/e2e/__tests__/deadlines.ts @@ -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 <>) + + 12 | describe('describe', () => { + 13 | it('it', async () => { + > 14 | await expect.withinDeadline(sleep(200)); + | ^ + 15 | }, 50); + 16 | }); + 17 | + + at Object. (__tests__/manual-exceeded.js:14:5)", + "summary": "Test Suites: 1 failed, 1 total +Tests: 1 failed, 1 total +Snapshots: 0 total +Time: <> +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 <>)", + "summary": "Test Suites: 1 failed, 1 total + Tests: 1 failed, 1 total + Snapshots: 0 total + Time: <> + 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 <>) + + 12 | describe('describe', () => { + 13 | beforeEach(async () => { + > 14 | await expect.withinDeadline(sleep(200)); + | ^ + 15 | }, 50); + 16 | + 17 | it('does nothing', () => {}); + + at Object. (__tests__/manual-exceeded-hook.js:14:5)", + "summary": "Test Suites: 1 failed, 1 total +Tests: 1 failed, 1 total +Snapshots: 0 total +Time: <> +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 <>)", + "summary": "Test Suites: 1 failed, 1 total + Tests: 1 failed, 1 total + Snapshots: 0 total + Time: <> + 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 <>) + + 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: <> +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 <>)", + "summary": "Test Suites: 1 failed, 1 total + Tests: 1 failed, 1 total + Snapshots: 0 total + Time: <> + Ran all test suites matching /manual-exceeded-hook-describe.js/i.", + } + `), + ); }); function summaryWithoutTime(result: {stderr: string}) {