Skip to content

test(integration): stabilize watch helper using run-completion sync#5879

Open
mostafaNazari702 wants to merge 1 commit intomochajs:mainfrom
mostafaNazari702:fix/watch-flaky-test-outside-cwd
Open

test(integration): stabilize watch helper using run-completion sync#5879
mostafaNazari702 wants to merge 1 commit intomochajs:mainfrom
mostafaNazari702:fix/watch-flaky-test-outside-cwd

Conversation

@mostafaNazari702
Copy link
Copy Markdown
Contributor

PR Checklist

Overview

This stabilizes test/integration/options/watch.spec.js by removing the brittle startup timing assumption in runMochaWatchAsync.

Before this change, helper timing was based on fixed sleeps (sleepMs) before and after the file change callback. That could miss real watch lifecycle timing on slower/contended CI environments, especially for watch paths outside the current working directory.

What changed:

  • runMochaWatchAsync now synchronizes using real watch-run completion markers from subprocess output instead of relying on fixed startup waits.
  • After applying the change callback, it waits for watch output to settle (no additional completed runs within the configured interval) before sending SIGINT.
  • This keeps behavior for tests expecting no rerun while allowing tests that trigger multiple reruns to complete consistently.

Why this approach:

Validation run:

  • npm run test-node:integration:watch30 passing
  • Repeated CI-like loops for the target test (--parallel --timeout 10000 --slow 3750, grep: outside the current working directory) passed consistently, including under CPU load.

@mostafaNazari702
Copy link
Copy Markdown
Contributor Author

Wrong branch.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.71%. Comparing base (e15bbda) to head (f755981).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5879   +/-   ##
=======================================
  Coverage   89.71%   89.71%           
=======================================
  Files          64       64           
  Lines        4695     4695           
  Branches      978      978           
=======================================
  Hits         4212     4212           
  Misses        483      483           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mostafaNazari702
Copy link
Copy Markdown
Contributor Author

I was actually right, thought that i pushed code to the previous active PR that i have. Sorry.
I would also like to mention that the PR body was rewritten from my notes, which normally sound like gibberish. using AI.

@mostafaNazari702 mostafaNazari702 force-pushed the fix/watch-flaky-test-outside-cwd branch from 8bb403d to f755981 Compare April 10, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🛠️ Repo: CI run failures (test failures)

1 participant