Skip to content

Commit

Permalink
test: try use fix fs delays
Browse files Browse the repository at this point in the history
  • Loading branch information
43081j committed Mar 24, 2024
1 parent 0101e20 commit b8fdee2
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions test.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-env mocha */

'use strict';

import fs from 'node:fs';
import sysPath from 'node:path';
import {fileURLToPath, pathToFileURL} from 'node:url';
Expand Down Expand Up @@ -101,18 +99,14 @@ const waitFor = async (spies) => {
}
return spy.callCount >= 1;
};
let intrvl, timeo;
function finish() {
clearInterval(intrvl);
clearTimeout(timeo);
resolve();
}
intrvl = setInterval(() => {
process.nextTick(() => {
if (spies.every(isSpyReady)) finish();
});
}, 20);
timeo = setTimeout(finish, 5000);
const checkSpiesReady = () => {
if (spies.every(isSpyReady)) {
resolve();
} else {
setTimeout(checkSpiesReady, 20);
}
};
checkSpiesReady();
});
};

Expand Down Expand Up @@ -262,31 +256,49 @@ const runTests = (baseopts) => {
await write(test3Path, dateNow());
await write(test4Path, dateNow());
await write(test5Path, dateNow());

await waitFor([[spy, 5]]);

await write(test6Path, dateNow());
await write(test7Path, dateNow());
await write(test8Path, dateNow());
await write(test9Path, dateNow());

await waitFor([[spy, 9]]);

await write(testb1Path, dateNow());
await write(testb2Path, dateNow());
await write(testb3Path, dateNow());
await write(testb4Path, dateNow());
await write(testb5Path, dateNow());

await waitFor([[spy, 14]]);

await write(testb6Path, dateNow());
await write(testb7Path, dateNow());
await write(testb8Path, dateNow());
await write(testb9Path, dateNow());

await waitFor([[spy, 18]]);

await write(testc1Path, dateNow());
await write(testc2Path, dateNow());
await write(testc3Path, dateNow());
await write(testc4Path, dateNow());
await write(testc5Path, dateNow());

await waitFor([[spy, 23]]);

await write(testc6Path, dateNow());
await write(testc7Path, dateNow());
await write(testc8Path, dateNow());
await write(testc9Path, dateNow());
await write(testd1Path, dateNow());
await write(teste1Path, dateNow());
await write(testf1Path, dateNow());

await waitFor([[spy, 30]]);

await write(testg1Path, dateNow());
await write(testh1Path, dateNow());
await write(testi1Path, dateNow());
Expand Down Expand Up @@ -381,9 +393,10 @@ const runTests = (baseopts) => {
fs.mkdirSync(testDir2, PERM_ARR);
fs.mkdirSync(testDir3, PERM_ARR);
const spy = await aspy(watcher, EV.UNLINK_DIR);
await waitFor([spy]);
await rimraf(testDir2); // test removing in one
await waitFor([spy]);
await Promise.all([
waitFor([[spy, 2]]),
rimraf(testDir2) // test removing in one
]);
spy.should.have.been.calledWith(testDir2);
spy.should.have.been.calledWith(testDir3);
expect(spy.args[0][1]).to.not.be.ok; // no stats
Expand Down

0 comments on commit b8fdee2

Please sign in to comment.