Skip to content

Commit

Permalink
test: delay after initial add
Browse files Browse the repository at this point in the history
Adds a small delay in some tests after the initial path has been added
(to avoid the FS de-duping/cancelling events).
  • Loading branch information
43081j committed Jun 2, 2024
1 parent b879371 commit a797b5e
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,12 @@ const runTests = (baseopts) => {
});
it('should emit `unlinkDir` event when a directory was removed', async () => {
const testDir = getFixturePath('subdir');
fs.mkdirSync(testDir, PERM_ARR);
const spy = sinon.spy(function unlinkDirSpy(){});

await fs_mkdir(testDir, PERM_ARR);
await delay(300);
watcher.on(EV.UNLINK_DIR, spy);

await delay();
await fs_rmdir(testDir);
await waitFor([spy]);
spy.should.have.been.calledWith(testDir);
Expand All @@ -428,13 +429,17 @@ const runTests = (baseopts) => {
const testDir2 = getFixturePath('subdir/subdir2');
const testDir3 = getFixturePath('subdir/subdir2/subdir3');
const spy = sinon.spy(function unlinkDirSpy(){});

await fs_mkdir(testDir, PERM_ARR);
await fs_mkdir(testDir2, PERM_ARR);
await fs_mkdir(testDir3, PERM_ARR);
await delay(300);

watcher.on(EV.UNLINK_DIR, spy);
fs.mkdirSync(testDir, PERM_ARR);
fs.mkdirSync(testDir2, PERM_ARR);
fs.mkdirSync(testDir3, PERM_ARR);
await delay();

await rimraf(testDir2);
await waitFor([[spy, 2]]);

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 Expand Up @@ -470,7 +475,7 @@ const runTests = (baseopts) => {
.on(EV.UNLINK, unlinkSpy)
.on(EV.ADD, addSpy)
.on(EV.CHANGE, changeSpy);
fs.writeFileSync(testPath, 'hello');
await write(testPath, 'hello');
await waitFor([[addSpy.withArgs(testPath), 1]]);
unlinkSpy.should.not.have.been.called;
changeSpy.should.not.have.been.called;
Expand Down Expand Up @@ -544,17 +549,16 @@ const runTests = (baseopts) => {
const addSpy = sinon.spy(function addSpy(){});
const testPath = getFixturePath('dirFile');
await fs_mkdir(testPath, PERM_ARR);
await delay(300);
watcher.on(EV.UNLINK_DIR, unlinkSpy).on(EV.ADD, addSpy);

await delay();
await fs_rmdir(testPath);
await delay(300);
await waitFor([unlinkSpy]);

await write(testPath, 'file content');
await waitFor([addSpy]);

await delay(300);
await waitFor([unlinkSpy]);
unlinkSpy.should.have.been.calledWith(testPath);
await waitFor([addSpy]);
addSpy.should.have.been.calledWith(testPath);
});
it('should emit `unlink` and `addDir` when file is replaced by dir', async () => {
Expand Down

0 comments on commit a797b5e

Please sign in to comment.