Tooling Suggestion Checklist
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
Tooling Suggestion Checklist
mainbranch of the repository.faqlabel, but none matched my issue.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
All of these
runMochaWatchJSONAsynctests by default sleep for 2 seconds before and after the change function (in this casetouchFile). This causes two problems:I imagine refactoring this test to work like this:
And likewise for the other tests.
I would refactor my
runMochaWatchWithChokidarMocktests to userunMochaWatchJSONAsyncwith amockChokidar: trueoption.Additional Info
No response