| 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 | |
| 311 | // Get the results from this specific test run |
| 312 | const result = container.result() |
| 313 | const currentStats = result.stats || {} |
| 314 | |
| 315 | // Calculate the difference from previous accumulated stats |
| 316 | const newPasses = Math.max(0, (currentStats.passes || 0) - previousStats.passes) |
| 317 | const newFailures = Math.max(0, (currentStats.failures || 0) - previousStats.failures) |
| 318 | const newTests = Math.max(0, (currentStats.tests || 0) - previousStats.tests) |
| 319 | const newPending = Math.max(0, (currentStats.pending || 0) - previousStats.pending) |
| 320 | const newFailedHooks = Math.max(0, (currentStats.failedHooks || 0) - previousStats.failedHooks) |
| 321 | |
| 322 | // Add only the new results |
| 323 | consolidatedStats.passes += newPasses |
| 324 | consolidatedStats.failures += newFailures |
| 325 | consolidatedStats.tests += newTests |
| 326 | consolidatedStats.pending += newPending |
| 327 | consolidatedStats.failedHooks += newFailedHooks |
| 328 | |
| 329 | // Update previous stats for next comparison |
| 330 | previousStats = { ...currentStats } |
| 331 | |
| 332 | // Add new failures to consolidated collections |
| 333 | if (result.failures && result.failures.length > allFailures.length) { |
| 334 | const newFailures = result.failures.slice(allFailures.length) |