Flaky-test exercise (Module 15)
flaky.test.js is deliberately flaky: it passes sometimes and fails sometimes, with no change to the code or the page. fixed.test.js is the same test, fixed. Neither runs in npm test or CI.
Both open slow-status.html, a tiny local page, so the exercise needs no network.
Run the flaky test 20 times and count the failures. Mocha has no repeat option, so use a loop:
for i in $(seq 1 20); do npx mocha tests/flaky/flaky.test.js > /dev/null 2>&1 && echo pass || echo FAIL; doneLook at a failure: the message, and the screenshot, page source, and console log that the failure hook saves in
test-results/.Write down the root cause: timing, shared state, test data, or environment.
Fix it without reading
fixed.test.js, then compare.Run your fix 50 times with the same loop (
seq 1 50) to show it is reliable.
The evidence for Evidence 15 is your written root cause, your fix, and the two runs.
Never "fix" a flaky test by adding retries or a longer sleep. That hides the variation instead of removing it. Wait explicitly for the condition the test needs.
View this document on GitHub practice-repo/tests/flaky/README.md