From ad85a00f49b41b46f6110eaf0e398278f13c4ea6 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 11 Jan 2021 17:10:50 +0100 Subject: [PATCH] test --- e2e/__tests__/globalSetup.test.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/e2e/__tests__/globalSetup.test.ts b/e2e/__tests__/globalSetup.test.ts index 6349cf2db883..b19f3a16c427 100644 --- a/e2e/__tests__/globalSetup.test.ts +++ b/e2e/__tests__/globalSetup.test.ts @@ -8,12 +8,18 @@ import {tmpdir} from 'os'; import * as path from 'path'; import * as fs from 'graceful-fs'; -import {cleanup, runYarnInstall} from '../Utils'; +import { + cleanup, + createEmptyPackage, + runYarnInstall, + writeFiles, +} from '../Utils'; import runJest, {json as runWithJson} from '../runJest'; const DIR = path.join(tmpdir(), 'jest-global-setup'); const project1DIR = path.join(tmpdir(), 'jest-global-setup-project-1'); const project2DIR = path.join(tmpdir(), 'jest-global-setup-project-2'); +const rejectionDir = path.join(tmpdir(), 'jest-global-setup-rejection'); const e2eDir = path.resolve(__dirname, '../global-setup'); beforeAll(() => { @@ -24,12 +30,14 @@ beforeEach(() => { cleanup(DIR); cleanup(project1DIR); cleanup(project2DIR); + cleanup(rejectionDir); }); afterAll(() => { cleanup(DIR); cleanup(project1DIR); cleanup(project2DIR); + cleanup(rejectionDir); }); test('globalSetup is triggered once before all test suites', () => { @@ -153,3 +161,23 @@ test('should transform node_modules if configured by transformIgnorePatterns', ( expect(exitCode).toBe(0); }); + +test('properly handle rejections', () => { + createEmptyPackage(rejectionDir, {jest: {globalSetup: '/setup.js'}}); + writeFiles(rejectionDir, { + 'setup.js': ` + module.exports = () => Promise.reject(); + `, + 'test.js': ` + test('dummy', () => { + expect(true).toBe(true); + }); + `, + }); + + const {exitCode, stderr} = runJest(rejectionDir, [`--no-cache`]); + + expect(exitCode).toBe(1); + expect(stderr).toContain('Error: Jest: Got error running globalSetup'); + expect(stderr).toContain('reason: undefined'); +});