Skip to content

Commit

Permalink
Add types
Browse files Browse the repository at this point in the history
  • Loading branch information
codetheweb committed Sep 25, 2023
1 parent 7b0c55b commit 78f9d37
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 0 deletions.
1 change: 1 addition & 0 deletions entrypoints/internal.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
1 change: 1 addition & 0 deletions entrypoints/internal.d.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./internal"
1 change: 1 addition & 0 deletions entrypoints/internal.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./internal"
25 changes: 25 additions & 0 deletions entrypoints/internal.d.ts
Original file line number Diff line number Diff line change
@@ -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<RunEvent>;
};
1 change: 1 addition & 0 deletions entrypoints/internal.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
3 changes: 3 additions & 0 deletions internal.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// For compatibility with resolution algorithms other than Node16.

export * from './entrypoints/internal.cjs';
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
143 changes: 143 additions & 0 deletions types/state-change-events.d.cts
Original file line number Diff line number Diff line change
@@ -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<string, {
declaredTests: number
failedHooks: number,
failedTests: number,
internalErrors: number
remainingTests: number,
passedKnownFailingTests: number,
passedTests: number,
selectedTests: number,
selectingLines: boolean,
skippedTests: number,
todoTests: number,
uncaughtExceptions: number,
unhandledRejections: number,
}>
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<string, Set<string>>
}
| {
type: "end"
}

0 comments on commit 78f9d37

Please sign in to comment.