Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Jan 11, 2021
1 parent 2f1acc2 commit ad85a00
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion e2e/__tests__/globalSetup.test.ts
Expand Up @@ -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(() => {
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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: '<rootDir>/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');
});

0 comments on commit ad85a00

Please sign in to comment.