From 78f9d371f99b45a9633cb629b4bac8862ed2dbed Mon Sep 17 00:00:00 2001 From: Max Isom Date: Mon, 25 Sep 2023 14:54:45 -0700 Subject: [PATCH] Add types --- entrypoints/internal.cjs | 1 + entrypoints/internal.d.cts | 1 + entrypoints/internal.d.mts | 1 + entrypoints/internal.d.ts | 25 ++++++ entrypoints/internal.mjs | 1 + internal.d.ts | 3 + package.json | 10 +++ types/state-change-events.d.cts | 143 ++++++++++++++++++++++++++++++++ 8 files changed, 185 insertions(+) create mode 100644 entrypoints/internal.cjs create mode 100644 entrypoints/internal.d.cts create mode 100644 entrypoints/internal.d.mts create mode 100644 entrypoints/internal.d.ts create mode 100644 entrypoints/internal.mjs create mode 100644 internal.d.ts create mode 100644 types/state-change-events.d.cts diff --git a/entrypoints/internal.cjs b/entrypoints/internal.cjs new file mode 100644 index 000000000..f053ebf79 --- /dev/null +++ b/entrypoints/internal.cjs @@ -0,0 +1 @@ +module.exports = {}; diff --git a/entrypoints/internal.d.cts b/entrypoints/internal.d.cts new file mode 100644 index 000000000..09f74b9a2 --- /dev/null +++ b/entrypoints/internal.d.cts @@ -0,0 +1 @@ +export * from "./internal" diff --git a/entrypoints/internal.d.mts b/entrypoints/internal.d.mts new file mode 100644 index 000000000..09f74b9a2 --- /dev/null +++ b/entrypoints/internal.d.mts @@ -0,0 +1 @@ +export * from "./internal" diff --git a/entrypoints/internal.d.ts b/entrypoints/internal.d.ts new file mode 100644 index 000000000..b3392c4a3 --- /dev/null +++ b/entrypoints/internal.d.ts @@ -0,0 +1,25 @@ +import type {StateChangeEvent} from '../types/state-change-events.d.cts'; + +export type RunEvent = { + type: 'stateChange'; + stateChange: StateChangeEvent; +} | { + type: 'run'; + plan: { + bailWithoutReporting: boolean; + debug: boolean; + failFastEnabled: boolean; + filePathPrefix: string; + files: string[]; + matching: boolean; + previousFailures: number; + runOnlyExclusive: boolean; + firstRun: boolean; + }; +}; + +export type {StateChangeEvent} from '../types/state-change-events.d.cts'; + +export type Run = { + events: AsyncIterableIterator; +}; diff --git a/entrypoints/internal.mjs b/entrypoints/internal.mjs new file mode 100644 index 000000000..cb0ff5c3b --- /dev/null +++ b/entrypoints/internal.mjs @@ -0,0 +1 @@ +export {}; diff --git a/internal.d.ts b/internal.d.ts new file mode 100644 index 000000000..7971cabce --- /dev/null +++ b/internal.d.ts @@ -0,0 +1,3 @@ +// For compatibility with resolution algorithms other than Node16. + +export * from './entrypoints/internal.cjs'; diff --git a/package.json b/package.json index 5f124ff64..88c04fdce 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,16 @@ "types": "./entrypoints/plugin.d.cts", "default": "./entrypoints/plugin.cjs" } + }, + "./internal": { + "import": { + "types": "./entrypoints/internal.d.mts", + "default": "./entrypoints/internal.mjs" + }, + "require": { + "types": "./entrypoints/internal.d.cts", + "default": "./entrypoints/internal.cjs" + } } }, "type": "module", diff --git a/types/state-change-events.d.cts b/types/state-change-events.d.cts new file mode 100644 index 000000000..fd481b2fa --- /dev/null +++ b/types/state-change-events.d.cts @@ -0,0 +1,143 @@ +type ErrorSource = { + isDependency: boolean + isWithinProject: boolean + file: string + line: number +} + +type SerializedErrorBase = { + message: string + name: string, + originalError: unknown, + stack: string +} + +type AggregateSerializedError = SerializedErrorBase & { + type: "aggregate" + errors: SerializedError[] +} + +type NativeSerializedError = SerializedErrorBase & { + type: "native" + source: ErrorSource | null +} + +type AVASerializedError = SerializedErrorBase & { + type: "ava" + assertion: string + improperUsage: unknown | null + formattedCause: unknown | null + formattedDetails: unknown | unknown[] + source: ErrorSource | null +} + +type SerializedError = AggregateSerializedError | NativeSerializedError | AVASerializedError + +export type StateChangeEvent = { + type: "starting", + testFile: string +} | { + type: "stats", + stats: { + byFile: Map + declaredTests: number + failedHooks: number, + failedTests: number, + failedWorkers: number, + files: number, + parallelRuns: { + currentIndex: number, + totalRuns: number + } | null + finishedWorkers: number, + internalErrors: number + remainingTests: number, + passedKnownFailingTests: number, + passedTests: number, + selectedTests: number, + sharedWorkerErrors: number, + skippedTests: number, + timedOutTests: number, + timeouts: number, + todoTests: number, + uncaughtExceptions: number, + unhandledRejections: number, + } +} | { + type: "declared-test" + title: string + knownFailing: boolean + todo: boolean + testFile: string +} | { + type: "selected-test" + title: string + knownFailing: boolean + skip: boolean + todo: boolean + testFile: string +} | { + type: "test-register-log-reference" + title: string + logs: string[] + testFile: string +} | { + type: "test-passed", + title: string + duration: number + knownFailing: boolean + logs: string[] + testFile: string +} | { + type: "test-failed", + title: string + err: SerializedError, + duration: number + knownFailing: boolean + logs: string[] + testFile: string +} | { + type: "worker-finished", + forcedExit: boolean, + testFile: string +} | { + type: "worker-failed", + nonZeroExitCode?: boolean, + signal?: string, + err?: SerializedError +} | { + type: "touched-files", + files: { + changedFiles: string[], + temporaryFiles: string[] + } +} | { + type: 'worker-stdout', + chunk: Uint8Array + testFile: string +} | { + type: 'worker-stderr', + chunk: Uint8Array + testFile: string +} | { + type: "timeout", + period: number, + pendingTests: Map> +} + | { + type: "end" +}