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:
parent
300d7ca6da
commit
31dccab2da
@ -9,7 +9,7 @@
|
|||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
|
|
||||||
import {createLanguageService} from '../src/language_service';
|
import {createLanguageService} from '../src/language_service';
|
||||||
import {CompletionKind, LanguageService} from '../src/types';
|
import {CompletionKind} from '../src/types';
|
||||||
import {TypeScriptServiceHost} from '../src/typescript_host';
|
import {TypeScriptServiceHost} from '../src/typescript_host';
|
||||||
|
|
||||||
import {MockTypescriptHost} from './test_utils';
|
import {MockTypescriptHost} from './test_utils';
|
||||||
@ -25,6 +25,8 @@ describe('completions', () => {
|
|||||||
const ngHost = new TypeScriptServiceHost(mockHost, tsLS);
|
const ngHost = new TypeScriptServiceHost(mockHost, tsLS);
|
||||||
const ngLS = createLanguageService(ngHost);
|
const ngLS = createLanguageService(ngHost);
|
||||||
|
|
||||||
|
beforeEach(() => { mockHost.reset(); });
|
||||||
|
|
||||||
it('should be able to get entity completions', () => {
|
it('should be able to get entity completions', () => {
|
||||||
const marker = mockHost.getLocationMarkerFor(APP_COMPONENT, 'entity-amp');
|
const marker = mockHost.getLocationMarkerFor(APP_COMPONENT, 'entity-amp');
|
||||||
const completions = ngLS.getCompletionsAt(APP_COMPONENT, marker.start);
|
const completions = ngLS.getCompletionsAt(APP_COMPONENT, marker.start);
|
||||||
@ -370,19 +372,8 @@ describe('completions', () => {
|
|||||||
// expectContain(completions, CompletionKind.PROPERTY, ['innerText']);
|
// 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', () => {
|
it('should not generate replacement entries for zero-length replacements', () => {
|
||||||
const fileName = mockHost.addCode(`
|
const fileName = mockHost.addCode(`
|
||||||
@Component({
|
@Component({
|
||||||
@ -558,6 +549,7 @@ describe('replace completions correctly', () => {
|
|||||||
expect(completion.replacementSpan).toEqual({start: location.start - 5, length: 5});
|
expect(completion.replacementSpan).toEqual({start: location.start - 5, length: 5});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function expectContain(
|
function expectContain(
|
||||||
completions: ts.CompletionInfo | undefined, kind: CompletionKind, names: string[]) {
|
completions: ts.CompletionInfo | undefined, kind: CompletionKind, names: string[]) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user