Skip to content

Commit

Permalink
test: add missing await in fs-rm/fs-rmdir tests
Browse files Browse the repository at this point in the history
Noticed that a few assertions were not being awaited, this could
potentially be leading to flakiness in tmp cleanup.

Refs: nodejs#41201
  • Loading branch information
bcoe committed Jan 16, 2022
1 parent 807c7e1 commit bb500d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions test/parallel/test-fs-rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,19 @@ function removeAsync(dir) {
makeNonEmptyDirectory(4, 10, 2, dir, true);

// Removal should fail without the recursive option set to true.
assert.rejects(fs.promises.rm(dir), { syscall: 'rm' });
assert.rejects(fs.promises.rm(dir, { recursive: false }), {
await assert.rejects(fs.promises.rm(dir), { syscall: 'rm' });
await assert.rejects(fs.promises.rm(dir, { recursive: false }), {
syscall: 'rm'
});

// Recursive removal should succeed.
await fs.promises.rm(dir, { recursive: true });

// Attempted removal should fail now because the directory is gone.
assert.rejects(fs.promises.rm(dir), { syscall: 'stat' });
await assert.rejects(fs.promises.rm(dir), { syscall: 'stat' });

// Should fail if target does not exist
assert.rejects(fs.promises.rm(
await assert.rejects(fs.promises.rm(
path.join(tmpdir.path, 'noexist.txt'),
{ recursive: true }
), {
Expand All @@ -207,7 +207,7 @@ function removeAsync(dir) {
});

// Should not fail if target does not exist and force option is true
fs.promises.rm(path.join(tmpdir.path, 'noexist.txt'), { force: true });
await fs.promises.rm(path.join(tmpdir.path, 'noexist.txt'), { force: true });

// Should delete file
const filePath = path.join(tmpdir.path, 'rm-promises-file.txt');
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-fs-rmdir-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ function removeAsync(dir) {
makeNonEmptyDirectory(4, 10, 2, dir, true);

// Removal should fail without the recursive option set to true.
assert.rejects(fs.promises.rmdir(dir), { syscall: 'rmdir' });
assert.rejects(fs.promises.rmdir(dir, { recursive: false }), {
await assert.rejects(fs.promises.rmdir(dir), { syscall: 'rmdir' });
await assert.rejects(fs.promises.rmdir(dir, { recursive: false }), {
syscall: 'rmdir'
});

Expand All @@ -154,7 +154,7 @@ function removeAsync(dir) {
{ code: 'ENOENT' });

// Attempted removal should fail now because the directory is gone.
assert.rejects(fs.promises.rmdir(dir), { syscall: 'rmdir' });
await assert.rejects(fs.promises.rmdir(dir), { syscall: 'rmdir' });
})().then(common.mustCall());

// Test input validation.
Expand Down

0 comments on commit bb500d4

Please sign in to comment.