From 30afe405ab3462107714fb401ad1b75e24dd8306 Mon Sep 17 00:00:00 2001 From: "Lyu, Wei Da" Date: Thu, 16 Nov 2023 15:07:19 +0800 Subject: [PATCH] chore: try fix flaky test --- .../features/CompletionProvider.test.ts | 2 +- .../test/plugins/typescript/service.test.ts | 29 +++++++++++++++++++ .../testfiles/completions/ScndImport.svelte | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 packages/language-server/test/plugins/typescript/testfiles/completions/ScndImport.svelte diff --git a/packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts b/packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts index ef22b06ee..ee6ee4acf 100644 --- a/packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts +++ b/packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts @@ -783,7 +783,7 @@ describe('CompletionProviderImpl', function () { async function openFileToBeImported( docManager: DocumentManager, completionProvider: CompletionsProviderImpl, - name = 'imported-file.svelte' + name = '../imported-file.svelte' ) { const filePath = join(testFilesDir, name); const hoverinfoDoc = docManager.openClientDocument({ diff --git a/packages/language-server/test/plugins/typescript/service.test.ts b/packages/language-server/test/plugins/typescript/service.test.ts index 1ad5e17a1..ad56a35bd 100644 --- a/packages/language-server/test/plugins/typescript/service.test.ts +++ b/packages/language-server/test/plugins/typescript/service.test.ts @@ -185,4 +185,33 @@ describe('service', () => { ); } }); + + it('can open client file that do not exist in fs', async () => { + const dirPath = getRandomVirtualDirPath(testDir); + const { virtualSystem, lsDocumentContext, rootUris } = setup(); + + virtualSystem.writeFile( + path.join(dirPath, 'tsconfig.json'), + JSON.stringify({ + compilerOptions: { + checkJs: true, + strict: true + } + }) + ); + + const ls = await getService( + path.join(dirPath, 'random.svelte'), + rootUris, + lsDocumentContext + ); + + const document = new Document(pathToUrl(path.join(dirPath, 'random.ts')), ''); + document.openedByClient = true; + ls.updateSnapshot(document); + + assert.doesNotThrow(() => { + ls.getService().getSemanticDiagnostics(document.getFilePath()!); + }); + }); }); diff --git a/packages/language-server/test/plugins/typescript/testfiles/completions/ScndImport.svelte b/packages/language-server/test/plugins/typescript/testfiles/completions/ScndImport.svelte new file mode 100644 index 000000000..f0b453d29 --- /dev/null +++ b/packages/language-server/test/plugins/typescript/testfiles/completions/ScndImport.svelte @@ -0,0 +1 @@ + \ No newline at end of file