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

@ -15,18 +15,12 @@ import {TypeScriptServiceHost} from '../src/typescript_host';
import {MockTypescriptHost} from './test_utils';
describe('references', () => {
let documentRegistry = ts.createDocumentRegistry();
let mockHost: MockTypescriptHost;
let service: ts.LanguageService;
let ngHost: TypeScriptServiceHost;
let ngService: LanguageService = createLanguageService(undefined !);
const mockHost = new MockTypescriptHost(['/app/main.ts']);
const service = ts.createLanguageService(mockHost);
const ngHost = new TypeScriptServiceHost(mockHost, service);
const ngService = createLanguageService(ngHost);
beforeEach(() => {
mockHost = new MockTypescriptHost(['/app/main.ts', '/app/parsing-cases.ts']);
service = ts.createLanguageService(mockHost, documentRegistry);
ngHost = new TypeScriptServiceHost(mockHost, service);
ngService = createLanguageService(ngHost);
});
beforeEach(() => { mockHost.reset(); });
it('should be able to get template references',
() => { expect(() => ngService.getTemplateReferences()).not.toThrow(); });