forked from vuejs/vetur
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test for reuse typechecker in ts language service
- Loading branch information
1 parent
37374ef
commit 9659aee
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
server/src/services/typescriptService/test/serviceHost.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import assert from 'assert'; | ||
import path from 'path'; | ||
import ts from 'typescript'; | ||
import { TextDocument } from 'vscode-languageserver-textdocument'; | ||
import { URI } from 'vscode-uri'; | ||
import { getDefaultVLSConfig } from '../../../config'; | ||
import { getVueDocumentRegions } from '../../../embeddedSupport/embeddedSupport'; | ||
import { LanguageModelCache } from '../../../embeddedSupport/languageModelCache'; | ||
import { createEnvironmentService } from '../../EnvironmentService'; | ||
import { getServiceHost } from '../serviceHost'; | ||
|
||
suite('serviceHost', () => { | ||
suite('interpolation performance', () => { | ||
const repoRootPath = path.resolve(__dirname, '../../../../..'); | ||
const fixturePath = path.resolve(__dirname, repoRootPath, './test/interpolation/fixture'); | ||
|
||
function setup() { | ||
const scriptRegionDocuments: LanguageModelCache<TextDocument> = { | ||
refreshAndGet(doc) { | ||
return getVueDocumentRegions(doc).getSingleTypeDocument('script'); | ||
}, | ||
onDocumentRemoved() {}, | ||
dispose() {} | ||
}; | ||
const serviceHost = getServiceHost( | ||
ts, | ||
createEnvironmentService( | ||
fixturePath, | ||
fixturePath, | ||
fixturePath, | ||
path.join(fixturePath, 'package.json'), | ||
fixturePath, | ||
[], | ||
getDefaultVLSConfig() | ||
), | ||
scriptRegionDocuments | ||
); | ||
|
||
const filePath = path.join(fixturePath, 'DoNotMatter.vue'); | ||
const doc = TextDocument.create(URI.file(filePath).toString(), 'vue', 0, ''); | ||
|
||
return { serviceHost, doc }; | ||
} | ||
test('reuse type checker', () => { | ||
const { serviceHost, doc } = setup(); | ||
|
||
const firstTypeChecker = serviceHost.updateCurrentVueTextDocument(doc).service.getProgram()?.getTypeChecker(); | ||
|
||
const secondTypeChecker = serviceHost.updateCurrentVueTextDocument(doc).service.getProgram()?.getTypeChecker(); | ||
|
||
assert.strictEqual(firstTypeChecker, secondTypeChecker); | ||
}).timeout(4000); | ||
test('reuse type checker', () => { | ||
const { serviceHost, doc } = setup(); | ||
|
||
const firstTypeChecker = serviceHost | ||
.updateCurrentVirtualVueTextDocument(doc) | ||
.templateService.getProgram() | ||
?.getTypeChecker(); | ||
|
||
const secondTypeChecker = serviceHost | ||
.updateCurrentVirtualVueTextDocument(doc) | ||
.templateService.getProgram() | ||
?.getTypeChecker(); | ||
|
||
assert.strictEqual(firstTypeChecker, secondTypeChecker); | ||
}).timeout(4000); | ||
}); | ||
}); |