Skip to content

Commit

Permalink
test(compiler-cli): load type declarations from fake_common (#41995)
Browse files Browse the repository at this point in the history
The ngtsc test targets have fake declarations files for `@angular/core`
and `@angular/common` and the template type checking tests can leverage
the fake common declarations instead of declaring its own types.

PR Close #41995
  • Loading branch information
JoostK authored and thePunderWoman committed Jun 3, 2021
1 parent bd1836b commit 481540d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 63 deletions.
13 changes: 11 additions & 2 deletions packages/compiler-cli/src/ngtsc/testing/fake_common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export declare class NgIf<T = unknown> {
'ngIfElse': 'ngIfElse';
}
, {}, never > ;
static ngTemplateGuard_ngIf: 'binding';
static ngTemplateContextGuard<T>(dir: NgIf<T>, ctx: any):
ctx is NgIfContext<Exclude<T, false|0|''|null|undefined>>;
}
Expand Down Expand Up @@ -83,8 +84,16 @@ export declare class DatePipe {
static ɵpipe: ɵɵPipeDeclaration<DatePipe, 'date'>;
}

export declare class IndexPipe {
transform<T>(value: T[], index: number): T;

static ɵpipe: ɵɵPipeDeclaration<IndexPipe, 'index'>;
}

export declare class CommonModule {
static ɵmod: ɵɵNgModuleDeclaration<
CommonModule, [typeof NgForOf, typeof NgIf, typeof DatePipe, typeof NgTemplateOutlet], never,
[typeof NgForOf, typeof NgIf, typeof DatePipe, typeof NgTemplateOutlet]>;
CommonModule,
[typeof NgForOf, typeof NgIf, typeof DatePipe, typeof IndexPipe, typeof NgTemplateOutlet],
never,
[typeof NgForOf, typeof NgIf, typeof DatePipe, typeof IndexPipe, typeof NgTemplateOutlet]>;
}
1 change: 1 addition & 0 deletions packages/compiler-cli/test/ngtsc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jasmine_node_test(
timeout = "long",
bootstrap = ["//tools/testing:node_no_angular_es5"],
data = [
"//packages/compiler-cli/src/ngtsc/testing/fake_common:npm_package",
"//packages/compiler-cli/src/ngtsc/testing/fake_core:npm_package",
],
shard_count = 4,
Expand Down
62 changes: 1 addition & 61 deletions packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {expectCompleteReuse, loadStandardTestFiles} from '../../src/ngtsc/testin

import {NgtscTestEnvironment} from './env';

const testFiles = loadStandardTestFiles();
const testFiles = loadStandardTestFiles({fakeCore: true, fakeCommon: true});

runInEachFileSystem(() => {
describe('ngtsc type checking', () => {
Expand All @@ -24,66 +24,6 @@ runInEachFileSystem(() => {
beforeEach(() => {
env = NgtscTestEnvironment.setup(testFiles);
env.tsconfig({fullTemplateTypeCheck: true});
env.write('node_modules/@angular/common/index.d.ts', `
import * as i0 from '@angular/core';
export declare class NgForOfContext<T, U extends i0.NgIterable<T> = i0.NgIterable<T>> {
$implicit: T;
count: number;
readonly even: boolean;
readonly first: boolean;
index: number;
readonly last: boolean;
ngForOf: U;
readonly odd: boolean;
constructor($implicit: T, ngForOf: U, index: number, count: number);
}
export declare class IndexPipe {
transform<T>(value: T[], index: number): T;
static ɵpipe: i0.ɵPipeDeclaration<IndexPipe, 'index'>;
}
export declare class SlicePipe {
transform<T>(value: ReadonlyArray<T>, start: number, end?: number): Array<T>;
transform(value: string, start: number, end?: number): string;
transform(value: null, start: number, end?: number): null;
transform(value: undefined, start: number, end?: number): undefined;
transform(value: any, start: number, end?: number): any;
static ɵpipe: i0.ɵPipeDeclaration<SlicePipe, 'slice'>;
}
export declare class NgForOf<T, U extends i0.NgIterable<T> = i0.NgIterable<T>> implements DoCheck {
ngForOf: (U & i0.NgIterable<T>) | undefined | null;
ngForTemplate: TemplateRef<NgForOfContext<T, U>>;
ngForTrackBy: TrackByFunction<T>;
constructor(_viewContainer: ViewContainerRef, _template: TemplateRef<NgForOfContext<T, U>>, _differs: IterableDiffers);
ngDoCheck(): void;
static ngTemplateContextGuard<T, U extends i0.NgIterable<T>>(dir: NgForOf<T, U>, ctx: any): ctx is NgForOfContext<T, U>;
static ɵdir: i0.ɵɵDirectiveDeclaration<NgForOf<any>, '[ngFor][ngForOf]', never, {'ngForOf': 'ngForOf'}, {}, never>;
}
export declare class NgIf<T = unknown> {
ngIf: T;
ngIfElse: TemplateRef<NgIfContext<T>> | null;
ngIfThen: TemplateRef<NgIfContext<T>> | null;
constructor(_viewContainer: ViewContainerRef, templateRef: TemplateRef<NgIfContext<T>>);
static ngTemplateGuard_ngIf: 'binding';
static ngTemplateContextGuard<T>(dir: NgIf<T>, ctx: any): ctx is NgIfContext<Exclude<T, false | 0 | "" | null | undefined>>;
static ɵdir: i0.ɵɵDirectiveDeclaration<NgIf<any>, '[ngIf]', never, {'ngIf': 'ngIf'}, {}, never>;
}
export declare class NgIfContext<T = unknown> {
$implicit: T;
ngIf: T;
}
export declare class CommonModule {
static ɵmod: i0.ɵɵNgModuleDeclaration<CommonModule, [typeof NgIf, typeof NgForOf, typeof IndexPipe, typeof SlicePipe], never, [typeof NgIf, typeof NgForOf, typeof IndexPipe, typeof SlicePipe]>;
}
`);
env.write('node_modules/@angular/animations/index.d.ts', `
export declare class AnimationEvent {
element: any;
Expand Down

0 comments on commit 481540d

Please sign in to comment.