From cb8e51f8cf22df8ac2224eaeac91c791fb3b9feb Mon Sep 17 00:00:00 2001 From: Daniel Trevino <23410540+danieltre23@users.noreply.github.com> Date: Thu, 12 Aug 2021 17:58:10 +0000 Subject: [PATCH] test(language-service): add extended diagnostics test (#43107) Add a test in the langauge-service to make sure the extended template diagnostics are being correctly generated. Refs #42966 PR Close #43107 --- .../ivy/test/diagnostic_spec.ts | 41 +++++++++++++++++++ .../ivy/testing/src/project.ts | 5 ++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/packages/language-service/ivy/test/diagnostic_spec.ts b/packages/language-service/ivy/test/diagnostic_spec.ts index 3d6f249c4cdf3..62f49823cccc5 100644 --- a/packages/language-service/ivy/test/diagnostic_spec.ts +++ b/packages/language-service/ivy/test/diagnostic_spec.ts @@ -361,6 +361,47 @@ describe('getSemanticDiagnostics', () => { expect(diag.category).toBe(ts.DiagnosticCategory.Error); expect(getTextOfDiagnostic(diag)).toBe(`'./missing.css'`); }); + + it('should produce invalid banana in box warning', () => { + const files = { + 'app.ts': ` + import {Component} from '@angular/core'; + @Component({ + selector: 'test', + template: '
', + }) + export class TestCmp { + bar: string = "text"; + } + ` + }; + const project = createModuleAndProjectWithDeclarations( + env, 'test', files, {strictTemplates: true, _extendedTemplateDiagnostics: true}); + + const diags = project.getDiagnosticsForFile('app.ts'); + expect(diags.length).toEqual(1); + expect(diags[0].code).toEqual(ErrorCode.INVALID_BANANA_IN_BOX); + expect(diags[0].category).toEqual(ts.DiagnosticCategory.Warning); + }); + + it('should not produce invalid banana in box warning', () => { + const files = { + 'app.ts': ` + import {Component} from '@angular/core'; + @Component({ + selector: 'test', + template: '
', + }) + export class TestCmp { + bar: string = "text"; + } + ` + }; + const project = createModuleAndProjectWithDeclarations(env, 'test', files); + + const diags = project.getDiagnosticsForFile('app.ts'); + expect(diags.length).toEqual(0); + }); }); function getTextOfDiagnostic(diag: ts.Diagnostic): string { diff --git a/packages/language-service/ivy/testing/src/project.ts b/packages/language-service/ivy/testing/src/project.ts index b3dc513405e20..18544da7ee23b 100644 --- a/packages/language-service/ivy/testing/src/project.ts +++ b/packages/language-service/ivy/testing/src/project.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {LegacyNgcOptions, StrictTemplateOptions} from '@angular/compiler-cli/src/ngtsc/core/api'; +import {InternalOptions, LegacyNgcOptions, StrictTemplateOptions} from '@angular/compiler-cli/src/ngtsc/core/api'; import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, getSourceFileOrError} from '@angular/compiler-cli/src/ngtsc/file_system'; import {OptimizeFor, TemplateTypeChecker} from '@angular/compiler-cli/src/ngtsc/typecheck/api'; import * as ts from 'typescript/lib/tsserverlibrary'; @@ -44,7 +44,8 @@ function writeTsconfig( null, 2)); } -export type TestableOptions = StrictTemplateOptions&Pick; +export type TestableOptions = + StrictTemplateOptions&InternalOptions&Pick; export class Project { private tsProject: ts.server.Project;