test(language-service): Completions test should reuse existing host and services (#33478)

Reusing the single instance of MockHost and language services makes the
tests run much faster.

PR Close #33478
This commit is contained in:
Keen Yee Liau 2019-10-29 16:32:18 -07:00 committed by Andrew Kushnir
parent 300d7ca6da
commit 31dccab2da
1 changed files with 169 additions and 177 deletions

View File

@ -9,7 +9,7 @@
import * as ts from 'typescript';
import {createLanguageService} from '../src/language_service';
import {CompletionKind, LanguageService} from '../src/types';
import {CompletionKind} from '../src/types';
import {TypeScriptServiceHost} from '../src/typescript_host';
import {MockTypescriptHost} from './test_utils';
@ -25,6 +25,8 @@ describe('completions', () => {
const ngHost = new TypeScriptServiceHost(mockHost, tsLS);
const ngLS = createLanguageService(ngHost);
beforeEach(() => { mockHost.reset(); });
it('should be able to get entity completions', () => {
const marker = mockHost.getLocationMarkerFor(APP_COMPONENT, 'entity-amp');
const completions = ngLS.getCompletionsAt(APP_COMPONENT, marker.start);
@ -370,19 +372,8 @@ describe('completions', () => {
// expectContain(completions, CompletionKind.PROPERTY, ['innerText']);
// });
});
});
describe('replace completions correctly', () => {
const mockHost = new MockTypescriptHost(['/app/main.ts']);
let ngLS: LanguageService;
beforeEach(() => {
mockHost.reset();
const tsLS = ts.createLanguageService(mockHost);
const ngHost = new TypeScriptServiceHost(mockHost, tsLS);
ngLS = createLanguageService(ngHost);
});
describe('replacement span', () => {
it('should not generate replacement entries for zero-length replacements', () => {
const fileName = mockHost.addCode(`
@Component({
@ -557,6 +548,7 @@ describe('replace completions correctly', () => {
expect(completion.kind).toBe('attribute');
expect(completion.replacementSpan).toEqual({start: location.start - 5, length: 5});
});
});
});
function expectContain(