Skip to content

Commit 256244a

Browse files
committed
fix: address PR feedback for watcher edge cases
1 parent 00c2320 commit 256244a

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/core/file-watcher.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ const TRACKED_EXTENSIONS = new Set(
1414
getSupportedExtensions().map((extension) => extension.toLowerCase())
1515
);
1616

17+
const TRACKED_METADATA_FILES = new Set(['.gitignore']);
18+
1719
function isTrackedSourcePath(filePath: string): boolean {
20+
const basename = path.basename(filePath).toLowerCase();
21+
if (TRACKED_METADATA_FILES.has(basename)) return true;
1822
const extension = path.extname(filePath).toLowerCase();
1923
return extension.length > 0 && TRACKED_EXTENSIONS.has(extension);
2024
}

tests/auto-refresh-e2e.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,21 @@ async function waitFor(
4444
intervalMs: number
4545
): Promise<void> {
4646
const startedAt = Date.now();
47+
let lastError: unknown;
4748
while (Date.now() - startedAt < timeoutMs) {
48-
if (await condition()) return;
49+
try {
50+
if (await condition()) return;
51+
lastError = undefined;
52+
} catch (error) {
53+
lastError = error;
54+
}
4955
await sleep(intervalMs);
5056
}
51-
throw new Error(`Timed out after ${timeoutMs}ms waiting for condition`);
57+
const reason =
58+
lastError instanceof Error && lastError.message
59+
? ` Last transient error: ${lastError.message}`
60+
: '';
61+
throw new Error(`Timed out after ${timeoutMs}ms waiting for condition.${reason}`);
5262
}
5363

5464
describe('Auto-refresh E2E', () => {

tests/file-watcher.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,26 @@ describe('FileWatcher', () => {
107107
stop();
108108
}
109109
}, 5000);
110+
111+
it('triggers on .gitignore changes', async () => {
112+
const debounceMs = 250;
113+
let callCount = 0;
114+
115+
const stop = startFileWatcher({
116+
rootPath: tempDir,
117+
debounceMs,
118+
onChanged: () => {
119+
callCount++;
120+
}
121+
});
122+
123+
try {
124+
await new Promise((resolve) => setTimeout(resolve, 100));
125+
await fs.writeFile(path.join(tempDir, '.gitignore'), 'dist/\n');
126+
await new Promise((resolve) => setTimeout(resolve, debounceMs + 700));
127+
expect(callCount).toBe(1);
128+
} finally {
129+
stop();
130+
}
131+
}, 5000);
110132
});

0 commit comments

Comments
 (0)