refactor(compiler-cli): move typecheck test utils into its own package (#42984)
This commit moves the test utils used in the typechecking tests into its own package. This makes them available to be used in the tests of a different package. Refs #42966 PR Close #42984
This commit is contained in:
parent
be8a8e17a8
commit
29e2bc7d91
|
@ -26,6 +26,7 @@ ts_library(
|
|||
"//packages/compiler-cli/src/ngtsc/typecheck",
|
||||
"//packages/compiler-cli/src/ngtsc/typecheck/api",
|
||||
"//packages/compiler-cli/src/ngtsc/typecheck/diagnostics",
|
||||
"//packages/compiler-cli/src/ngtsc/typecheck/testing",
|
||||
"//packages/compiler-cli/src/ngtsc/util",
|
||||
"@npm//typescript",
|
||||
],
|
||||
|
|
|
@ -12,7 +12,7 @@ import {absoluteFrom, getSourceFileOrError} from '../../file_system';
|
|||
import {runInEachFileSystem, TestFile} from '../../file_system/testing';
|
||||
import {OptimizeFor, TypeCheckingConfig} from '../api';
|
||||
|
||||
import {ngForDeclaration, ngForDts, setup, TestDeclaration} from './test_utils';
|
||||
import {ngForDeclaration, ngForDts, setup, TestDeclaration} from '../testing';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('template diagnostics', () => {
|
||||
|
|
|
@ -15,7 +15,7 @@ import {sfExtensionData, ShimReferenceTagger} from '../../shims';
|
|||
import {expectCompleteReuse, makeProgram} from '../../testing';
|
||||
import {OptimizeFor} from '../api';
|
||||
|
||||
import {setup} from './test_utils';
|
||||
import {setup} from '../testing';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('template type-checking program', () => {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
import {initMockFileSystem} from '../../file_system/testing';
|
||||
import {tcb, TestDeclaration} from './test_utils';
|
||||
import {tcb, TestDeclaration} from '../testing';
|
||||
|
||||
describe('type check blocks diagnostics', () => {
|
||||
beforeEach(() => initMockFileSystem('Native'));
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import {initMockFileSystem} from '../../file_system/testing';
|
||||
import {TypeCheckingConfig} from '../api';
|
||||
|
||||
import {ALL_ENABLED_CONFIG, tcb, TestDeclaration, TestDirective} from './test_utils';
|
||||
import {ALL_ENABLED_CONFIG, tcb, TestDeclaration, TestDirective} from '../testing';
|
||||
|
||||
|
||||
describe('type check blocks', () => {
|
||||
|
|
|
@ -14,7 +14,7 @@ import {runInEachFileSystem} from '../../file_system/testing';
|
|||
import {getTokenAtPosition} from '../../util/src/typescript';
|
||||
import {CompletionKind, GlobalCompletion, TemplateTypeChecker, TypeCheckingConfig} from '../api';
|
||||
|
||||
import {getClass, setup, TypeCheckingTarget} from './test_utils';
|
||||
import {getClass, setup, TypeCheckingTarget} from '../testing';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('TemplateTypeChecker.getGlobalCompletions()', () => {
|
||||
|
|
|
@ -15,7 +15,7 @@ import {runInEachFileSystem} from '../../file_system/testing';
|
|||
import {ClassDeclaration} from '../../reflection';
|
||||
import {DirectiveSymbol, DomBindingSymbol, ElementSymbol, ExpressionSymbol, InputBindingSymbol, OutputBindingSymbol, PipeSymbol, ReferenceSymbol, Symbol, SymbolKind, TemplateSymbol, TemplateTypeChecker, TypeCheckingConfig, VariableSymbol} from '../api';
|
||||
|
||||
import {getClass, ngForDeclaration, ngForTypeCheckTarget, setup as baseTestSetup, TypeCheckingTarget} from './test_utils';
|
||||
import {getClass, ngForDeclaration, ngForTypeCheckTarget, setup as baseTestSetup, TypeCheckingTarget} from '../testing';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('TemplateTypeChecker.getSymbolOfNode', () => {
|
||||
|
|
|
@ -11,7 +11,7 @@ import {absoluteFrom, absoluteFromSourceFile, getSourceFileOrError} from '../../
|
|||
import {runInEachFileSystem} from '../../file_system/testing';
|
||||
import {OptimizeFor} from '../api';
|
||||
|
||||
import {getClass, setup, TestDeclaration} from './test_utils';
|
||||
import {getClass, setup, TestDeclaration} from '../testing';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('TemplateTypeChecker', () => {
|
||||
|
|
|
@ -19,7 +19,7 @@ import {InliningMode, PendingFileTypeCheckingData, TypeCheckContextImpl, TypeChe
|
|||
import {TemplateSourceManager} from '../src/source';
|
||||
import {TypeCheckFile} from '../src/type_check_file';
|
||||
|
||||
import {ALL_ENABLED_CONFIG} from './test_utils';
|
||||
import {ALL_ENABLED_CONFIG} from '../testing';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
describe('ngtsc typechecking', () => {
|
||||
|
|
|
@ -13,7 +13,7 @@ import {isNamedClassDeclaration, TypeScriptReflectionHost} from '../../reflectio
|
|||
import {getDeclaration, makeProgram} from '../../testing';
|
||||
import {TypeParameterEmitter} from '../src/type_parameter_emitter';
|
||||
|
||||
import {angularCoreDts} from './test_utils';
|
||||
import {angularCoreDts} from '../testing';
|
||||
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
load("//tools:defaults.bzl", "ts_library")
|
||||
|
||||
ts_library(
|
||||
name = "testing",
|
||||
testonly = True,
|
||||
srcs = glob([
|
||||
"**/*.ts",
|
||||
]),
|
||||
visibility = ["//packages/compiler-cli/src/ngtsc:__subpackages__"],
|
||||
deps = [
|
||||
"//packages/compiler",
|
||||
"//packages/compiler-cli/src/ngtsc/file_system",
|
||||
"//packages/compiler-cli/src/ngtsc/file_system/testing",
|
||||
"//packages/compiler-cli/src/ngtsc/imports",
|
||||
"//packages/compiler-cli/src/ngtsc/incremental",
|
||||
"//packages/compiler-cli/src/ngtsc/metadata",
|
||||
"//packages/compiler-cli/src/ngtsc/perf",
|
||||
"//packages/compiler-cli/src/ngtsc/program_driver",
|
||||
"//packages/compiler-cli/src/ngtsc/reflection",
|
||||
"//packages/compiler-cli/src/ngtsc/scope",
|
||||
"//packages/compiler-cli/src/ngtsc/testing",
|
||||
"//packages/compiler-cli/src/ngtsc/typecheck",
|
||||
"//packages/compiler-cli/src/ngtsc/typecheck/api",
|
||||
"//packages/compiler-cli/src/ngtsc/typecheck/diagnostics",
|
||||
"//packages/compiler-cli/src/ngtsc/util",
|
||||
"@npm//typescript",
|
||||
],
|
||||
)
|
|
@ -35,58 +35,58 @@ export function typescriptLibDts(): TestFile {
|
|||
return {
|
||||
name: absoluteFrom('/lib.d.ts'),
|
||||
contents: `
|
||||
type Partial<T> = { [P in keyof T]?: T[P]; };
|
||||
type Pick<T, K extends keyof T> = { [P in K]: T[P]; };
|
||||
type NonNullable<T> = T extends null | undefined ? never : T;
|
||||
|
||||
// The following native type declarations are required for proper type inference
|
||||
declare interface Function {
|
||||
call(...args: any[]): any;
|
||||
}
|
||||
declare interface Array<T> {
|
||||
[index: number]: T;
|
||||
length: number;
|
||||
}
|
||||
declare interface String {
|
||||
length: number;
|
||||
}
|
||||
|
||||
declare interface Event {
|
||||
preventDefault(): void;
|
||||
}
|
||||
declare interface MouseEvent extends Event {
|
||||
readonly x: number;
|
||||
readonly y: number;
|
||||
}
|
||||
|
||||
declare interface HTMLElementEventMap {
|
||||
"click": MouseEvent;
|
||||
}
|
||||
declare interface HTMLElement {
|
||||
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any): void;
|
||||
addEventListener(type: string, listener: (evt: Event): void;): void;
|
||||
}
|
||||
declare interface HTMLDivElement extends HTMLElement {}
|
||||
declare interface HTMLImageElement extends HTMLElement {
|
||||
src: string;
|
||||
alt: string;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
declare interface HTMLQuoteElement extends HTMLElement {
|
||||
cite: string;
|
||||
}
|
||||
declare interface HTMLElementTagNameMap {
|
||||
"blockquote": HTMLQuoteElement;
|
||||
"div": HTMLDivElement;
|
||||
"img": HTMLImageElement;
|
||||
}
|
||||
declare interface Document {
|
||||
createElement<K extends keyof HTMLElementTagNameMap>(tagName: K): HTMLElementTagNameMap[K];
|
||||
createElement(tagName: string): HTMLElement;
|
||||
}
|
||||
declare const document: Document;
|
||||
`
|
||||
type Partial<T> = { [P in keyof T]?: T[P]; };
|
||||
type Pick<T, K extends keyof T> = { [P in K]: T[P]; };
|
||||
type NonNullable<T> = T extends null | undefined ? never : T;
|
||||
|
||||
// The following native type declarations are required for proper type inference
|
||||
declare interface Function {
|
||||
call(...args: any[]): any;
|
||||
}
|
||||
declare interface Array<T> {
|
||||
[index: number]: T;
|
||||
length: number;
|
||||
}
|
||||
declare interface String {
|
||||
length: number;
|
||||
}
|
||||
|
||||
declare interface Event {
|
||||
preventDefault(): void;
|
||||
}
|
||||
declare interface MouseEvent extends Event {
|
||||
readonly x: number;
|
||||
readonly y: number;
|
||||
}
|
||||
|
||||
declare interface HTMLElementEventMap {
|
||||
"click": MouseEvent;
|
||||
}
|
||||
declare interface HTMLElement {
|
||||
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any): void;
|
||||
addEventListener(type: string, listener: (evt: Event): void;): void;
|
||||
}
|
||||
declare interface HTMLDivElement extends HTMLElement {}
|
||||
declare interface HTMLImageElement extends HTMLElement {
|
||||
src: string;
|
||||
alt: string;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
declare interface HTMLQuoteElement extends HTMLElement {
|
||||
cite: string;
|
||||
}
|
||||
declare interface HTMLElementTagNameMap {
|
||||
"blockquote": HTMLQuoteElement;
|
||||
"div": HTMLDivElement;
|
||||
"img": HTMLImageElement;
|
||||
}
|
||||
declare interface Document {
|
||||
createElement<K extends keyof HTMLElementTagNameMap>(tagName: K): HTMLElementTagNameMap[K];
|
||||
createElement(tagName: string): HTMLElement;
|
||||
}
|
||||
declare const document: Document;
|
||||
`
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -94,18 +94,18 @@ export function angularCoreDts(): TestFile {
|
|||
return {
|
||||
name: absoluteFrom('/node_modules/@angular/core/index.d.ts'),
|
||||
contents: `
|
||||
export declare class TemplateRef<C> {
|
||||
abstract readonly elementRef: unknown;
|
||||
abstract createEmbeddedView(context: C): unknown;
|
||||
}
|
||||
|
||||
export declare class EventEmitter<T> {
|
||||
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): unknown;
|
||||
subscribe(observerOrNext?: any, error?: any, complete?: any): unknown;
|
||||
}
|
||||
|
||||
export declare type NgIterable<T> = Array<T> | Iterable<T>;
|
||||
`
|
||||
export declare class TemplateRef<C> {
|
||||
abstract readonly elementRef: unknown;
|
||||
abstract createEmbeddedView(context: C): unknown;
|
||||
}
|
||||
|
||||
export declare class EventEmitter<T> {
|
||||
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): unknown;
|
||||
subscribe(observerOrNext?: any, error?: any, complete?: any): unknown;
|
||||
}
|
||||
|
||||
export declare type NgIterable<T> = Array<T> | Iterable<T>;
|
||||
`
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -113,10 +113,10 @@ export function angularAnimationsDts(): TestFile {
|
|||
return {
|
||||
name: absoluteFrom('/node_modules/@angular/animations/index.d.ts'),
|
||||
contents: `
|
||||
export declare class AnimationEvent {
|
||||
element: any;
|
||||
}
|
||||
`
|
||||
export declare class AnimationEvent {
|
||||
element: any;
|
||||
}
|
||||
`
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -136,25 +136,25 @@ export function ngForDts(): TestFile {
|
|||
return {
|
||||
name: absoluteFrom('/ngfor.d.ts'),
|
||||
contents: `
|
||||
export declare class NgForOf<T> {
|
||||
ngForOf: T[];
|
||||
ngForTrackBy: TrackByFunction<T>;
|
||||
static ngTemplateContextGuard<T>(dir: NgForOf<T>, ctx: any): ctx is NgForOfContext<T>;
|
||||
}
|
||||
|
||||
export interface TrackByFunction<T> {
|
||||
(index: number, item: T): any;
|
||||
}
|
||||
|
||||
export declare class NgForOfContext<T> {
|
||||
$implicit: T;
|
||||
index: number;
|
||||
count: number;
|
||||
readonly odd: boolean;
|
||||
readonly even: boolean;
|
||||
readonly first: boolean;
|
||||
readonly last: boolean;
|
||||
}`,
|
||||
export declare class NgForOf<T> {
|
||||
ngForOf: T[];
|
||||
ngForTrackBy: TrackByFunction<T>;
|
||||
static ngTemplateContextGuard<T>(dir: NgForOf<T>, ctx: any): ctx is NgForOfContext<T>;
|
||||
}
|
||||
|
||||
export interface TrackByFunction<T> {
|
||||
(index: number, item: T): any;
|
||||
}
|
||||
|
||||
export declare class NgForOfContext<T> {
|
||||
$implicit: T;
|
||||
index: number;
|
||||
count: number;
|
||||
readonly odd: boolean;
|
||||
readonly even: boolean;
|
||||
readonly first: boolean;
|
||||
readonly last: boolean;
|
||||
}`,
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue