Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(global_setup|global_teardown): fixed await call, change to TypeEr…
…ror, add path to error
  • Loading branch information
ranyitz committed Mar 20, 2018
commit 87a432c323be2c5f8831d9362811a73a86401f64
5 changes: 4 additions & 1 deletion integration-tests/__tests__/global_setup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ test('jest throws an error when globalSetup does not export a function', () => {
]);

expect(status).toBe(1);
expect(stderr).toMatch('Error: globalSetup file must export a function');
expect(stderr).toMatch(
'TypeError: globalSetup file must export a function at',
);
expect(stderr).toMatch(setupPath);
});
9 changes: 6 additions & 3 deletions integration-tests/__tests__/global_teardown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ test('globalTeardown is triggered once after all test suites', () => {
});

test('jest throws an error when globalTeardown does not export a function', () => {
const setupPath = path.resolve(
const teardownPath = path.resolve(
__dirname,
'../global-teardown/invalid_teardown.js',
);
const {status, stderr} = runJest('global-teardown', [
`--globalTeardown=${setupPath}`,
`--globalTeardown=${teardownPath}`,
]);

expect(status).toBe(1);
expect(stderr).toMatch('Error: globalTeardown file must export a function');
expect(stderr).toMatch(
'TypeError: globalTeardown file must export a function at',
);
expect(stderr).toMatch(teardownPath);
});
20 changes: 14 additions & 6 deletions packages/jest-cli/src/run_jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,16 @@ export default (async function runJest({
setConfig(contexts, {cwd: process.cwd()});
if (globalConfig.globalSetup) {
// $FlowFixMe
const globalSetup = await require(globalConfig.globalSetup);
const globalSetup = require(globalConfig.globalSetup);
if (typeof globalSetup !== 'function') {
throw new Error('globalSetup file must export a function');
throw new TypeError(
`globalSetup file must export a function at ${
globalConfig.globalSetup
}`,
);
}

globalSetup();
await globalSetup();
}
const results = await new TestScheduler(
globalConfig,
Expand All @@ -221,12 +225,16 @@ export default (async function runJest({

if (globalConfig.globalTeardown) {
// $FlowFixMe
const globalTeardown = await require(globalConfig.globalTeardown);
const globalTeardown = require(globalConfig.globalTeardown);
if (typeof globalTeardown !== 'function') {
throw new Error('globalTeardown file must export a function');
throw new TypeError(
`globalTeardown file must export a function at ${
globalConfig.globalTeardown
}`,
);
}

globalTeardown();
await globalTeardown();
}
return processResults(results, {
isJSON: globalConfig.json,
Expand Down