(test)
| 11 | |
| 12 | class CodeceptRerunner extends BaseCodecept { |
| 13 | async runOnce(test) { |
| 14 | await container.started() |
| 15 | |
| 16 | // Ensure translations are loaded for Gherkin features |
| 17 | try { |
| 18 | const { loadTranslations } = await import('./mocha/gherkin.js') |
| 19 | await loadTranslations() |
| 20 | } catch (e) { |
| 21 | // Ignore if gherkin module not available |
| 22 | } |
| 23 | |
| 24 | return new Promise(async (resolve, reject) => { |
| 25 | try { |
| 26 | // Create a fresh Mocha instance for each run |
| 27 | // @ts-ignore |
| 28 | container.createMocha() |
| 29 | const mocha = container.mocha() |
| 30 | |
| 31 | let filesToRun = this.testFiles |
| 32 | if (test) { |
| 33 | if (!fsPath.isAbsolute(test)) { |
| 34 | test = fsPath.join(store.codeceptDir, test) |
| 35 | } |
| 36 | filesToRun = this.testFiles.filter(t => fsPath.basename(t, '.js') === test || t === test) |
| 37 | } |
| 38 | |
| 39 | // Clear any existing tests/suites |
| 40 | mocha.suite.suites = [] |
| 41 | mocha.suite.tests = [] |
| 42 | |
| 43 | // Manually load each test file by importing it |
| 44 | for (const file of filesToRun) { |
| 45 | try { |
| 46 | // Clear CommonJS cache if available (for mixed environments) |
| 47 | try { |
| 48 | delete require.cache[file] |
| 49 | } catch (e) { |
| 50 | // ESM modules don't have require.cache, ignore |
| 51 | } |
| 52 | |
| 53 | // Force reload the module by using a cache-busting query parameter |
| 54 | const fileUrl = `${fsPath.resolve(file)}` |
| 55 | const resolvedPath = resolveImportModulePath(fileUrl) |
| 56 | await import(resolvedPath) |
| 57 | } catch (e) { |
| 58 | console.error(`Error loading test file ${file}:`, e) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | const done = () => { |
| 63 | event.emit(event.all.result, container.result()) |
| 64 | event.emit(event.all.after, this) |
| 65 | |
| 66 | // Check if there were any failures |
| 67 | if (container.result().hasFailed) { |
| 68 | reject(new Error('Test run failed')) |
| 69 | } else { |
| 70 | resolve(undefined) |
no test coverage detected