Skip to content

Commit c8de061

Browse files
committed
feat: support loading ESM config files
In Node.js v24.0.0, v22.12.0, and v20.19.0, ECMAScript modules can be loaded via `require` in a CommonJS context without an experimental flag. When a system already uses ESM for the majority of its code it can be inconsistent and confusing to have a single CommonJS file. This change allows n-test to load a config file that's an ECMAScript module by looking for the default export. We only try the `default` property of the imported config file if it's not an array. See https://nodejs.org/api/modules.html#loading-ecmascript-modules-using-require for more information on how this works and why we use `__esModule` and the `default` property.
1 parent c4e09e7 commit c8de061

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/smoke/smoke-test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ class SmokeTest {
5252
}
5353

5454
async compileTests (sets) {
55-
const configsToRun = await filterConfigs(this.configFile, sets, this.isInteractive);
55+
let configsToRun = await filterConfigs(this.configFile, sets, this.isInteractive);
56+
if (!Array.isArray(configsToRun) && configsToRun.__esModule) {
57+
configsToRun = configsToRun.default;
58+
}
5659
const canRunCrossBrowser = await getBrowserstackConfig(this.enabledBrowsers);
5760
const globalOptions = {
5861
headers: this.globalHeaders,

0 commit comments

Comments
 (0)