Managing Test State with Mocha Hooks: Avoiding the Pollution Trap
Mocha hooks extract repeated setup and teardown, but choosing before versus beforeEach determines whether tests stay isolated or pollute each other.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Mocha hooks extract repeated setup and teardown, but choosing before versus beforeEach determines whether tests stay isolated or pollute each other.
Mocha's native retry feature lets you automatically re‑run flaky UI tests up to a configurable number of times, reporting the attempt count so you can see exactly how often a test needed a second chance.
Mocha’s parallel test execution (v8+) speeds up suites by distributing test files across isolated worker processes. This architecture note outlines the requirements, minimal design, trust boundaries, operational checks, failure modes, and when a redesign would be needed.
Decide whether to use Playwright Test or an external runner like Jest or Mocha. Compare isolation, tracing, ecosystem, and CI integration, then see concrete configs and verification steps.
Use Mocha’s --grep to filter tests by name, supporting regex and inversion. This architecture note covers requirements, design, trust boundaries, operational checks, failure modes, and when to change the design.
Learn how Mocha’s native retry feature works, see a concrete example of retrying a flaky API call, and understand the trade‑offs and best‑practice guidelines for using it in CI pipelines.
Learn how to use Mocha's --parallel flag to reduce test suite execution time by distributing test files across multiple worker processes.
A decision guide for Mocha async testing: compare done callbacks, returned promises, and async/await, then implement isolated tests with Sinon stubs and proper cleanup.
Mocha hooks control test setup and teardown. Match before/after to suite lifetime and beforeEach/afterEach to test isolation to avoid pollution and unnecessary cost.