Skip to content

Commit

Permalink
Use default export of jest-environment if present
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
noseworthy committed Mar 7, 2022
1 parent a94d84e commit b30747c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion environment.js
Expand Up @@ -13,11 +13,13 @@ const globalConfigPath = path.join(cwd, 'globalConfig.json');
const options = getMongodbMemoryOptions();
const isReplSet = Boolean(options.replSet);

const TestEnvironment = NodeEnvironment.default ? NodeEnvironment.default : NodeEnvironment;

debug(`isReplSet`, isReplSet);

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

module.exports = class MongoEnvironment extends NodeEnvironment {
module.exports = class MongoEnvironment extends TestEnvironment {
constructor(config, context) {
super(config, context);
}
Expand Down

0 comments on commit b30747c

Please sign in to comment.