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:

committed by
Matias Niemelä

parent
43241a560a
commit
11bf7679a1
@ -8,7 +8,6 @@
|
||||
|
||||
import * as ts from 'typescript';
|
||||
import {createLanguageService} from '../src/language_service';
|
||||
import * as ng from '../src/types';
|
||||
import {TypeScriptServiceHost} from '../src/typescript_host';
|
||||
import {MockTypescriptHost} from './test_utils';
|
||||
|
||||
@ -29,17 +28,12 @@ const NG_FOR_CASES = '/app/ng-for-cases.ts';
|
||||
const NG_IF_CASES = '/app/ng-if-cases.ts';
|
||||
|
||||
describe('diagnostics', () => {
|
||||
let mockHost: MockTypescriptHost;
|
||||
let ngHost: TypeScriptServiceHost;
|
||||
let tsLS: ts.LanguageService;
|
||||
let ngLS: ng.LanguageService;
|
||||
const mockHost = new MockTypescriptHost(['/app/main.ts', '/app/parsing-cases.ts']);
|
||||
const tsLS = ts.createLanguageService(mockHost);
|
||||
const ngHost = new TypeScriptServiceHost(mockHost, tsLS);
|
||||
const ngLS = createLanguageService(ngHost);
|
||||
|
||||
beforeEach(() => {
|
||||
mockHost = new MockTypescriptHost(['/app/main.ts', '/app/parsing-cases.ts']);
|
||||
tsLS = ts.createLanguageService(mockHost);
|
||||
ngHost = new TypeScriptServiceHost(mockHost, tsLS);
|
||||
ngLS = createLanguageService(ngHost);
|
||||
});
|
||||
beforeEach(() => { mockHost.reset(); });
|
||||
|
||||
it('should produce no diagnostics for test.ng', () => {
|
||||
// there should not be any errors on existing external template
|
||||
|
Reference in New Issue
Block a user