aboutsummaryrefslogtreecommitdiff
path: root/test/js/node/watch/fs.watch.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/js/node/watch/fs.watch.test.js')
-rw-r--r--test/js/node/watch/fs.watch.test.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/js/node/watch/fs.watch.test.js b/test/js/node/watch/fs.watch.test.js
index 33d05df29..faf6a8546 100644
--- a/test/js/node/watch/fs.watch.test.js
+++ b/test/js/node/watch/fs.watch.test.js
@@ -19,6 +19,8 @@ const testDir = tempDirWithFiles("watch", {
"url.txt": "hello",
"close.txt": "hello",
"close-close.txt": "hello",
+ "sym-sync.txt": "hello",
+ "sym.txt": "hello",
[encodingFileName]: "hello",
});
@@ -341,6 +343,36 @@ describe("fs.watch", () => {
watcher.once("close", () => reject());
});
});
+
+ test("should work with symlink", async () => {
+ const filepath = path.join(testDir, "sym-symlink2.txt");
+ await fs.promises.symlink(path.join(testDir, "sym-sync.txt"), filepath);
+
+ const interval = repeat(() => {
+ fs.writeFileSync(filepath, "hello");
+ });
+
+ const promise = new Promise((resolve, reject) => {
+ let timeout = null;
+ const watcher = fs.watch(filepath, event => {
+ clearTimeout(timeout);
+ clearInterval(interval);
+ try {
+ resolve(event);
+ } catch (e) {
+ reject(e);
+ } finally {
+ watcher.close();
+ }
+ });
+ setTimeout(() => {
+ clearInterval(interval);
+ watcher?.close();
+ reject("timeout");
+ }, 3000);
+ });
+ expect(promise).resolves.toBe("change");
+ });
});
describe("fs.promises.watch", () => {
@@ -464,4 +496,27 @@ describe("fs.promises.watch", () => {
}
})();
});
+
+ test("should work with symlink", async () => {
+ const filepath = path.join(testDir, "sym-symlink.txt");
+ await fs.promises.symlink(path.join(testDir, "sym.txt"), filepath);
+
+ const watcher = fs.promises.watch(filepath);
+ const interval = repeat(() => {
+ fs.writeFileSync(filepath, "hello");
+ });
+
+ const promise = (async () => {
+ try {
+ for await (const event of watcher) {
+ return event.eventType;
+ }
+ } catch (e) {
+ expect("unreacheable").toBe(false);
+ } finally {
+ clearInterval(interval);
+ }
+ })();
+ expect(promise).resolves.toBe("change");
+ });
});