Skip to content

Commit b7416d5

Browse files
clydinfilipesilva
authored andcommitted
test: update E2E test utilities to support Node.js v16
Node.js v16's `fs.rmdir` will now throw an `ENOENT` error if the path does not exist. `fs.rm` is now the preferred option when using Node.js v16 but since this function is not available on Node.js v12 both are tried with `fs.rm` given preference.
1 parent a54e5e0 commit b7416d5

File tree

1 file changed

+26
-2
lines changed
  • tests/legacy-cli/e2e/utils

1 file changed

+26
-2
lines changed

tests/legacy-cli/e2e/utils/fs.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { promises as fs, constants } from 'fs';
1+
import { PathLike, promises as fs, constants } from 'fs';
22
import { dirname, join } from 'path';
33
import { stripIndents } from 'common-tags';
44

@@ -15,7 +15,31 @@ export function deleteFile(path: string): Promise<void> {
1515
}
1616

1717
export function rimraf(path: string): Promise<void> {
18-
return fs.rmdir(path, { recursive: true, maxRetries: 3 });
18+
// The below should be removed and replaced with just `rm` when support for Node.Js 12 is removed.
19+
const { rm, rmdir } = fs as typeof fs & {
20+
rm?: (
21+
path: PathLike,
22+
options?: {
23+
force?: boolean;
24+
maxRetries?: number;
25+
recursive?: boolean;
26+
retryDelay?: number;
27+
},
28+
) => Promise<void>;
29+
};
30+
31+
if (rm) {
32+
return rm(path, {
33+
force: true,
34+
recursive: true,
35+
maxRetries: 3,
36+
});
37+
} else {
38+
return rmdir(path, {
39+
recursive: true,
40+
maxRetries: 3,
41+
});
42+
}
1943
}
2044

2145
export function moveFile(from: string, to: string): Promise<void> {

0 commit comments

Comments
 (0)