aboutsummaryrefslogtreecommitdiff
path: root/test/js
diff options
context:
space:
mode:
authorGravatar Ciro Spaciari <ciro.spaciari@gmail.com> 2023-06-25 20:16:25 -0300
committerGravatar GitHub <noreply@github.com> 2023-06-25 16:16:25 -0700
commit3ed28f2828a29129a1791b7a4f6935d842d6493c (patch)
treec23b6e76e32bf9c2f30070af72593aa16289dc86 /test/js
parentfcf9f0a7eeb3d462d5c6c2110ecdf5a4460c1736 (diff)
downloadbun-3ed28f2828a29129a1791b7a4f6935d842d6493c.tar.gz
bun-3ed28f2828a29129a1791b7a4f6935d842d6493c.tar.zst
bun-3ed28f2828a29129a1791b7a4f6935d842d6493c.zip
[fs.watch] fix reference/deinit (#3396)
* fix js reference * fix close oops * refactor + hasPendingActivity * fmt * fix race conditions * fixup * add test calling close on error event * fix close inside close + test * cleanup
Diffstat (limited to 'test/js')
-rw-r--r--test/js/node/watch/fs.watch.test.js45
1 files changed, 44 insertions, 1 deletions
diff --git a/test/js/node/watch/fs.watch.test.js b/test/js/node/watch/fs.watch.test.js
index 56e1798f1..33d05df29 100644
--- a/test/js/node/watch/fs.watch.test.js
+++ b/test/js/node/watch/fs.watch.test.js
@@ -17,6 +17,8 @@ const testDir = tempDirWithFiles("watch", {
"relative.txt": "hello",
"abort.txt": "hello",
"url.txt": "hello",
+ "close.txt": "hello",
+ "close-close.txt": "hello",
[encodingFileName]: "hello",
});
@@ -105,6 +107,7 @@ describe("fs.watch", () => {
let err = undefined;
watcher.on("change", (event, filename) => {
const basename = path.basename(filename);
+
if (basename === "subfolder") return;
count++;
try {
@@ -274,6 +277,46 @@ describe("fs.watch", () => {
}
});
+ test("calling close from error event should not throw", done => {
+ const filepath = path.join(testDir, "close.txt");
+ try {
+ const ac = new AbortController();
+ const watcher = fs.watch(pathToFileURL(filepath), { signal: ac.signal });
+ watcher.once("error", () => {
+ try {
+ watcher.close();
+ done();
+ } catch (e) {
+ done("Should not error when calling close from error event");
+ }
+ });
+ ac.abort();
+ } catch (e) {
+ done(e);
+ }
+ });
+
+ test("calling close from close event should not throw", done => {
+ const filepath = path.join(testDir, "close-close.txt");
+ try {
+ const ac = new AbortController();
+ const watcher = fs.watch(pathToFileURL(filepath), { signal: ac.signal });
+
+ watcher.once("close", () => {
+ try {
+ watcher.close();
+ done();
+ } catch (e) {
+ done("Should not error when calling close from close event");
+ }
+ });
+
+ ac.abort();
+ } catch (e) {
+ done(e);
+ }
+ });
+
test("Signal aborted after creating the watcher", async () => {
const filepath = path.join(testDir, "abort.txt");
@@ -300,7 +343,7 @@ describe("fs.watch", () => {
});
});
-describe("fs.promises.watchFile", () => {
+describe("fs.promises.watch", () => {
test("add file/folder to folder", async () => {
let count = 0;
const root = path.join(testDir, "add-promise-directory");