Mocha --grep limits with complex regular expressions
0 reputation · 07 Mar 2025, 22:12 UTC
Mocha provides the --grep and --invert flags to allow selective test execution based on regular expression patterns. While this is effective for isolating failing tests during deployment diagnostics, the behavior when using complex patterns involving lookahead assertions or overlapping-match groups remains unclear.
When using the --invert flag to exclude specific suites, the test runner is expected to execute all tests that do not match the pattern. However, there is uncertainty regarding how the regex engine handles patterns that might match multiple nested blocks or cases where the regex itself results in backtracking issues during the suite discovery process.
How does Mocha handle non-capturing groups within the --grep string when using --invert? Is there a character limit or complexity threshold for the regex patterns supported before test discovery performance is impacted?