Skip to content

Commit 94f4124

Browse files
authored
fix excluded file got added to snapshot manager (#956)
* fix excluded file got added * test doesn't fail before
1 parent 0b390a2 commit 94f4124

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

packages/language-server/src/plugins/typescript/TypeScriptPlugin.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,9 @@ export class TypeScriptPlugin
382382
}
383383
} else if (changeType === FileChangeType.Deleted) {
384384
snapshotManager.delete(fileName);
385-
return;
385+
} else {
386+
snapshotManager.updateTsOrJsFile(fileName);
386387
}
387-
388-
snapshotManager.updateTsOrJsFile(fileName);
389388
}
390389
}
391390

packages/language-server/test/plugins/typescript/TypescriptPlugin.test.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,19 @@ describe('TypescriptPlugin', () => {
431431
assert.equal(secondSnapshot, undefined);
432432
});
433433

434-
it('should add snapshot when project file added', async () => {
434+
const testForOnWatchedFileAdd = async (filePath: string, shouldExist: boolean) => {
435435
const { snapshotManager, plugin, targetSvelteFile } = await setupForOnWatchedFileChanges();
436-
const addFile = path.join(path.dirname(targetSvelteFile), 'foo.ts');
436+
const addFile = path.join(path.dirname(targetSvelteFile), filePath);
437437
const normalizedAddFilePath = normalizeWatchFilePath(addFile);
438438

439+
const dir = path.dirname(addFile);
440+
if (!fs.existsSync(dir)) {
441+
fs.mkdirSync(dir);
442+
}
443+
fs.writeFileSync(addFile, 'export function abc() {}');
444+
assert.ok(fs.existsSync(addFile));
445+
439446
try {
440-
fs.writeFileSync(addFile, 'export function abc() {}');
441447
assert.equal(snapshotManager.has(normalizedAddFilePath), false);
442448

443449
await plugin.onWatchFileChanges([
@@ -447,10 +453,18 @@ describe('TypescriptPlugin', () => {
447453
}
448454
]);
449455

450-
assert.equal(snapshotManager.has(normalizedAddFilePath), true);
456+
assert.equal(snapshotManager.has(normalizedAddFilePath), shouldExist);
451457
} finally {
452458
fs.unlinkSync(addFile);
453459
}
460+
};
461+
462+
it('should add snapshot when a project file is added', async () => {
463+
await testForOnWatchedFileAdd('foo.ts', true);
464+
});
465+
466+
it('should not add snapshot when an excluded file is added', async () => {
467+
await testForOnWatchedFileAdd(path.join('dist', 'index.js'), false);
454468
});
455469

456470
it('should update ts/js file after document change', async () => {

packages/language-server/test/plugins/typescript/testfiles/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@
66
because TS does not look up other types.
77
*/
88
"types": ["svelte"]
9-
}
9+
},
10+
"exclude": [
11+
/**For testing exclude */
12+
"./dist"
13+
]
1014
}

0 commit comments

Comments
 (0)