()
| 251 | } |
| 252 | |
| 253 | async function runPoolTests() { |
| 254 | try { |
| 255 | await codecept.bootstrap() |
| 256 | } catch (err) { |
| 257 | throw new Error(`Error while running bootstrap file :${err}`) |
| 258 | } |
| 259 | |
| 260 | initializeListeners() |
| 261 | disablePause() |
| 262 | |
| 263 | // Emit event.all.before once at the start of pool mode |
| 264 | event.dispatcher.emit(event.all.before, codecept) |
| 265 | |
| 266 | // Accumulate results across all tests in pool mode |
| 267 | let consolidatedStats = { passes: 0, failures: 0, tests: 0, pending: 0, failedHooks: 0 } |
| 268 | let allTests = [] |
| 269 | let allFailures = [] |
| 270 | let previousStats = { passes: 0, failures: 0, tests: 0, pending: 0, failedHooks: 0 } |
| 271 | |
| 272 | // Keep requesting tests until no more available |
| 273 | while (true) { |
| 274 | // Request a test assignment and wait for response |
| 275 | const testResult = await new Promise((resolve, reject) => { |
| 276 | // Set up pool mode message handler FIRST before sending request |
| 277 | const messageHandler = async eventData => { |
| 278 | // Remove handler immediately to prevent duplicate processing |
| 279 | parentPort?.off('message', messageHandler) |
| 280 | |
| 281 | if (eventData.type === 'TEST_ASSIGNED') { |
| 282 | // In pool mode with ESM, we receive test FILE paths instead of UIDs |
| 283 | // because UIDs are not stable across different mocha instances |
| 284 | const testIdentifier = eventData.test |
| 285 | |
| 286 | try { |
| 287 | // Create a fresh Mocha instance for each test file |
| 288 | container.createMocha() |
| 289 | const mocha = container.mocha() |
| 290 | |
| 291 | // Load only the assigned test file |
| 292 | mocha.files = [testIdentifier] |
| 293 | mocha.loadFiles() |
| 294 | |
| 295 | try { |
| 296 | require('fs').appendFileSync('/tmp/config_listener_debug.log', `${new Date().toISOString()} [POOL] Loaded ${testIdentifier}, tests: ${mocha.suite.total()}\n`) |
| 297 | } catch (e) { /* ignore */ } |
| 298 | |
| 299 | if (mocha.suite.total() > 0) { |
| 300 | // Run only the tests in the current mocha suite |
| 301 | // Don't use codecept.run() as it overwrites mocha.files with ALL test files |
| 302 | await new Promise((resolve, reject) => { |
| 303 | mocha.run(() => { |
| 304 | try { |
| 305 | require('fs').appendFileSync('/tmp/config_listener_debug.log', `${new Date().toISOString()} [POOL] Finished ${testIdentifier}\n`) |
| 306 | } catch (e) { /* ignore */ } |
| 307 | resolve() |
| 308 | }) |
| 309 | }) |
| 310 |
no test coverage detected