Skip to content

Commit b30747c

Browse files
committed
Use default export of jest-environment if present
Jest v28 is going to start using ESM, and the latest release candidate has started exporting modules with ESM syntax: jestjs/jest#12340 This breaks jest-mongodb when importing jest-environment-node. In order to properly import this module when running in jest v28 we need to look for the default export. If the default export is present, use that, otherwise use the test environment as normal.
1 parent a94d84e commit b30747c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

environment.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ const globalConfigPath = path.join(cwd, 'globalConfig.json');
1313
const options = getMongodbMemoryOptions();
1414
const isReplSet = Boolean(options.replSet);
1515

16+
const TestEnvironment = NodeEnvironment.default ? NodeEnvironment.default : NodeEnvironment;
17+
1618
debug(`isReplSet`, isReplSet);
1719

1820
let mongo = isReplSet ? new MongoMemoryReplSet(options) : new MongoMemoryServer(options);
1921

20-
module.exports = class MongoEnvironment extends NodeEnvironment {
22+
module.exports = class MongoEnvironment extends TestEnvironment {
2123
constructor(config, context) {
2224
super(config, context);
2325
}

0 commit comments

Comments
 (0)