-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
area: repository toolingconcerning ease of contributionconcerning ease of contributionstatus: accepting prsMocha can use your help with this one!Mocha can use your help with this one!
Description
Tooling Suggestion Checklist
- I have tried restarting my IDE and the issue persists.
- I have pulled the latest
mainbranch of the repository. - I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
- I have searched for related issues and issues with the
faqlabel, but none matched my issue. - I want to provide a PR to resolve this
Overview
Once my changes in #5409 are merged, I want to adapt my IPC messaging approach to improve other preexisting watch mode tests.
For example, one of the basic tests is
it("reruns test when watched test file is touched", function () {
const testFile = path.join(tempDir, "test.js");
copyFixture(DEFAULT_FIXTURE, testFile);
return runMochaWatchJSONAsync([testFile], tempDir, () => {
touchFile(testFile);
}).then((results) => {
expect(results, "to have length", 2);
});
});All of these runMochaWatchJSONAsync tests by default sleep for 2 seconds before and after the change function (in this case touchFile). This causes two problems:
- A hiccup in task switching or virtualization in the CI runner might cause Mocha to take longer to boot up or run tests than those 2 seconds, causing the test to fail
- Running the whole test suite is slow, so it's harder to iterate on improvements
I imagine refactoring this test to work like this:
it("reruns test when watched test file is touched", async function () {
const testFile = path.join(tempDir, "test.js");
copyFixture(DEFAULT_FIXTURE, testFile);
const results = await runMochaWatchJSONAsync(
[testFile],
tempDir,
// would refactor runMochaWatchJSONAsync to turn on IPC messaging
// and provide this API
async (mochaProcess, { gotMessage }) => {
// no more waiting 2 seconds when Mocha runs quickly,
// but we can wait longer if necessary when there's a hiccup
await gotMessage((msg) => msg.runFinished);
touchFile(testFile);
await gotMessage((msg) => msg.runFinished);
}
)
expect(results, "to have length", 2);
});And likewise for the other tests.
I would refactor my runMochaWatchWithChokidarMock tests to use runMochaWatchJSONAsync with a mockChokidar: true option.
Additional Info
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: repository toolingconcerning ease of contributionconcerning ease of contributionstatus: accepting prsMocha can use your help with this one!Mocha can use your help with this one!
Type
Projects
Status
No status