UNPKG

tstyche

Version:

Everything You Need for Type Testing.

745 lines (668 loc) 24.3 kB
import type ts from 'typescript'; declare enum CancellationReason { ConfigChange = "configChange", ConfigError = "configError", FailFast = "failFast", WatchClose = "watchClose" } declare class CancellationToken { #private; cancel(reason: CancellationReason): void; isCancellationRequested(): boolean; getReason(): CancellationReason | undefined; reset(): void; } declare class Cli { #private; run(commandLine: ReadonlyArray<string>, cancellationToken?: CancellationToken): Promise<number>; } declare enum DiagnosticCategory { Error = "error", Warning = "warning" } interface SuppressedError { directive: TextRange; ignore: boolean; argument?: TextRange; diagnostics: Array<ts.Diagnostic>; } declare enum TestTreeNodeBrand { Describe = "describe", Test = "test", It = "it", Expect = "expect" } declare enum TestTreeNodeFlags { None = 0, Only = 1, Skip = 2, Todo = 4 } declare class TestTreeNode { brand: TestTreeNodeBrand; children: Array<TestTreeNode | ExpectNode>; diagnostics: Set<ts.Diagnostic>; flags: TestTreeNodeFlags; name: string; node: ts.CallExpression; parent: TestTree | TestTreeNode; constructor(compiler: typeof ts, brand: TestTreeNodeBrand, node: ts.CallExpression, parent: TestTree | TestTreeNode, flags: TestTreeNodeFlags); } declare class ExpectNode extends TestTreeNode { abilityDiagnostics: Set<ts.Diagnostic>; isNot: boolean; matcherNode: ts.CallExpression | ts.Decorator; matcherNameNode: ts.PropertyAccessExpression; modifierNode: ts.PropertyAccessExpression; notNode: ts.PropertyAccessExpression | undefined; source: ts.NodeArray<ts.Expression> | ts.NodeArray<ts.TypeNode>; target: ts.NodeArray<ts.Expression> | ts.NodeArray<ts.TypeNode> | undefined; constructor(compiler: typeof ts, brand: TestTreeNodeBrand, node: ts.CallExpression, parent: TestTree | TestTreeNode, flags: TestTreeNodeFlags, matcherNode: ts.CallExpression | ts.Decorator, matcherNameNode: ts.PropertyAccessExpression, modifierNode: ts.PropertyAccessExpression, notNode: ts.PropertyAccessExpression | undefined); } declare class TestTree { children: Array<TestTreeNode | ExpectNode>; diagnostics: Set<ts.Diagnostic>; hasOnly: boolean; sourceFile: ts.SourceFile; suppressedErrors: Array<SuppressedError> | undefined; constructor(diagnostics: Set<ts.Diagnostic>, sourceFile: ts.SourceFile); } declare class DiagnosticOrigin { assertionNode: ExpectNode | undefined; end: number; sourceFile: ts.SourceFile | JsonSourceFile; start: number; constructor(start: number, end: number, sourceFile: ts.SourceFile | JsonSourceFile, assertionNode?: ExpectNode); static fromAssertion(assertionNode: ExpectNode): DiagnosticOrigin; static fromNode(node: ts.Node, assertionNode?: ExpectNode): DiagnosticOrigin; } declare class Diagnostic { category: DiagnosticCategory; code: string | undefined; origin: DiagnosticOrigin | undefined; related: Array<Diagnostic> | undefined; text: string | Array<string>; constructor(text: string | Array<string>, category: DiagnosticCategory, origin?: DiagnosticOrigin); add(options: { code?: string | undefined; related?: Array<Diagnostic> | undefined; }): this; static error(text: string | Array<string>, origin?: DiagnosticOrigin): Diagnostic; extendWith(text: string | Array<string>, origin?: DiagnosticOrigin): Diagnostic; static fromDiagnostics(diagnostics: Array<ts.Diagnostic>): Array<Diagnostic>; static warning(text: string | Array<string>, origin?: DiagnosticOrigin): Diagnostic; } declare function diagnosticBelongsToNode(diagnostic: ts.Diagnostic, node: ts.NodeArray<ts.Node> | ts.Node): boolean; declare function getDiagnosticMessageText(diagnostic: ts.Diagnostic): string | Array<string>; declare function getTextSpanEnd(span: ts.TextSpan): number; declare function isDiagnosticWithLocation(diagnostic: ts.Diagnostic): diagnostic is ts.DiagnosticWithLocation; type DiagnosticsHandler<T extends Diagnostic | Array<Diagnostic> = Diagnostic> = (this: void, diagnostics: T) => void; declare class JsonSourceFile { #private; fileName: string; text: string; constructor(fileName: string, text: string); getLineStarts(): Array<number>; getLineAndCharacterOfPosition(position: number): { line: number; character: number; }; } interface CommandLineOptions { config?: string; failFast?: boolean; fetch?: boolean; help?: boolean; list?: boolean; listFiles?: boolean; only?: string; prune?: boolean; quiet?: boolean; reporters?: Array<string>; root?: string; showConfig?: boolean; skip?: string; target?: Array<string>; tsconfig?: string; update?: boolean; verbose?: boolean; version?: boolean; watch?: boolean; } interface ConfigFileOptions { checkDeclarationFiles?: boolean; checkSuppressedErrors?: boolean; failFast?: boolean; fixtureFileMatch?: Array<string>; quiet?: boolean; rejectAnyType?: boolean; rejectNeverType?: boolean; reporters?: Array<string>; target?: Array<string>; testFileMatch?: Array<string>; tsconfig?: string; verbose?: boolean; } interface InlineConfig { fixme?: boolean; if?: { target?: Array<string>; }; template?: boolean; } interface ResolvedConfig extends Omit<CommandLineOptions, "config" | "root" | keyof ConfigFileOptions>, Required<ConfigFileOptions> { configFilePath: string; pathMatch: Array<string>; rootPath: string; } interface TextRange { start: number; end: number; text: string; } interface DirectiveRange { sourceFile: ts.SourceFile; namespace: TextRange; directive?: TextRange; argument?: TextRange; } declare class Config { #private; static parseCommandLine(commandLine: ReadonlyArray<string>): Promise<{ commandLineOptions: CommandLineOptions; pathMatch: Array<string>; }>; static parseConfigFile(configPath?: string | undefined, rootPath?: string | undefined): Promise<{ configFileOptions: ConfigFileOptions; }>; static resolve(options?: { configFileOptions?: ConfigFileOptions; commandLineOptions?: CommandLineOptions; pathMatch?: Array<string>; }): ResolvedConfig; static resolveConfigFilePath(configPath?: string | undefined, rootPath?: string | undefined): string; static resolveRootPath(rootPath?: string | undefined): string; } declare enum OptionBrand { String = "string", SemverRange = "range", Number = "number", Boolean = "boolean", True = "true", List = "list" } declare class ConfigDiagnosticText { static expected(element: string): string; static expectsListItemType(optionName: string, optionBrand: OptionBrand): string; static expectsValue(optionName: string): string; static fileDoesNotExist(filePath: string): string; static fileMatchPatternCannotStartWith(optionName: string, segment: string): Array<string>; static inspectSupportedVersions(): string; static moduleWasNotFound(specifier: string): string; static optionValueMustBe(optionName: string, optionBrand: OptionBrand): string; static rangeIsNotValid(value: string): string; static rangeDoesNotMatchSupported(value: string): string; static rangeUsage(): Array<string>; static seen(element: string): string; static unexpected(element: string): string; static unknownOption(optionName: string): string; static versionIsNotSupported(value: string): string; static watchCannotBeEnabled(): string; } declare class Directive { #private; static getDirectiveRange(compiler: typeof ts, owner: TestTreeNode, directiveText: string): DirectiveRange | undefined; static getDirectiveRanges(compiler: typeof ts, node: ts.Node): Array<DirectiveRange> | undefined; static getInlineConfig(ranges: Array<DirectiveRange> | DirectiveRange | undefined): Promise<InlineConfig | undefined>; } declare const defaultOptions: Required<ConfigFileOptions>; declare enum OptionGroup { CommandLine = 2, ConfigFile = 4, InlineConditions = 8 } interface BaseOptionDefinition { brand: OptionBrand; description: string; group: OptionGroup; name: string; } interface PrimitiveTypeOptionDefinition extends BaseOptionDefinition { brand: OptionBrand.String | OptionBrand.SemverRange | OptionBrand.Number | OptionBrand.Boolean | OptionBrand.True; } interface ItemDefinition { brand: OptionBrand.String; name: string; } interface ListTypeOptionDefinition extends BaseOptionDefinition { brand: OptionBrand.List; items: ItemDefinition; } type OptionDefinition = PrimitiveTypeOptionDefinition | ListTypeOptionDefinition; declare class Options { #private; static for(optionGroup: OptionGroup): Map<string, OptionDefinition>; static isJsonString(text: string): boolean; static resolve(optionName: string, optionValue: string, basePath?: string): string; static validate(optionName: string, optionValue: string, onDiagnostics: DiagnosticsHandler, origin?: DiagnosticOrigin): Promise<void>; } interface EnvironmentOptions { isCi: boolean; noColor: boolean; noInteractive: boolean; npmRegistry: string; storePath: string; timeout: number; typescriptModule: string | undefined; } declare const environmentOptions: EnvironmentOptions; interface Reporter { on: (event: ReporterEvent) => void; } type ReporterEvent = Exclude<Event, ["config:error" | "select:error", {}]>; declare abstract class BaseReporter implements Reporter { protected resolvedConfig: ResolvedConfig; constructor(resolvedConfig: ResolvedConfig); abstract on([event, payload]: ReporterEvent): void; } declare class DotReporter extends BaseReporter { #private; on([event, payload]: ReporterEvent): void; } declare class ListReporter extends BaseReporter { #private; on([event, payload]: ReporterEvent): void; } declare class SetupReporter { on([event, payload]: ReporterEvent): void; } declare class SummaryReporter extends BaseReporter { on([event, payload]: ReporterEvent): void; } declare class WatchReporter extends BaseReporter { on([event, payload]: ReporterEvent): void; } declare enum ProjectConfigKind { Discovered = 0, Default = 1, Provided = 2, Synthetic = 3 } declare enum ResultStatus { Runs = "runs", Passed = "passed", Matched = "matched", Failed = "failed", Fixme = "fixme", Skipped = "skipped", Ignored = "ignored", Todo = "todo" } type ProjectConfig = { kind: ProjectConfigKind; specifier: string; }; type TargetResultStatus = ResultStatus.Runs | ResultStatus.Passed | ResultStatus.Failed; type TargetCounts = { [K in Exclude<TargetResultStatus, ResultStatus.Runs>]: number; }; type FileResultStatus = ResultStatus.Runs | ResultStatus.Passed | ResultStatus.Failed; type FileCounts = { [K in Exclude<FileResultStatus, ResultStatus.Runs>]: number; }; type TestResultStatus = ResultStatus.Runs | ResultStatus.Passed | ResultStatus.Failed | ResultStatus.Skipped | ResultStatus.Fixme | ResultStatus.Todo; type TestCounts = { [K in Exclude<TestResultStatus, ResultStatus.Runs>]: number; }; type AssertionResultStatus = ResultStatus.Runs | ResultStatus.Passed | ResultStatus.Failed | ResultStatus.Skipped | ResultStatus.Fixme | ResultStatus.Todo; type AssertionCounts = { [K in Exclude<AssertionResultStatus, ResultStatus.Runs>]: number; }; type SuppressedResultStatus = ResultStatus.Matched | ResultStatus.Failed | ResultStatus.Ignored; type SuppressedCounts = { [K in SuppressedResultStatus]: number; }; type ResultCounts = TargetCounts | FileCounts | TestCounts | AssertionCounts | SuppressedCounts; interface ResultTiming { start: number; end: number; } declare class ExpectResult { expect: ExpectNode; parent: TestResult | undefined; status: AssertionResultStatus; timing: ResultTiming; constructor(expect: ExpectNode, parent?: TestResult); } declare class TestResult { assertionCounts: AssertionCounts; parent: DescribeResult | undefined; results: Array<ExpectResult>; status: ResultStatus; test: TestTreeNode; timing: ResultTiming; constructor(test: TestTreeNode, parent?: DescribeResult); } declare class DescribeResult { describe: TestTreeNode; parent: DescribeResult | undefined; results: Array<DescribeResult | TestResult>; timing: ResultTiming; constructor(describe: TestTreeNode, parent?: DescribeResult); } declare class FileLocation { #private; path: string; position: number | undefined; constructor(file: string | URL, position?: number); } declare class FileResult { assertionCounts: AssertionCounts; file: FileLocation; results: Array<DescribeResult | TestResult | ExpectResult>; suppressedCounts: SuppressedCounts; status: FileResultStatus; testCounts: TestCounts; timing: ResultTiming; constructor(file: FileLocation); } declare class ProjectResult { compilerVersion: string; projectConfig: ProjectConfig; results: Array<FileResult>; constructor(compilerVersion: string, projectConfig: ProjectConfig); } declare class TargetResult { files: Array<FileLocation>; results: Map<string | undefined, ProjectResult>; status: TargetResultStatus; target: string; timing: ResultTiming; constructor(target: string, files: Array<FileLocation>); } declare class Result { assertionCounts: AssertionCounts; fileCounts: FileCounts; files: Array<FileLocation>; results: Array<TargetResult>; suppressedCounts: SuppressedCounts; targetCounts: TargetCounts; testCounts: TestCounts; timing: ResultTiming; constructor(files: Array<FileLocation>); } declare class SuppressedResult { suppressed: SuppressedError; constructor(suppressed: SuppressedError); } type Event = ["config:error", { diagnostics: Array<Diagnostic>; }] | ["select:error", { diagnostics: Array<Diagnostic>; }] | ["run:start", { result: Result; }] | ["run:end", { result: Result; }] | ["store:adds", { packagePath: string; packageVersion: string; }] | ["store:error", { diagnostics: Array<Diagnostic>; }] | ["target:start", { result: TargetResult; }] | ["target:end", { result: TargetResult; }] | ["project:uses", { compilerVersion: string; projectConfig: ProjectConfig; }] | ["project:error", { diagnostics: Array<Diagnostic>; }] | ["file:start", { result: FileResult; }] | ["file:error", { diagnostics: Array<Diagnostic>; result: FileResult; }] | ["file:end", { result: FileResult; }] | ["directive:error", { diagnostics: Array<Diagnostic>; }] | ["collect:start", { tree: TestTree; }] | ["collect:error", { diagnostics: Array<Diagnostic>; }] | ["collect:node", { node: TestTreeNode | ExpectNode; }] | ["collect:end", { tree: TestTree; }] | ["describe:start", { result: DescribeResult; }] | ["describe:end", { result: DescribeResult; }] | ["test:start", { result: TestResult; }] | ["test:error", { diagnostics: Array<Diagnostic>; result: TestResult; }] | ["test:fail", { result: TestResult; }] | ["test:pass", { result: TestResult; }] | ["test:skip", { result: TestResult; }] | ["test:fixme", { result: TestResult; }] | ["test:todo", { result: TestResult; }] | ["expect:start", { result: ExpectResult; }] | ["expect:error", { diagnostics: Array<Diagnostic>; result: ExpectResult; }] | ["expect:fail", { diagnostics: Array<Diagnostic>; result: ExpectResult; }] | ["expect:pass", { result: ExpectResult; }] | ["expect:skip", { result: ExpectResult; }] | ["expect:fixme", { result: ExpectResult; }] | ["suppressed:error", { diagnostics: Array<Diagnostic>; result: SuppressedResult; }] | ["suppressed:match", { result: SuppressedResult; }] | ["suppressed:ignore", { result: SuppressedResult; }] | ["watch:error", { diagnostics: Array<Diagnostic>; }]; interface EventHandler { on: (event: Event) => void; } declare class EventEmitter { #private; static instanceCount: number; constructor(); addHandler(handler: EventHandler): void; addReporter(reporter: Reporter): void; static dispatch(event: Event): void; removeHandler(handler: EventHandler): void; removeReporter(reporter: Reporter): void; removeHandlers(): void; removeReporters(): void; } declare enum Color { Reset = "0", Red = "31", Green = "32", Yellow = "33", Blue = "34", Magenta = "35", Cyan = "36", Gray = "90" } type ScribblerNode = Array<ScribblerNode> | ScribblerJsx.Element | string | number | undefined; type FunctionComponent = (props: Record<string, unknown>) => ScribblerJsx.Element; declare namespace ScribblerJsx { interface Element { props: Record<string, unknown>; type: FunctionComponent | number | string; } interface IntrinsicElements { ansi: { escapes: Color | Array<Color>; }; newLine: {}; text: { children: Array<ScribblerNode>; indent: number; }; } } interface LineProps { children?: ScribblerNode; color?: Color; indent?: number; } declare function Line({ children, color, indent }: LineProps): ScribblerJsx.Element; interface ScribblerOptions { newLine?: string; noColor?: boolean; } declare class Scribbler { #private; constructor(options?: ScribblerOptions); render(element: ScribblerJsx.Element): string; } interface TextProps { children?: ScribblerNode; color?: Color | undefined; indent?: number | undefined; } declare function Text({ children, color, indent }: TextProps): ScribblerJsx.Element; declare function addsText(packageVersion: string, packagePath: string, options?: { short?: boolean; }): ScribblerJsx.Element; declare function describeNameText(name: string, indent?: number): ScribblerJsx.Element; interface CodeFrameOptions { linesAbove?: number; linesBelow?: number; showBreadcrumbs?: boolean; } declare function diagnosticText(diagnostic: Diagnostic, codeFrameOptions?: CodeFrameOptions): ScribblerJsx.Element; declare function dotText(status: ResultStatus): ScribblerJsx.Element; declare function fileStatusText(status: FileResultStatus, file: FileLocation): ScribblerJsx.Element; declare function formattedText(input: string | Array<string> | Record<string, unknown>): ScribblerJsx.Element; declare function helpText(options: Map<string, OptionDefinition>, version: string): ScribblerJsx.Element; interface WriteStream { write(text: string): void; } declare class StreamController { #private; constructor(stream: WriteStream); disable(): void; enable(): void; write(text: string): void; } declare class OutputService { #private; static errorStream: StreamController; static outputStream: StreamController; static clearTerminal(): void; static eraseLastLine(): void; static writeBlankLine(count?: number): void; static writeError(element: ScribblerJsx.Element | Array<ScribblerJsx.Element>): void; static writeMessage(element: ScribblerJsx.Element | Array<ScribblerJsx.Element>): void; static writeWarning(element: ScribblerJsx.Element | Array<ScribblerJsx.Element>): void; } declare function prologueText(runnerVersion: string, rootPath: string): ScribblerJsx.Element; interface SummaryTextOptions { targetCounts: ResultCounts; fileCounts: ResultCounts; testCounts: ResultCounts; assertionCounts: ResultCounts; suppressedCounts: SuppressedCounts; timing: ResultTiming; } declare function summaryText({ targetCounts, fileCounts, testCounts, assertionCounts, suppressedCounts, timing, }: SummaryTextOptions): ScribblerJsx.Element; declare function testNameText(status: Exclude<TestResultStatus, ResultStatus.Runs>, name: string, indent?: number): ScribblerJsx.Element; declare function usesText(compilerVersion: string, projectConfig: ProjectConfig, options?: { short?: boolean; }): ScribblerJsx.Element; declare function waitingForFileChangesText(): ScribblerJsx.Element; declare function watchUsageText(): ScribblerJsx.Element; declare class Path { static normalizeSlashes: (filePath: string) => string; static dirname(filePath: string): string; static join(...filePaths: Array<string>): string; static relative(from: string, to: string): string; static resolve(...filePaths: Array<string>): string; } declare class Runner { #private; static version: string; constructor(resolvedConfig: ResolvedConfig); run(files: Array<string | URL | FileLocation>, cancellationToken?: CancellationToken): Promise<void>; } declare class Select { #private; static isFixtureFile(filePath: string, resolvedConfig: ResolvedConfig): boolean; static isTestFile(filePath: string, resolvedConfig: ResolvedConfig): boolean; static selectFiles(resolvedConfig: ResolvedConfig): Promise<Array<string>>; } declare class SelectDiagnosticText { #private; static noTestFilesWereLeft(resolvedConfig: ResolvedConfig): Array<string>; static noTestFilesWereSelected(resolvedConfig: ResolvedConfig): Array<string>; } interface ManifestData { $version?: string; lastUpdated?: number; minorVersions: Array<string>; npmRegistry: string; packages: Record<string, { integrity: string; tarball: string; }>; resolutions: Record<string, string>; versions: Array<string>; } declare class Manifest { #private; $version: string; lastUpdated: number; minorVersions: Array<string>; npmRegistry: string; packages: Record<string, { integrity: string; tarball: string; }>; resolutions: Record<string, string>; versions: Array<string>; constructor(data: ManifestData); isOutdated(options?: { ageTolerance?: number; }): boolean; static parse(text: string): Manifest | undefined; resolve(tag: string): string | undefined; stringify(): string; } declare class Store { #private; static manifest: Manifest | undefined; static fetch(tag: string): Promise<void>; static load(tag: string): Promise<typeof ts | undefined>; static open(): Promise<void>; static prune(): Promise<void>; static update(): Promise<void>; static validateTag(tag: string): Promise<boolean | undefined>; } declare class Version { #private; static isGreaterThan(source: string, target: string): boolean; static isIncluded(source: string, range: Array<string>): boolean; static isSatisfiedWith(source: string, target: string): boolean; } export { BaseReporter, CancellationReason, CancellationToken, Cli, Color, Config, ConfigDiagnosticText, DescribeResult, Diagnostic, DiagnosticCategory, DiagnosticOrigin, Directive, DotReporter, EventEmitter, ExpectResult, FileLocation, FileResult, Line, ListReporter, OptionBrand, OptionGroup, Options, OutputService, Path, ProjectConfigKind, ProjectResult, Result, ResultStatus, Runner, Scribbler, ScribblerJsx, Select, SelectDiagnosticText, SetupReporter, Store, StreamController, SummaryReporter, SuppressedResult, TargetResult, TestResult, Text, Version, WatchReporter, addsText, defaultOptions, describeNameText, diagnosticBelongsToNode, diagnosticText, dotText, environmentOptions, fileStatusText, formattedText, getDiagnosticMessageText, getTextSpanEnd, helpText, isDiagnosticWithLocation, prologueText, summaryText, testNameText, usesText, waitingForFileChangesText, watchUsageText }; export type { AssertionCounts, AssertionResultStatus, CodeFrameOptions, CommandLineOptions, ConfigFileOptions, DiagnosticsHandler, DirectiveRange, EnvironmentOptions, Event, EventHandler, FileCounts, FileResultStatus, InlineConfig, ItemDefinition, OptionDefinition, ProjectConfig, Reporter, ReporterEvent, ResolvedConfig, ResultCounts, ResultTiming, ScribblerOptions, SuppressedCounts, SuppressedResultStatus, TargetCounts, TargetResultStatus, TestCounts, TestResultStatus, TextRange, WriteStream };