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",
|
||||||
"//packages/compiler-cli/src/ngtsc/typecheck/api",
|
"//packages/compiler-cli/src/ngtsc/typecheck/api",
|
||||||
"//packages/compiler-cli/src/ngtsc/typecheck/diagnostics",
|
"//packages/compiler-cli/src/ngtsc/typecheck/diagnostics",
|
||||||
|
"//packages/compiler-cli/src/ngtsc/typecheck/testing",
|
||||||
"//packages/compiler-cli/src/ngtsc/util",
|
"//packages/compiler-cli/src/ngtsc/util",
|
||||||
"@npm//typescript",
|
"@npm//typescript",
|
||||||
],
|
],
|
||||||
|
@ -12,7 +12,7 @@ import {absoluteFrom, getSourceFileOrError} from '../../file_system';
|
|||||||
import {runInEachFileSystem, TestFile} from '../../file_system/testing';
|
import {runInEachFileSystem, TestFile} from '../../file_system/testing';
|
||||||
import {OptimizeFor, TypeCheckingConfig} from '../api';
|
import {OptimizeFor, TypeCheckingConfig} from '../api';
|
||||||
|
|
||||||
import {ngForDeclaration, ngForDts, setup, TestDeclaration} from './test_utils';
|
import {ngForDeclaration, ngForDts, setup, TestDeclaration} from '../testing';
|
||||||
|
|
||||||
runInEachFileSystem(() => {
|
runInEachFileSystem(() => {
|
||||||
describe('template diagnostics', () => {
|
describe('template diagnostics', () => {
|
||||||
|
@ -15,7 +15,7 @@ import {sfExtensionData, ShimReferenceTagger} from '../../shims';
|
|||||||
import {expectCompleteReuse, makeProgram} from '../../testing';
|
import {expectCompleteReuse, makeProgram} from '../../testing';
|
||||||
import {OptimizeFor} from '../api';
|
import {OptimizeFor} from '../api';
|
||||||
|
|
||||||
import {setup} from './test_utils';
|
import {setup} from '../testing';
|
||||||
|
|
||||||
runInEachFileSystem(() => {
|
runInEachFileSystem(() => {
|
||||||
describe('template type-checking program', () => {
|
describe('template type-checking program', () => {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {initMockFileSystem} from '../../file_system/testing';
|
import {initMockFileSystem} from '../../file_system/testing';
|
||||||
import {tcb, TestDeclaration} from './test_utils';
|
import {tcb, TestDeclaration} from '../testing';
|
||||||
|
|
||||||
describe('type check blocks diagnostics', () => {
|
describe('type check blocks diagnostics', () => {
|
||||||
beforeEach(() => initMockFileSystem('Native'));
|
beforeEach(() => initMockFileSystem('Native'));
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
import {initMockFileSystem} from '../../file_system/testing';
|
import {initMockFileSystem} from '../../file_system/testing';
|
||||||
import {TypeCheckingConfig} from '../api';
|
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', () => {
|
describe('type check blocks', () => {
|
||||||
|
@ -14,7 +14,7 @@ import {runInEachFileSystem} from '../../file_system/testing';
|
|||||||
import {getTokenAtPosition} from '../../util/src/typescript';
|
import {getTokenAtPosition} from '../../util/src/typescript';
|
||||||
import {CompletionKind, GlobalCompletion, TemplateTypeChecker, TypeCheckingConfig} from '../api';
|
import {CompletionKind, GlobalCompletion, TemplateTypeChecker, TypeCheckingConfig} from '../api';
|
||||||
|
|
||||||
import {getClass, setup, TypeCheckingTarget} from './test_utils';
|
import {getClass, setup, TypeCheckingTarget} from '../testing';
|
||||||
|
|
||||||
runInEachFileSystem(() => {
|
runInEachFileSystem(() => {
|
||||||
describe('TemplateTypeChecker.getGlobalCompletions()', () => {
|
describe('TemplateTypeChecker.getGlobalCompletions()', () => {
|
||||||
|
@ -15,7 +15,7 @@ import {runInEachFileSystem} from '../../file_system/testing';
|
|||||||
import {ClassDeclaration} from '../../reflection';
|
import {ClassDeclaration} from '../../reflection';
|
||||||
import {DirectiveSymbol, DomBindingSymbol, ElementSymbol, ExpressionSymbol, InputBindingSymbol, OutputBindingSymbol, PipeSymbol, ReferenceSymbol, Symbol, SymbolKind, TemplateSymbol, TemplateTypeChecker, TypeCheckingConfig, VariableSymbol} from '../api';
|
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(() => {
|
runInEachFileSystem(() => {
|
||||||
describe('TemplateTypeChecker.getSymbolOfNode', () => {
|
describe('TemplateTypeChecker.getSymbolOfNode', () => {
|
||||||
|
@ -11,7 +11,7 @@ import {absoluteFrom, absoluteFromSourceFile, getSourceFileOrError} from '../../
|
|||||||
import {runInEachFileSystem} from '../../file_system/testing';
|
import {runInEachFileSystem} from '../../file_system/testing';
|
||||||
import {OptimizeFor} from '../api';
|
import {OptimizeFor} from '../api';
|
||||||
|
|
||||||
import {getClass, setup, TestDeclaration} from './test_utils';
|
import {getClass, setup, TestDeclaration} from '../testing';
|
||||||
|
|
||||||
runInEachFileSystem(() => {
|
runInEachFileSystem(() => {
|
||||||
describe('TemplateTypeChecker', () => {
|
describe('TemplateTypeChecker', () => {
|
||||||
|
@ -19,7 +19,7 @@ import {InliningMode, PendingFileTypeCheckingData, TypeCheckContextImpl, TypeChe
|
|||||||
import {TemplateSourceManager} from '../src/source';
|
import {TemplateSourceManager} from '../src/source';
|
||||||
import {TypeCheckFile} from '../src/type_check_file';
|
import {TypeCheckFile} from '../src/type_check_file';
|
||||||
|
|
||||||
import {ALL_ENABLED_CONFIG} from './test_utils';
|
import {ALL_ENABLED_CONFIG} from '../testing';
|
||||||
|
|
||||||
runInEachFileSystem(() => {
|
runInEachFileSystem(() => {
|
||||||
describe('ngtsc typechecking', () => {
|
describe('ngtsc typechecking', () => {
|
||||||
|
@ -13,7 +13,7 @@ import {isNamedClassDeclaration, TypeScriptReflectionHost} from '../../reflectio
|
|||||||
import {getDeclaration, makeProgram} from '../../testing';
|
import {getDeclaration, makeProgram} from '../../testing';
|
||||||
import {TypeParameterEmitter} from '../src/type_parameter_emitter';
|
import {TypeParameterEmitter} from '../src/type_parameter_emitter';
|
||||||
|
|
||||||
import {angularCoreDts} from './test_utils';
|
import {angularCoreDts} from '../testing';
|
||||||
|
|
||||||
|
|
||||||
runInEachFileSystem(() => {
|
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 {
|
return {
|
||||||
name: absoluteFrom('/lib.d.ts'),
|
name: absoluteFrom('/lib.d.ts'),
|
||||||
contents: `
|
contents: `
|
||||||
type Partial<T> = { [P in keyof T]?: T[P]; };
|
type Partial<T> = { [P in keyof T]?: T[P]; };
|
||||||
type Pick<T, K extends keyof T> = { [P in K]: T[P]; };
|
type Pick<T, K extends keyof T> = { [P in K]: T[P]; };
|
||||||
type NonNullable<T> = T extends null | undefined ? never : T;
|
type NonNullable<T> = T extends null | undefined ? never : T;
|
||||||
|
|
||||||
// The following native type declarations are required for proper type inference
|
// The following native type declarations are required for proper type inference
|
||||||
declare interface Function {
|
declare interface Function {
|
||||||
call(...args: any[]): any;
|
call(...args: any[]): any;
|
||||||
}
|
}
|
||||||
declare interface Array<T> {
|
declare interface Array<T> {
|
||||||
[index: number]: T;
|
[index: number]: T;
|
||||||
length: number;
|
length: number;
|
||||||
}
|
}
|
||||||
declare interface String {
|
declare interface String {
|
||||||
length: number;
|
length: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare interface Event {
|
declare interface Event {
|
||||||
preventDefault(): void;
|
preventDefault(): void;
|
||||||
}
|
}
|
||||||
declare interface MouseEvent extends Event {
|
declare interface MouseEvent extends Event {
|
||||||
readonly x: number;
|
readonly x: number;
|
||||||
readonly y: number;
|
readonly y: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare interface HTMLElementEventMap {
|
declare interface HTMLElementEventMap {
|
||||||
"click": MouseEvent;
|
"click": MouseEvent;
|
||||||
}
|
}
|
||||||
declare interface HTMLElement {
|
declare interface HTMLElement {
|
||||||
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any): void;
|
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any): void;
|
||||||
addEventListener(type: string, listener: (evt: Event): void;): void;
|
addEventListener(type: string, listener: (evt: Event): void;): void;
|
||||||
}
|
}
|
||||||
declare interface HTMLDivElement extends HTMLElement {}
|
declare interface HTMLDivElement extends HTMLElement {}
|
||||||
declare interface HTMLImageElement extends HTMLElement {
|
declare interface HTMLImageElement extends HTMLElement {
|
||||||
src: string;
|
src: string;
|
||||||
alt: string;
|
alt: string;
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
}
|
}
|
||||||
declare interface HTMLQuoteElement extends HTMLElement {
|
declare interface HTMLQuoteElement extends HTMLElement {
|
||||||
cite: string;
|
cite: string;
|
||||||
}
|
}
|
||||||
declare interface HTMLElementTagNameMap {
|
declare interface HTMLElementTagNameMap {
|
||||||
"blockquote": HTMLQuoteElement;
|
"blockquote": HTMLQuoteElement;
|
||||||
"div": HTMLDivElement;
|
"div": HTMLDivElement;
|
||||||
"img": HTMLImageElement;
|
"img": HTMLImageElement;
|
||||||
}
|
}
|
||||||
declare interface Document {
|
declare interface Document {
|
||||||
createElement<K extends keyof HTMLElementTagNameMap>(tagName: K): HTMLElementTagNameMap[K];
|
createElement<K extends keyof HTMLElementTagNameMap>(tagName: K): HTMLElementTagNameMap[K];
|
||||||
createElement(tagName: string): HTMLElement;
|
createElement(tagName: string): HTMLElement;
|
||||||
}
|
}
|
||||||
declare const document: Document;
|
declare const document: Document;
|
||||||
`
|
`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,18 +94,18 @@ export function angularCoreDts(): TestFile {
|
|||||||
return {
|
return {
|
||||||
name: absoluteFrom('/node_modules/@angular/core/index.d.ts'),
|
name: absoluteFrom('/node_modules/@angular/core/index.d.ts'),
|
||||||
contents: `
|
contents: `
|
||||||
export declare class TemplateRef<C> {
|
export declare class TemplateRef<C> {
|
||||||
abstract readonly elementRef: unknown;
|
abstract readonly elementRef: unknown;
|
||||||
abstract createEmbeddedView(context: C): unknown;
|
abstract createEmbeddedView(context: C): unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class EventEmitter<T> {
|
export declare class EventEmitter<T> {
|
||||||
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): unknown;
|
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): unknown;
|
||||||
subscribe(observerOrNext?: any, error?: any, complete?: any): unknown;
|
subscribe(observerOrNext?: any, error?: any, complete?: any): unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare type NgIterable<T> = Array<T> | Iterable<T>;
|
export declare type NgIterable<T> = Array<T> | Iterable<T>;
|
||||||
`
|
`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,10 +113,10 @@ export function angularAnimationsDts(): TestFile {
|
|||||||
return {
|
return {
|
||||||
name: absoluteFrom('/node_modules/@angular/animations/index.d.ts'),
|
name: absoluteFrom('/node_modules/@angular/animations/index.d.ts'),
|
||||||
contents: `
|
contents: `
|
||||||
export declare class AnimationEvent {
|
export declare class AnimationEvent {
|
||||||
element: any;
|
element: any;
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,25 +136,25 @@ export function ngForDts(): TestFile {
|
|||||||
return {
|
return {
|
||||||
name: absoluteFrom('/ngfor.d.ts'),
|
name: absoluteFrom('/ngfor.d.ts'),
|
||||||
contents: `
|
contents: `
|
||||||
export declare class NgForOf<T> {
|
export declare class NgForOf<T> {
|
||||||
ngForOf: T[];
|
ngForOf: T[];
|
||||||
ngForTrackBy: TrackByFunction<T>;
|
ngForTrackBy: TrackByFunction<T>;
|
||||||
static ngTemplateContextGuard<T>(dir: NgForOf<T>, ctx: any): ctx is NgForOfContext<T>;
|
static ngTemplateContextGuard<T>(dir: NgForOf<T>, ctx: any): ctx is NgForOfContext<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TrackByFunction<T> {
|
export interface TrackByFunction<T> {
|
||||||
(index: number, item: T): any;
|
(index: number, item: T): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class NgForOfContext<T> {
|
export declare class NgForOfContext<T> {
|
||||||
$implicit: T;
|
$implicit: T;
|
||||||
index: number;
|
index: number;
|
||||||
count: number;
|
count: number;
|
||||||
readonly odd: boolean;
|
readonly odd: boolean;
|
||||||
readonly even: boolean;
|
readonly even: boolean;
|
||||||
readonly first: boolean;
|
readonly first: boolean;
|
||||||
readonly last: boolean;
|
readonly last: boolean;
|
||||||
}`,
|
}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user