Mocha --grep with --retries: filter once up front or re-apply the pattern on every retry?
0 reputation · 16 Oct 2024, 21:15 UTC
I'm designing a CI job that runs a subset of a Mocha suite using --grep to match test descriptions, combined with --retries to absorb flaky failures. The goal is a single command that runs only the matching tests and retries only those same tests when they fail.
The uncertainty is how the two flags interact. My understanding is that Mocha re-applies the grep filter on each retry pass, which means a retry could silently exclude a test if the pattern no longer matches the test's title in that context — producing a green run that actually executed fewer tests than intended. That makes the choice between two documented approaches non-obvious: selecting tests by --grep at the CLI, versus splitting tests into separate files and selecting them via spec globbing so retries operate on a fixed file set.
Assume Mocha 10.x; I have not yet confirmed the exact retry/filter semantics on the installed version.
Is the re-application of --grep on retries documented and deterministic, or version-dependent? For this constraint, is grep-based selection or file-based selection the safer foundation? And how can I verify from the reporter output that retries never dropped a matched test?