fix(language-service): reset MockHost after every spec instead of creating new LS (#33200)

This commit speeds up the tests by calling `MockHost.reset()` in
`beforeEach()` instead of destroying the entire language service and
creating a new one. The creation of a new language service instance is
expensive due to the need to initialize many core Symbols when creating
a new program.

This speeds ups the test (on my local machine) from 35 secs to 15 secs.

PR Close #33200
This commit is contained in:
Keen Yee Liau
2019-10-16 12:00:41 -07:00
committed by Matias Niemelä
parent 43241a560a
commit 11bf7679a1
6 changed files with 27 additions and 62 deletions

View File

@ -9,24 +9,17 @@
import * as ts from 'typescript';
import {createLanguageService} from '../src/language_service';
import {LanguageService} from '../src/types';
import {TypeScriptServiceHost} from '../src/typescript_host';
import {MockTypescriptHost} from './test_utils';
describe('definitions', () => {
let mockHost: MockTypescriptHost;
let service: ts.LanguageService;
let ngHost: TypeScriptServiceHost;
let ngService: LanguageService;
const mockHost = new MockTypescriptHost(['/app/main.ts']);
const service = ts.createLanguageService(mockHost);
const ngHost = new TypeScriptServiceHost(mockHost, service);
const ngService = createLanguageService(ngHost);
beforeEach(() => {
// Create a new mockHost every time to reset any files that are overridden.
mockHost = new MockTypescriptHost(['/app/main.ts', '/app/parsing-cases.ts']);
service = ts.createLanguageService(mockHost);
ngHost = new TypeScriptServiceHost(mockHost, service);
ngService = createLanguageService(ngHost);
});
beforeEach(() => { mockHost.reset(); });
it('should be able to find field in an interpolation', () => {
const fileName = mockHost.addCode(`
@ -201,7 +194,6 @@ describe('definitions', () => {
});
it('should be able to find an input provider', () => {
// '/app/parsing-cases.ts', 'tcName',
const fileName = mockHost.addCode(`
@Component({
template: '<test-comp ~{start-my}[«tcName»]="name"~{end-my}></div>'