Skip to content

Commit 7685e12

Browse files
committed
fix: resolve test file discovery issue for ESM configs
Key fixes: 1. Added initMochaGlobals() call in factory.js to set up globals early 2. Fixed config loading to properly extract config from module.default - Changed: configModule.config || configModule.default?.config || configModule - To: configModule.config || configModule.default?.config || configModule.default || configModule 3. This ensures .cjs config files (which export via module.exports) are properly unwrapped when loaded as ESM Impact: - Test data files (.js) can now be discovered and loaded - Timeout tests: 10/10 passing (was 0) - All sandbox test files now loadable by CodeceptJS
1 parent 30ee679 commit 7685e12

File tree

6 files changed

+5
-2
lines changed

6 files changed

+5
-2
lines changed

lib/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ async function loadConfigFile(configFile) {
209209
}
210210
}
211211

212-
const rawConfig = configModule.config || configModule.default?.config || configModule
212+
const rawConfig = configModule.config || configModule.default?.config || configModule.default || configModule
213213

214214
// Process helpers to extract imported classes
215215
if (rawConfig.helpers) {

lib/mocha/factory.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import reporter from './cli.js'
66
import gherkinParser, { loadTranslations } from './gherkin.js'
77
import output from '../output.js'
88
import scenarioUiFunction from './ui.js'
9+
import { initMochaGlobals } from '../globals.js'
910

1011
const __filename = fileURLToPath(import.meta.url)
1112
const __dirname = fsPath.dirname(__filename)
@@ -23,6 +24,8 @@ class MochaFactory {
2324
if (mocha.suite && mocha.suite.emit) {
2425
const context = {}
2526
mocha.suite.emit('pre-require', context, '', mocha)
27+
// Also set globals immediately so they're available when ESM modules load
28+
initMochaGlobals(context)
2629
}
2730

2831
Mocha.Runner.prototype.uncaught = function (err) {

test/data/sandbox/configs/timeouts/beforeSuite_timeout_test.cjs renamed to test/data/sandbox/configs/timeouts/beforeSuite_timeout_test.js

File renamed without changes.

test/data/sandbox/configs/timeouts/codecept.conf.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
tests: './*_test.cjs',
2+
tests: './*_test.js',
33
output: './output',
44
helpers: {
55
CustomHelper: {
File renamed without changes.

test/data/sandbox/configs/timeouts/suite_timeout_test.cjs renamed to test/data/sandbox/configs/timeouts/suite_timeout_test.js

File renamed without changes.

0 commit comments

Comments
 (0)