From 642d740b385dd7ccc75dd9269211ba7bf6204994 Mon Sep 17 00:00:00 2001 From: Tobias Baunbaek Date: Wed, 22 Nov 2023 13:14:56 +0100 Subject: [PATCH] Add test case for .watch(file) --- README.md | 4 ++-- test.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 62cb8ccd..23b58bff 100644 --- a/README.md +++ b/README.md @@ -239,9 +239,9 @@ Efficiently mirror this drive into another. Returns a [`MirrorDrive`](https://gi Call `await mirror.done()` to wait for the mirroring to finish. -#### `const watcher = db.watch([folder])` +#### `const watcher = db.watch([file|folder])` -Returns an iterator that listens on `folder` to yield changes, by default on `/`. +Returns an iterator that listens on a `file` or `folder` to yield changes, by default on `/`. Usage example: ```js diff --git a/test.js b/test.js index 263215b9..4766a5d5 100644 --- a/test.js +++ b/test.js @@ -462,6 +462,23 @@ test('watch(folder) should normalize folder', async function (t) { onchange = null }) +test('watch(file) basic', async function (t) { + t.plan(1) + t.timeout(1000) + + const { drive } = await testenv(t.teardown) + const buf = b4a.from('hi') + + await drive.put('/a.txt', buf) + + const watcher = drive.watch('/a.txt') + watcher.next().then(data => { + t.ok(data) + }) + + await drive.put('/a.txt', buf) +}) + test('drive.diff(length)', async (t) => { const { drive, paths: { root, tmp } } = await testenv(t.teardown) const paths = []