Skip to content

Commit

Permalink
test for reuse typechecker in ts language service
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlyu123 committed Jan 22, 2021
1 parent 37374ef commit 9659aee
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions server/src/services/typescriptService/test/serviceHost.test.ts
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);
});
});

0 comments on commit 9659aee

Please sign in to comment.