Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

globalSetup and globalTeardown use default export with es modules #7750

Merged
merged 3 commits into from
Jan 29, 2019
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
2 changes: 1 addition & 1 deletion e2e/__tests__/globalSetup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,6 @@ test('globalSetup throws with named export', () => {

expect(status).toBe(1);
expect(stderr).toMatch(
`TypeError: globalSetup file must use a default export with ES Modules at ${setupPath}`,
`TypeError: globalSetup file must export a function at ${setupPath}`,
);
});
20 changes: 6 additions & 14 deletions packages/jest-cli/src/runGlobalHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import pEachSeries from 'p-each-series';
import {addHook} from 'pirates';
import Runtime from 'jest-runtime';

// copied from https://github.com/babel/babel/blob/56044c7851d583d498f919e9546caddf8f80a72f/packages/babel-helpers/src/helpers.js#L558-L562
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}

export default ({
allTests,
globalConfig,
Expand Down Expand Up @@ -59,20 +64,7 @@ export default ({
);

// $FlowFixMe
let globalModule = require(modulePath);

if (
typeof globalModule === 'object' &&
globalModule.__esModule === true
) {
if (globalModule.default) {
globalModule = globalModule.default;
} else {
throw new TypeError(
`${moduleName} file must use a default export with ES Modules at ${modulePath}`,
);
}
}
const globalModule = _interopRequireDefault(require(modulePath)).default;
chrisblossom marked this conversation as resolved.
Show resolved Hide resolved

if (typeof globalModule !== 'function') {
throw new TypeError(
Expand Down