2020-04-29 18:52:17 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2020-04-29 18:52:17 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2020-10-09 19:46:55 -04:00
|
|
|
import {LanguageService, parseNgCompilerOptions} from '../language_service';
|
2020-04-29 18:52:17 -04:00
|
|
|
|
2020-10-09 19:46:55 -04:00
|
|
|
import {setup, TEST_TEMPLATE} from './mock_host';
|
2020-04-29 18:52:17 -04:00
|
|
|
|
2020-10-09 19:46:55 -04:00
|
|
|
const {project, tsLS, service} = setup();
|
2020-04-29 18:52:17 -04:00
|
|
|
|
|
|
|
describe('parseNgCompilerOptions', () => {
|
|
|
|
it('should read angularCompilerOptions in tsconfig.json', () => {
|
|
|
|
const options = parseNgCompilerOptions(project);
|
|
|
|
expect(options).toEqual(jasmine.objectContaining({
|
|
|
|
enableIvy: true, // default for ivy is true
|
2020-09-28 14:26:07 -04:00
|
|
|
strictTemplates: true,
|
2020-04-29 18:52:17 -04:00
|
|
|
strictInjectionParameters: true,
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
2020-10-09 19:46:55 -04:00
|
|
|
|
|
|
|
describe('last known program', () => {
|
|
|
|
const ngLS = new LanguageService(project, tsLS);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
service.reset();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be set after getSemanticDiagnostics()', () => {
|
|
|
|
const d0 = ngLS.getSemanticDiagnostics(TEST_TEMPLATE);
|
|
|
|
expect(d0.length).toBe(0);
|
|
|
|
const p0 = getLastKnownProgram(ngLS);
|
|
|
|
|
|
|
|
const d1 = ngLS.getSemanticDiagnostics(TEST_TEMPLATE);
|
|
|
|
expect(d1.length).toBe(0);
|
|
|
|
const p1 = getLastKnownProgram(ngLS);
|
|
|
|
expect(p1).toBe(p0); // last known program should not have changed
|
|
|
|
|
|
|
|
service.overwrite(TEST_TEMPLATE, `<test-c¦omp></test-comp>`);
|
|
|
|
const d2 = ngLS.getSemanticDiagnostics(TEST_TEMPLATE);
|
|
|
|
expect(d2.length).toBe(0);
|
|
|
|
const p2 = getLastKnownProgram(ngLS);
|
|
|
|
expect(p2).not.toBe(p1); // last known program should have changed
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be set after getDefinitionAndBoundSpan()', () => {
|
|
|
|
const {position: pos0} = service.overwrite(TEST_TEMPLATE, `<test-c¦omp></test-comp>`);
|
|
|
|
|
|
|
|
const d0 = ngLS.getDefinitionAndBoundSpan(TEST_TEMPLATE, pos0);
|
|
|
|
expect(d0).toBeDefined();
|
|
|
|
const p0 = getLastKnownProgram(ngLS);
|
|
|
|
|
|
|
|
const d1 = ngLS.getDefinitionAndBoundSpan(TEST_TEMPLATE, pos0);
|
|
|
|
expect(d1).toBeDefined();
|
|
|
|
const p1 = getLastKnownProgram(ngLS);
|
|
|
|
expect(p1).toBe(p0); // last known program should not have changed
|
|
|
|
|
|
|
|
const {position: pos1} = service.overwrite(TEST_TEMPLATE, `{{ ti¦tle }}`);
|
|
|
|
const d2 = ngLS.getDefinitionAndBoundSpan(TEST_TEMPLATE, pos1);
|
|
|
|
expect(d2).toBeDefined();
|
|
|
|
const p2 = getLastKnownProgram(ngLS);
|
|
|
|
expect(p2).not.toBe(p1); // last known program should have changed
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be set after getQuickInfoAtPosition()', () => {
|
|
|
|
const {position: pos0} = service.overwrite(TEST_TEMPLATE, `<test-c¦omp></test-comp>`);
|
|
|
|
|
|
|
|
const q0 = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, pos0);
|
|
|
|
expect(q0).toBeDefined();
|
|
|
|
const p0 = getLastKnownProgram(ngLS);
|
|
|
|
|
|
|
|
const q1 = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, pos0);
|
|
|
|
expect(q1).toBeDefined();
|
|
|
|
const p1 = getLastKnownProgram(ngLS);
|
|
|
|
expect(p1).toBe(p0); // last known program should not have changed
|
|
|
|
|
|
|
|
const {position: pos1} = service.overwrite(TEST_TEMPLATE, `{{ ti¦tle }}`);
|
|
|
|
const q2 = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, pos1);
|
|
|
|
expect(q2).toBeDefined();
|
|
|
|
const p2 = getLastKnownProgram(ngLS);
|
|
|
|
expect(p2).not.toBe(p1); // last known program should have changed
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be set after getTypeDefinitionAtPosition()', () => {
|
|
|
|
const {position: pos0} = service.overwrite(TEST_TEMPLATE, `<test-c¦omp></test-comp>`);
|
|
|
|
|
|
|
|
const q0 = ngLS.getTypeDefinitionAtPosition(TEST_TEMPLATE, pos0);
|
|
|
|
expect(q0).toBeDefined();
|
|
|
|
const p0 = getLastKnownProgram(ngLS);
|
|
|
|
|
|
|
|
const d1 = ngLS.getTypeDefinitionAtPosition(TEST_TEMPLATE, pos0);
|
|
|
|
expect(d1).toBeDefined();
|
|
|
|
const p1 = getLastKnownProgram(ngLS);
|
|
|
|
expect(p1).toBe(p0); // last known program should not have changed
|
|
|
|
|
|
|
|
const {position: pos1} = service.overwrite(TEST_TEMPLATE, `{{ ti¦tle }}`);
|
|
|
|
const d2 = ngLS.getTypeDefinitionAtPosition(TEST_TEMPLATE, pos1);
|
|
|
|
expect(d2).toBeDefined();
|
|
|
|
const p2 = getLastKnownProgram(ngLS);
|
|
|
|
expect(p2).not.toBe(p1); // last known program should have changed
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function getLastKnownProgram(ngLS: LanguageService): ts.Program {
|
|
|
|
const program = ngLS['compilerFactory']['lastKnownProgram'];
|
|
|
|
expect(program).toBeDefined();
|
|
|
|
return program!;
|
|
|
|
}
|