feat(watchers): Integrate chokidar-based Node watcher, expose awaitWriteFinish options, and update docs/tests

This commit is contained in:
2025-12-11 21:04:42 +00:00
parent 696d454b00
commit 61a8222c9b
10 changed files with 185 additions and 960 deletions

View File

@@ -74,11 +74,15 @@ tap.test('should add paths and start watching', async () => {
testSmartwatch.add([`${TEST_DIR}/**/*.txt`]);
await testSmartwatch.start();
expect(testSmartwatch.status).toEqual('watching');
// Wait for chokidar to be ready
await delay(500);
});
tap.test('should detect ADD event for new files', async () => {
const addObservable = await testSmartwatch.getObservableFor('add');
const eventPromise = waitForEvent(addObservable);
// Subscribe FIRST, then create file
const eventPromise = waitForFileEvent(addObservable, 'add-test.txt');
// Create a new file
const testFile = path.join(TEST_DIR, 'add-test.txt');
@@ -87,9 +91,9 @@ tap.test('should detect ADD event for new files', async () => {
const [filePath] = await eventPromise;
expect(filePath).toInclude('add-test.txt');
// Cleanup - wait for atomic delay to complete (100ms debounce + 100ms atomic)
// Cleanup
await fs.promises.unlink(testFile);
await delay(250);
await delay(200);
});
tap.test('should detect CHANGE event for modified files', async () => {
@@ -98,10 +102,10 @@ tap.test('should detect CHANGE event for modified files', async () => {
await smartfile.memory.toFs('initial content', testFile);
// Wait for add event to complete
await delay(200);
await delay(300);
const changeObservable = await testSmartwatch.getObservableFor('change');
const eventPromise = waitForEvent(changeObservable);
const eventPromise = waitForFileEvent(changeObservable, 'change-test.txt');
// Modify the file
await smartfile.memory.toFs('modified content', testFile);
@@ -109,9 +113,9 @@ tap.test('should detect CHANGE event for modified files', async () => {
const [filePath] = await eventPromise;
expect(filePath).toInclude('change-test.txt');
// Cleanup - wait for atomic delay to complete
// Cleanup
await fs.promises.unlink(testFile);
await delay(250);
await delay(200);
});
tap.test('should detect UNLINK event for deleted files', async () => {
@@ -120,7 +124,7 @@ tap.test('should detect UNLINK event for deleted files', async () => {
await smartfile.memory.toFs('to be deleted', testFile);
// Wait for add event to complete
await delay(200);
await delay(300);
const unlinkObservable = await testSmartwatch.getObservableFor('unlink');