| 394 | } |
| 395 | |
| 396 | function filterTestById(testUid) { |
| 397 | // In pool mode with ESM, test files are already loaded once at initialization |
| 398 | // We just need to filter the existing mocha suite to only include the target test |
| 399 | |
| 400 | // Get the existing mocha instance |
| 401 | const mocha = container.mocha() |
| 402 | |
| 403 | // Save reference to all suites before clearing |
| 404 | const allSuites = [...mocha.suite.suites] |
| 405 | |
| 406 | // Clear suites and tests but preserve other mocha settings |
| 407 | mocha.suite.suites = [] |
| 408 | mocha.suite.tests = [] |
| 409 | |
| 410 | // Find and add only the suite containing our target test |
| 411 | let foundTest = false |
| 412 | for (const suite of allSuites) { |
| 413 | const originalTests = [...suite.tests] |
| 414 | |
| 415 | // Check if this suite has our target test |
| 416 | const targetTest = originalTests.find(test => test.uid === testUid) |
| 417 | |
| 418 | if (targetTest) { |
| 419 | // Create a filtered suite with only the target test |
| 420 | suite.tests = [targetTest] |
| 421 | mocha.suite.suites.push(suite) |
| 422 | foundTest = true |
| 423 | break // Only include one test |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | if (!foundTest) { |
| 428 | console.error(`WARNING: Test with UID ${testUid} not found in mocha suites`) |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | function filterTests() { |
| 433 | const files = codecept.testFiles |