From 1a28d61a936920b3a229b2f04958ab815c0e2024 Mon Sep 17 00:00:00 2001 From: Mike Noseworthy Date: Mon, 7 Mar 2022 13:24:16 -0330 Subject: [PATCH] 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. 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. --- environment.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/environment.js b/environment.js index 73f0a48f..d2262c76 100644 --- a/environment.js +++ b/environment.js @@ -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); }