vouchington-tooling 0.61.1 → 0.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -0
- package/dist/postgres-test-faults/fault-support.d.mts +11 -0
- package/dist/postgres-test-faults/fault-support.mjs +61 -0
- package/dist/postgres-test-faults/fault-types.d.mts +43 -0
- package/dist/postgres-test-faults/fault-types.mjs +1 -0
- package/dist/postgres-test-faults/index.d.mts +5 -0
- package/dist/postgres-test-faults/index.mjs +4 -0
- package/dist/postgres-test-faults/lock-observers.d.mts +20 -0
- package/dist/postgres-test-faults/lock-observers.mjs +14 -0
- package/dist/postgres-test-faults/lock-wait.d.mts +13 -0
- package/dist/postgres-test-faults/lock-wait.mjs +62 -0
- package/dist/postgres-test-faults/lock-waiter.d.mts +19 -0
- package/dist/postgres-test-faults/lock-waiter.mjs +95 -0
- package/dist/postgres-test-faults/observation-queue.d.mts +2 -0
- package/dist/postgres-test-faults/observation-queue.mjs +22 -0
- package/dist/postgres-test-faults/polling.d.mts +6 -0
- package/dist/postgres-test-faults/polling.mjs +33 -0
- package/dist/postgres-test-faults/pool-query-failure.d.mts +8 -0
- package/dist/postgres-test-faults/pool-query-failure.mjs +136 -0
- package/dist/postgres-test-faults/query-failure.d.mts +8 -0
- package/dist/postgres-test-faults/query-failure.mjs +108 -0
- package/dist/postgres-test-faults/test-cluster.test-helpers.d.mts +13 -0
- package/dist/postgres-test-faults/test-cluster.test-helpers.mjs +84 -0
- package/dist/provider-replay/abort-listeners.d.mts +4 -0
- package/dist/provider-replay/abort-listeners.mjs +19 -0
- package/dist/provider-replay/aws-replay-abort-signal.d.mts +5 -0
- package/dist/provider-replay/aws-replay-abort-signal.mjs +63 -0
- package/dist/provider-replay/aws-replay-request-handler.d.mts +38 -0
- package/dist/provider-replay/aws-replay-request-handler.mjs +66 -0
- package/dist/provider-replay/force-client-option.d.mts +6 -0
- package/dist/provider-replay/force-client-option.mjs +13 -0
- package/dist/provider-replay/index.d.mts +6 -0
- package/dist/provider-replay/index.mjs +6 -0
- package/dist/provider-replay/provider-replay.d.mts +32 -0
- package/dist/provider-replay/provider-replay.mjs +54 -0
- package/dist/provider-replay/recorded-response.d.mts +17 -0
- package/dist/provider-replay/recorded-response.mjs +42 -0
- package/dist/provider-replay/replay-response.d.mts +8 -0
- package/dist/provider-replay/replay-response.mjs +38 -0
- package/dist/runner-port-policy/index.d.mts +9 -0
- package/dist/runner-port-policy/index.mjs +32 -0
- package/dist/vitest-diagnostics/index.d.mts +8 -0
- package/dist/vitest-diagnostics/index.mjs +4 -0
- package/dist/vitest-diagnostics/vitest-ci-reporters.d.mts +40 -0
- package/dist/vitest-diagnostics/vitest-ci-reporters.mjs +70 -0
- package/dist/vitest-diagnostics/vitest-file-progress-reporter.d.mts +24 -0
- package/dist/vitest-diagnostics/vitest-file-progress-reporter.mjs +49 -0
- package/dist/vitest-diagnostics/vitest-github-actions-reporter.d.mts +13 -0
- package/dist/vitest-diagnostics/vitest-github-actions-reporter.mjs +35 -0
- package/dist/vitest-diagnostics/vitest-storybook-progress-reporter.d.mts +24 -0
- package/dist/vitest-diagnostics/vitest-storybook-progress-reporter.mjs +53 -0
- package/package.json +17 -1
- package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { readUntilAborted } from "./abort-listeners.mjs";
|
|
2
|
+
import { forceClientOption } from "./force-client-option.mjs";
|
|
3
|
+
import { toReplayResponse } from "./replay-response.mjs";
|
|
4
|
+
export function createProviderReplay(options = {}) {
|
|
5
|
+
const requests = [];
|
|
6
|
+
const queue = [];
|
|
7
|
+
// `new Request(...)` applies fetch semantics to the SDK's arguments: the effective URL, method,
|
|
8
|
+
// and headers (a form body brings its own `content-type`), the body bytes, and an abort signal
|
|
9
|
+
// that follows `init.signal`.
|
|
10
|
+
const replayRequest = async (request, url = request.url, headers = request.headers) => {
|
|
11
|
+
const { signal } = request;
|
|
12
|
+
signal.throwIfAborted();
|
|
13
|
+
// Reserve the request's position and its response before awaiting the body, so concurrent
|
|
14
|
+
// calls keep the order in which they started.
|
|
15
|
+
const sent = {
|
|
16
|
+
method: request.method,
|
|
17
|
+
url,
|
|
18
|
+
headers: Object.fromEntries(headers.entries()),
|
|
19
|
+
body: undefined,
|
|
20
|
+
json: () => JSON.parse(sent.body?.toString('utf8') ?? 'null'),
|
|
21
|
+
};
|
|
22
|
+
requests.push(sent);
|
|
23
|
+
const next = queue.shift();
|
|
24
|
+
if (!next) {
|
|
25
|
+
throw new Error(`Provider replay has no recorded response for request ${requests.length}: ${sent.method} ${sent.url}`);
|
|
26
|
+
}
|
|
27
|
+
const bytes = await readUntilAborted(request, signal);
|
|
28
|
+
sent.body = bytes.length === 0 ? undefined : bytes;
|
|
29
|
+
return toReplayResponse(next, options.chunkBytes, signal);
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
fetch: async (input, init) => replayRequest(new Request(input, init)),
|
|
33
|
+
sendHttpRequest: async (url, init) => replayRequest(new Request(url, init), url, new Headers(init?.headers)),
|
|
34
|
+
requests,
|
|
35
|
+
respondWith: (...responses) => void queue.push(...responses),
|
|
36
|
+
assertDrained: () => {
|
|
37
|
+
if (queue.length > 0) {
|
|
38
|
+
throw new Error(`Provider replay left ${queue.length} recorded response(s) unrequested`);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
reset: () => {
|
|
42
|
+
requests.length = 0;
|
|
43
|
+
queue.length = 0;
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Subclasses an SDK client so every instance sends through the replay, whatever `fetch` production
|
|
49
|
+
* code configured. Use it inside a `vi.mock` of the SDK package for a client that production builds
|
|
50
|
+
* itself, so the test never edits production code.
|
|
51
|
+
*/
|
|
52
|
+
export function replayClient(Constructor, replay) {
|
|
53
|
+
return forceClientOption(Constructor, 'fetch', replay.fetch);
|
|
54
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** A provider response as it arrived on the wire: status, headers and the raw body bytes. */
|
|
2
|
+
export type RecordedResponse = {
|
|
3
|
+
status: number;
|
|
4
|
+
statusText: string;
|
|
5
|
+
headers: Array<[name: string, value: string]>;
|
|
6
|
+
body: Buffer;
|
|
7
|
+
};
|
|
8
|
+
export type LoadRecordedResponseOptions = {
|
|
9
|
+
/** Directory (path or `file:` URL) that holds the raw `.http` fixtures. */
|
|
10
|
+
fixtureRoot: string | URL;
|
|
11
|
+
/** Literal tokens swapped in the whole file, for ids a test must keep unique. */
|
|
12
|
+
replace?: Record<string, string>;
|
|
13
|
+
};
|
|
14
|
+
/** Loads the raw `.http` fixture `<fixtureRoot>/<name>` and parses it. */
|
|
15
|
+
export declare function loadRecordedResponse(name: string, options: LoadRecordedResponseOptions): RecordedResponse;
|
|
16
|
+
/** Parses raw HTTP response text: a status line, headers, a blank line, then the body bytes. */
|
|
17
|
+
export declare function parseRecordedResponse(raw: Buffer): RecordedResponse;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
/** Headers describing the original transfer framing; the replay serves the decoded body instead. */
|
|
5
|
+
const FRAMING_HEADERS = new Set([
|
|
6
|
+
'connection',
|
|
7
|
+
'content-encoding',
|
|
8
|
+
'content-length',
|
|
9
|
+
'keep-alive',
|
|
10
|
+
'transfer-encoding',
|
|
11
|
+
]);
|
|
12
|
+
/** Loads the raw `.http` fixture `<fixtureRoot>/<name>` and parses it. */
|
|
13
|
+
export function loadRecordedResponse(name, options) {
|
|
14
|
+
const { fixtureRoot } = options;
|
|
15
|
+
const root = typeof fixtureRoot === 'string' ? fixtureRoot : fileURLToPath(fixtureRoot);
|
|
16
|
+
let raw = readFileSync(resolve(root, name)).toString('latin1');
|
|
17
|
+
for (const [token, value] of Object.entries(options.replace ?? {})) {
|
|
18
|
+
raw = raw.replaceAll(token, value);
|
|
19
|
+
}
|
|
20
|
+
return parseRecordedResponse(Buffer.from(raw, 'latin1'));
|
|
21
|
+
}
|
|
22
|
+
/** Parses raw HTTP response text: a status line, headers, a blank line, then the body bytes. */
|
|
23
|
+
export function parseRecordedResponse(raw) {
|
|
24
|
+
const crlf = raw.indexOf('\r\n\r\n');
|
|
25
|
+
const lf = raw.indexOf('\n\n');
|
|
26
|
+
const useCrlf = crlf !== -1 && (lf === -1 || crlf < lf);
|
|
27
|
+
const headEnd = useCrlf ? crlf : lf;
|
|
28
|
+
const head = headEnd === -1 ? raw : raw.subarray(0, headEnd);
|
|
29
|
+
const body = headEnd === -1 ? Buffer.alloc(0) : raw.subarray(headEnd + (useCrlf ? 4 : 2));
|
|
30
|
+
const [statusLine = '', ...headerLines] = head.toString('latin1').split(/\r?\n/);
|
|
31
|
+
const status = /^HTTP\/\S+ (\d{3})(?: (.*))?$/.exec(statusLine);
|
|
32
|
+
if (!status)
|
|
33
|
+
throw new Error(`Recorded response has no HTTP status line: ${statusLine}`);
|
|
34
|
+
const headers = headerLines.flatMap((line) => {
|
|
35
|
+
const colon = line.indexOf(':');
|
|
36
|
+
const name = line.slice(0, colon).trim().toLowerCase();
|
|
37
|
+
if (colon < 1 || FRAMING_HEADERS.has(name))
|
|
38
|
+
return [];
|
|
39
|
+
return [[name, line.slice(colon + 1).trim()]];
|
|
40
|
+
});
|
|
41
|
+
return { status: Number(status[1]), statusText: status[2] ?? '', headers, body };
|
|
42
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RecordedResponse } from './recorded-response.mts';
|
|
2
|
+
/**
|
|
3
|
+
* Builds the `Response` an SDK reads. The body streams in `chunkBytes` pieces (default: one), so a
|
|
4
|
+
* small value proves the consumer does not depend on events arriving aligned to chunk boundaries.
|
|
5
|
+
* When the request's `signal` aborts while the body is being read, the stream errors with the
|
|
6
|
+
* signal's reason, as a real transport does.
|
|
7
|
+
*/
|
|
8
|
+
export declare function toReplayResponse(recorded: RecordedResponse, chunkBytes?: number, signal?: AbortSignal | null): Response;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { onAbort } from "./abort-listeners.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Builds the `Response` an SDK reads. The body streams in `chunkBytes` pieces (default: one), so a
|
|
4
|
+
* small value proves the consumer does not depend on events arriving aligned to chunk boundaries.
|
|
5
|
+
* When the request's `signal` aborts while the body is being read, the stream errors with the
|
|
6
|
+
* signal's reason, as a real transport does.
|
|
7
|
+
*/
|
|
8
|
+
export function toReplayResponse(recorded, chunkBytes, signal) {
|
|
9
|
+
const size = chunkBytes ?? Math.max(recorded.body.length, 1);
|
|
10
|
+
if (!Number.isSafeInteger(size) || size < 1) {
|
|
11
|
+
throw new RangeError(`chunkBytes must be a positive integer, received ${chunkBytes}`);
|
|
12
|
+
}
|
|
13
|
+
let offset = 0;
|
|
14
|
+
let detach;
|
|
15
|
+
const body = recorded.body.length === 0
|
|
16
|
+
? null
|
|
17
|
+
: new ReadableStream({
|
|
18
|
+
start(controller) {
|
|
19
|
+
detach = onAbort(signal, () => controller.error(signal?.reason));
|
|
20
|
+
},
|
|
21
|
+
pull(controller) {
|
|
22
|
+
if (signal?.aborted)
|
|
23
|
+
return controller.error(signal.reason);
|
|
24
|
+
if (offset >= recorded.body.length) {
|
|
25
|
+
detach();
|
|
26
|
+
return controller.close();
|
|
27
|
+
}
|
|
28
|
+
controller.enqueue(recorded.body.subarray(offset, offset + size));
|
|
29
|
+
offset += size;
|
|
30
|
+
},
|
|
31
|
+
cancel: detach,
|
|
32
|
+
});
|
|
33
|
+
return new Response(body, {
|
|
34
|
+
status: recorded.status,
|
|
35
|
+
statusText: recorded.statusText,
|
|
36
|
+
headers: recorded.headers,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -20,6 +20,15 @@ export declare class EphemeralListenerAttemptsExhaustedError extends Error {
|
|
|
20
20
|
export declare const runnerPortPolicy: RunnerPortPolicy;
|
|
21
21
|
export declare function isRunnerReservedPort(port: number, policy?: RunnerPortPolicy): boolean;
|
|
22
22
|
export declare function listenOnRunnerUnreservedEphemeralPort(server: Server, host: string, options?: EphemeralListenerOptions): Promise<number>;
|
|
23
|
+
export type LoopbackHost = '::1' | '127.0.0.1';
|
|
24
|
+
/**
|
|
25
|
+
* Binds `server` to an unreserved ephemeral port on IPv6 loopback, falling back to IPv4
|
|
26
|
+
* loopback only when the host has no IPv6 support (EAFNOSUPPORT). Other errors are rethrown.
|
|
27
|
+
*/
|
|
28
|
+
export declare function listenOnLoopbackEphemeralPort(server: Server, options?: EphemeralListenerOptions): Promise<{
|
|
29
|
+
host: LoopbackHost;
|
|
30
|
+
port: number;
|
|
31
|
+
}>;
|
|
23
32
|
export declare function loadRunnerPortPolicy(policyUrl?: URL): RunnerPortPolicy;
|
|
24
33
|
export declare function validateRunnerPortPolicy(parsedPolicy: unknown, policyUrl?: URL): RunnerPortPolicy;
|
|
25
34
|
export {};
|
|
@@ -26,6 +26,38 @@ export async function listenOnRunnerUnreservedEphemeralPort(server, host, option
|
|
|
26
26
|
}
|
|
27
27
|
throw new EphemeralListenerAttemptsExhaustedError(maxBindAttempts);
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Binds `server` to an unreserved ephemeral port on IPv6 loopback, falling back to IPv4
|
|
31
|
+
* loopback only when the host has no IPv6 support (EAFNOSUPPORT). Other errors are rethrown.
|
|
32
|
+
*/
|
|
33
|
+
export async function listenOnLoopbackEphemeralPort(server, options = {}) {
|
|
34
|
+
const listen = options.listen ?? listenOnHost;
|
|
35
|
+
let ipv6Unsupported = false;
|
|
36
|
+
try {
|
|
37
|
+
const port = await listenOnRunnerUnreservedEphemeralPort(server, '::1', {
|
|
38
|
+
...options,
|
|
39
|
+
listen: async (target, host) => {
|
|
40
|
+
try {
|
|
41
|
+
await listen(target, host);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
ipv6Unsupported =
|
|
45
|
+
error instanceof Error && 'code' in error && error.code === 'EAFNOSUPPORT';
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
return { host: '::1', port };
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (!ipv6Unsupported)
|
|
54
|
+
throw error;
|
|
55
|
+
return {
|
|
56
|
+
host: '127.0.0.1',
|
|
57
|
+
port: await listenOnRunnerUnreservedEphemeralPort(server, '127.0.0.1', options),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
29
61
|
export function loadRunnerPortPolicy(policyUrl = shippedPolicyUrl) {
|
|
30
62
|
return validateRunnerPortPolicy(JSON.parse(readFileSync(policyUrl, 'utf8')), policyUrl);
|
|
31
63
|
}
|
|
@@ -18,3 +18,11 @@ export type { ForkLeakDiagnosticsOptions } from './vitest-fork-leak-diagnostics.
|
|
|
18
18
|
export type { ForkLeakDetector, ForkLeakDetectorOptions, ForkLeakVerdict, } from './vitest-fork-leak-detection.mts';
|
|
19
19
|
export { DEFAULT_MAX_DIAGNOSTIC_REPORTS, DEFAULT_MAX_FORMATTED_DIAGNOSTIC_REPORTS, formatDiagnosticReportSummaries, HARD_MAX_DIAGNOSTIC_REPORTS, MAX_DIAGNOSTIC_REPORT_BYTES, HARD_MAX_DIAGNOSTIC_DIRECTORY_ENTRIES, readDiagnosticReportSummaries, summarizeDiagnosticReport, } from './report-summary.mts';
|
|
20
20
|
export type { DiagnosticReportLimitOptions, DiagnosticReportSummary } from './report-summary.mts';
|
|
21
|
+
export { DEFAULT_CI_REPORTER_ENV_NAMES, ciOutputFile, ciReporters } from './vitest-ci-reporters.mts';
|
|
22
|
+
export type { CiReporterEnvNames, CiReportersOptions, VitestReporter, VitestReporters, } from './vitest-ci-reporters.mts';
|
|
23
|
+
export { githubActionsReporter, normalizeGithubActionsPath, } from './vitest-github-actions-reporter.mts';
|
|
24
|
+
export type { GithubActionsEnv, NormalizeGithubActionsPathOptions, } from './vitest-github-actions-reporter.mts';
|
|
25
|
+
export { DEFAULT_FILE_PROGRESS_PREFIX, createFileProgressWriter, createVitestFileProgressReporter, formatFileProgress, isFileProgressReporter, } from './vitest-file-progress-reporter.mts';
|
|
26
|
+
export type { FileProgressEvent, FileProgressReporterOptions, WriteProgress, } from './vitest-file-progress-reporter.mts';
|
|
27
|
+
export { DEFAULT_STORYBOOK_PROGRESS_PREFIX, createVitestStorybookProgressReporter, formatStorybookProgressMarker, latestStorybookProgressSequence, } from './vitest-storybook-progress-reporter.mts';
|
|
28
|
+
export type { StorybookProgressEvent, StorybookProgressReporterOptions, } from './vitest-storybook-progress-reporter.mts';
|
|
@@ -9,3 +9,7 @@ export { FORK_LEAK_HANDSHAKE_MAX_TURNS, FORK_LEAK_HANDSHAKE_STABLE_OBSERVATIONS,
|
|
|
9
9
|
export { countResourcesByType } from "./vitest-process-resources.mjs";
|
|
10
10
|
export { recordForkLeakCheckpoint } from "./vitest-fork-leak-handshake-samples.mjs";
|
|
11
11
|
export { DEFAULT_MAX_DIAGNOSTIC_REPORTS, DEFAULT_MAX_FORMATTED_DIAGNOSTIC_REPORTS, formatDiagnosticReportSummaries, HARD_MAX_DIAGNOSTIC_REPORTS, MAX_DIAGNOSTIC_REPORT_BYTES, HARD_MAX_DIAGNOSTIC_DIRECTORY_ENTRIES, readDiagnosticReportSummaries, summarizeDiagnosticReport, } from "./report-summary.mjs";
|
|
12
|
+
export { DEFAULT_CI_REPORTER_ENV_NAMES, ciOutputFile, ciReporters } from "./vitest-ci-reporters.mjs";
|
|
13
|
+
export { githubActionsReporter, normalizeGithubActionsPath, } from "./vitest-github-actions-reporter.mjs";
|
|
14
|
+
export { DEFAULT_FILE_PROGRESS_PREFIX, createFileProgressWriter, createVitestFileProgressReporter, formatFileProgress, isFileProgressReporter, } from "./vitest-file-progress-reporter.mjs";
|
|
15
|
+
export { DEFAULT_STORYBOOK_PROGRESS_PREFIX, createVitestStorybookProgressReporter, formatStorybookProgressMarker, latestStorybookProgressSequence, } from "./vitest-storybook-progress-reporter.mjs";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { InlineConfig } from 'vitest/node';
|
|
2
|
+
export type VitestReporters = NonNullable<InlineConfig['reporters']>;
|
|
3
|
+
export type VitestReporter = Extract<VitestReporters, readonly unknown[]>[number];
|
|
4
|
+
type VitestOutputFile = NonNullable<InlineConfig['outputFile']>;
|
|
5
|
+
type Env = Record<string, string | undefined>;
|
|
6
|
+
export interface CiReporterEnvNames {
|
|
7
|
+
/** Selects the reporter set: unset or empty for local, `run` for CI. */
|
|
8
|
+
reporters: string;
|
|
9
|
+
/** `1` streams file progress to stdout. */
|
|
10
|
+
diagnostics: string;
|
|
11
|
+
/** Path that buffers file progress when set. */
|
|
12
|
+
fileProgressFile: string;
|
|
13
|
+
/** `1` adds the Storybook progress reporter. */
|
|
14
|
+
storybookBrowser: string;
|
|
15
|
+
/** Path of the JUnit XML output file. */
|
|
16
|
+
junitOutputFile: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const DEFAULT_CI_REPORTER_ENV_NAMES: CiReporterEnvNames;
|
|
19
|
+
export interface CiReportersOptions {
|
|
20
|
+
/** Environment to read; defaults to `process.env`. */
|
|
21
|
+
env?: Env;
|
|
22
|
+
/** Override any of the env var names. */
|
|
23
|
+
envNames?: Partial<CiReporterEnvNames>;
|
|
24
|
+
/** Marker prefix for file progress lines. */
|
|
25
|
+
fileProgressPrefix?: string;
|
|
26
|
+
/** Marker prefix for Storybook progress lines. */
|
|
27
|
+
storybookProgressPrefix?: string;
|
|
28
|
+
/** Extra reporters inserted in `run` mode after `junit` (for example no-skips or teardown). */
|
|
29
|
+
extraReporters?: readonly VitestReporter[];
|
|
30
|
+
/** Working directory for the `github-actions` reporter's path normalization. */
|
|
31
|
+
cwd?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Builds the Vitest reporter list from env vars, or `undefined` for the default reporters.
|
|
35
|
+
* File progress streams to stdout when diagnostics are on and is appended to the progress file
|
|
36
|
+
* when set. Throws for an unknown reporter-set value.
|
|
37
|
+
*/
|
|
38
|
+
export declare function ciReporters(options?: CiReportersOptions): VitestReporters | undefined;
|
|
39
|
+
export declare function ciOutputFile(options?: CiReportersOptions): VitestOutputFile | undefined;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { githubActionsReporter } from "./vitest-github-actions-reporter.mjs";
|
|
2
|
+
import { createFileProgressWriter, createVitestFileProgressReporter, } from "./vitest-file-progress-reporter.mjs";
|
|
3
|
+
import { createVitestStorybookProgressReporter } from "./vitest-storybook-progress-reporter.mjs";
|
|
4
|
+
export const DEFAULT_CI_REPORTER_ENV_NAMES = {
|
|
5
|
+
reporters: 'VITEST_CI_REPORTERS',
|
|
6
|
+
diagnostics: 'VITEST_DIAGNOSTICS',
|
|
7
|
+
fileProgressFile: 'VITEST_FILE_PROGRESS_FILE',
|
|
8
|
+
storybookBrowser: 'VITEST_STORYBOOK_BROWSER',
|
|
9
|
+
junitOutputFile: 'VITEST_JUNIT_OUTPUT_FILE',
|
|
10
|
+
};
|
|
11
|
+
function resolveNames(options) {
|
|
12
|
+
return { ...DEFAULT_CI_REPORTER_ENV_NAMES, ...options.envNames };
|
|
13
|
+
}
|
|
14
|
+
function fileProgress(prefix, write) {
|
|
15
|
+
return createVitestFileProgressReporter({
|
|
16
|
+
...(write ? { write } : {}),
|
|
17
|
+
...(prefix ? { prefix } : {}),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function fileProgressReporters(env, names, prefix) {
|
|
21
|
+
const progressFile = env[names.fileProgressFile];
|
|
22
|
+
const toFile = progressFile ? createFileProgressWriter(progressFile) : undefined;
|
|
23
|
+
const toStdout = env[names.diagnostics] === '1';
|
|
24
|
+
if (!toFile && !toStdout)
|
|
25
|
+
return [];
|
|
26
|
+
if (!toFile)
|
|
27
|
+
return [fileProgress(prefix)];
|
|
28
|
+
if (!toStdout)
|
|
29
|
+
return [fileProgress(prefix, toFile)];
|
|
30
|
+
return [fileProgress(prefix), fileProgress(prefix, toFile)];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Builds the Vitest reporter list from env vars, or `undefined` for the default reporters.
|
|
34
|
+
* File progress streams to stdout when diagnostics are on and is appended to the progress file
|
|
35
|
+
* when set. Throws for an unknown reporter-set value.
|
|
36
|
+
*/
|
|
37
|
+
export function ciReporters(options = {}) {
|
|
38
|
+
const env = options.env ?? process.env;
|
|
39
|
+
const names = resolveNames(options);
|
|
40
|
+
const prefix = options.fileProgressPrefix;
|
|
41
|
+
const selected = env[names.reporters];
|
|
42
|
+
switch (selected) {
|
|
43
|
+
case undefined:
|
|
44
|
+
case '':
|
|
45
|
+
return env[names.diagnostics] === '1' ? ['default', fileProgress(prefix)] : undefined;
|
|
46
|
+
case 'run':
|
|
47
|
+
return [
|
|
48
|
+
'minimal',
|
|
49
|
+
...(env[names.storybookBrowser] === '1'
|
|
50
|
+
? [
|
|
51
|
+
createVitestStorybookProgressReporter(options.storybookProgressPrefix ? { prefix: options.storybookProgressPrefix } : {}),
|
|
52
|
+
]
|
|
53
|
+
: []),
|
|
54
|
+
githubActionsReporter({
|
|
55
|
+
env,
|
|
56
|
+
...(options.cwd ? { cwd: options.cwd } : {}),
|
|
57
|
+
}),
|
|
58
|
+
'junit',
|
|
59
|
+
...(options.extraReporters ?? []),
|
|
60
|
+
'hanging-process',
|
|
61
|
+
...fileProgressReporters(env, names, prefix),
|
|
62
|
+
];
|
|
63
|
+
default:
|
|
64
|
+
throw new Error(`Unknown ${names.reporters} value "${selected}". Accepted value: run.`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function ciOutputFile(options = {}) {
|
|
68
|
+
const junit = (options.env ?? process.env)[resolveNames(options).junitOutputFile];
|
|
69
|
+
return junit ? { junit } : undefined;
|
|
70
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Reporter, TestModule } from 'vitest/node';
|
|
2
|
+
export declare const DEFAULT_FILE_PROGRESS_PREFIX = "[vitest-file]";
|
|
3
|
+
export type FileProgressEvent = 'start' | 'finish';
|
|
4
|
+
export type WriteProgress = (chunk: string) => void;
|
|
5
|
+
type Clock = () => number;
|
|
6
|
+
export interface FileProgressReporterOptions {
|
|
7
|
+
write?: WriteProgress;
|
|
8
|
+
now?: Clock;
|
|
9
|
+
/** Marker prefix for each line. Defaults to `DEFAULT_FILE_PROGRESS_PREFIX`. */
|
|
10
|
+
prefix?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function formatFileProgress(event: FileProgressEvent, moduleId: string, state?: string, atMs?: number, prefix?: string): string;
|
|
13
|
+
declare class VitestFileProgressReporter implements Reporter {
|
|
14
|
+
private readonly write;
|
|
15
|
+
private readonly now;
|
|
16
|
+
private readonly prefix;
|
|
17
|
+
constructor(write: WriteProgress, now: Clock, prefix: string);
|
|
18
|
+
onTestModuleQueued(testModule: TestModule): void;
|
|
19
|
+
onTestModuleEnd(testModule: TestModule): void;
|
|
20
|
+
}
|
|
21
|
+
export declare function createFileProgressWriter(filePath: string): WriteProgress;
|
|
22
|
+
export declare function createVitestFileProgressReporter(options?: FileProgressReporterOptions): VitestFileProgressReporter;
|
|
23
|
+
export declare function isFileProgressReporter(reporter: unknown): reporter is VitestFileProgressReporter;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { appendFileSync, writeSync } from 'node:fs';
|
|
2
|
+
export const DEFAULT_FILE_PROGRESS_PREFIX = '[vitest-file]';
|
|
3
|
+
const MAX_MODULE_ID_CHARS = 400;
|
|
4
|
+
function moduleId(testModule) {
|
|
5
|
+
return testModule.relativeModuleId || testModule.moduleId;
|
|
6
|
+
}
|
|
7
|
+
export function formatFileProgress(event, moduleId, state, atMs, prefix = DEFAULT_FILE_PROGRESS_PREFIX) {
|
|
8
|
+
let boundedModuleId = moduleId.slice(0, MAX_MODULE_ID_CHARS);
|
|
9
|
+
if (boundedModuleId.length < moduleId.length) {
|
|
10
|
+
boundedModuleId = `${boundedModuleId.slice(0, -1)}…`;
|
|
11
|
+
}
|
|
12
|
+
const stateToken = state !== undefined && /^[a-z]+$/u.test(state) ? ` state=${state}` : '';
|
|
13
|
+
// Epoch milliseconds, so a deadline report can tell a slow file from a stuck one.
|
|
14
|
+
const atToken = atMs !== undefined && Number.isSafeInteger(atMs) ? ` at=${atMs}` : '';
|
|
15
|
+
return `${prefix} event=${event} module=${JSON.stringify(boundedModuleId)}${stateToken}${atToken}\n`;
|
|
16
|
+
}
|
|
17
|
+
class VitestFileProgressReporter {
|
|
18
|
+
write;
|
|
19
|
+
now;
|
|
20
|
+
prefix;
|
|
21
|
+
constructor(write, now, prefix) {
|
|
22
|
+
this.write = write;
|
|
23
|
+
this.now = now;
|
|
24
|
+
this.prefix = prefix;
|
|
25
|
+
}
|
|
26
|
+
onTestModuleQueued(testModule) {
|
|
27
|
+
// Queued fires when a worker takes the file, before import. A shard that dies
|
|
28
|
+
// during that file still has this line; the CI minimal reporter prints nothing.
|
|
29
|
+
this.write(formatFileProgress('start', moduleId(testModule), undefined, this.now(), this.prefix));
|
|
30
|
+
}
|
|
31
|
+
onTestModuleEnd(testModule) {
|
|
32
|
+
this.write(formatFileProgress('finish', moduleId(testModule), testModule.state(), this.now(), this.prefix));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function writeProgressLine(chunk) {
|
|
36
|
+
writeSync(process.stdout.fd, chunk);
|
|
37
|
+
}
|
|
38
|
+
// Appends each event to a file so a quiet CI run keeps its start/finish history without logging it.
|
|
39
|
+
export function createFileProgressWriter(filePath) {
|
|
40
|
+
return (chunk) => {
|
|
41
|
+
appendFileSync(filePath, chunk);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function createVitestFileProgressReporter(options = {}) {
|
|
45
|
+
return new VitestFileProgressReporter(options.write ?? writeProgressLine, options.now ?? Date.now, options.prefix ?? DEFAULT_FILE_PROGRESS_PREFIX);
|
|
46
|
+
}
|
|
47
|
+
export function isFileProgressReporter(reporter) {
|
|
48
|
+
return reporter instanceof VitestFileProgressReporter;
|
|
49
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface GithubActionsEnv {
|
|
2
|
+
GITHUB_WORKSPACE?: string | undefined;
|
|
3
|
+
GITHUB_REPOSITORY?: string | undefined;
|
|
4
|
+
GITHUB_SHA?: string | undefined;
|
|
5
|
+
}
|
|
6
|
+
export interface NormalizeGithubActionsPathOptions {
|
|
7
|
+
env?: GithubActionsEnv;
|
|
8
|
+
cwd?: string;
|
|
9
|
+
}
|
|
10
|
+
/** Rewrites an absolute path under the workspace or cwd to a repo-relative annotation path. */
|
|
11
|
+
export declare function normalizeGithubActionsPath(filePath: string, options?: NormalizeGithubActionsPathOptions): string;
|
|
12
|
+
/** The `github-actions` reporter tuple with path normalization and job-summary links wired. */
|
|
13
|
+
export declare function githubActionsReporter(options?: NormalizeGithubActionsPathOptions): readonly [string, Record<string, unknown>];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import path, { relative } from 'node:path';
|
|
2
|
+
/** Rewrites an absolute path under the workspace or cwd to a repo-relative annotation path. */
|
|
3
|
+
export function normalizeGithubActionsPath(filePath, options = {}) {
|
|
4
|
+
const env = options.env ?? process.env;
|
|
5
|
+
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
6
|
+
const roots = [env.GITHUB_WORKSPACE, options.cwd ?? process.cwd()].filter((root) => Boolean(root));
|
|
7
|
+
for (const root of roots) {
|
|
8
|
+
const normalizedRoot = root.replace(/\\/g, '/');
|
|
9
|
+
const relativePath = path.isAbsolute(normalizedPath)
|
|
10
|
+
? relative(normalizedRoot, normalizedPath)
|
|
11
|
+
: normalizedPath;
|
|
12
|
+
if (!relativePath.startsWith('..') && !path.isAbsolute(relativePath)) {
|
|
13
|
+
return relativePath.replace(/\\/g, '/');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return normalizedPath;
|
|
17
|
+
}
|
|
18
|
+
/** The `github-actions` reporter tuple with path normalization and job-summary links wired. */
|
|
19
|
+
export function githubActionsReporter(options = {}) {
|
|
20
|
+
const env = options.env ?? process.env;
|
|
21
|
+
return [
|
|
22
|
+
'github-actions',
|
|
23
|
+
{
|
|
24
|
+
onWritePath: (filePath) => normalizeGithubActionsPath(filePath, options),
|
|
25
|
+
jobSummary: {
|
|
26
|
+
enabled: false,
|
|
27
|
+
fileLinks: {
|
|
28
|
+
repository: env.GITHUB_REPOSITORY,
|
|
29
|
+
commitHash: env.GITHUB_SHA,
|
|
30
|
+
workspacePath: env.GITHUB_WORKSPACE,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Reporter, TestModule } from 'vitest/node';
|
|
2
|
+
export declare const DEFAULT_STORYBOOK_PROGRESS_PREFIX = "[vitest-browser-progress]";
|
|
3
|
+
export type StorybookProgressEvent = 'module-collected' | 'module-start' | 'module-end';
|
|
4
|
+
type WriteProgress = (chunk: string) => void;
|
|
5
|
+
export interface StorybookProgressReporterOptions {
|
|
6
|
+
write?: WriteProgress;
|
|
7
|
+
/** Marker prefix for each line. Defaults to `DEFAULT_STORYBOOK_PROGRESS_PREFIX`. */
|
|
8
|
+
prefix?: string;
|
|
9
|
+
}
|
|
10
|
+
declare class VitestStorybookProgressReporter implements Reporter {
|
|
11
|
+
private sequence;
|
|
12
|
+
private readonly write;
|
|
13
|
+
private readonly prefix;
|
|
14
|
+
constructor(write: WriteProgress, prefix: string);
|
|
15
|
+
onTestRunStart(): void;
|
|
16
|
+
onTestModuleCollected(testModule: TestModule): void;
|
|
17
|
+
onTestModuleStart(testModule: TestModule): void;
|
|
18
|
+
onTestModuleEnd(testModule: TestModule): void;
|
|
19
|
+
private emit;
|
|
20
|
+
}
|
|
21
|
+
export declare function createVitestStorybookProgressReporter(options?: StorybookProgressReporterOptions): VitestStorybookProgressReporter;
|
|
22
|
+
export declare function formatStorybookProgressMarker(sequence: number, event: StorybookProgressEvent, moduleId: string, prefix?: string): string;
|
|
23
|
+
export declare function latestStorybookProgressSequence(text: string, prefix?: string): number | null;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export const DEFAULT_STORYBOOK_PROGRESS_PREFIX = '[vitest-browser-progress]';
|
|
2
|
+
const MAX_MARKER_BYTES = 512;
|
|
3
|
+
const MAX_MODULE_ID_CHARS = 400;
|
|
4
|
+
class VitestStorybookProgressReporter {
|
|
5
|
+
sequence = 0;
|
|
6
|
+
write;
|
|
7
|
+
prefix;
|
|
8
|
+
constructor(write, prefix) {
|
|
9
|
+
this.write = write;
|
|
10
|
+
this.prefix = prefix;
|
|
11
|
+
}
|
|
12
|
+
onTestRunStart() {
|
|
13
|
+
this.sequence = 0;
|
|
14
|
+
}
|
|
15
|
+
onTestModuleCollected(testModule) {
|
|
16
|
+
this.emit('module-collected', testModule);
|
|
17
|
+
}
|
|
18
|
+
onTestModuleStart(testModule) {
|
|
19
|
+
this.emit('module-start', testModule);
|
|
20
|
+
}
|
|
21
|
+
onTestModuleEnd(testModule) {
|
|
22
|
+
this.emit('module-end', testModule);
|
|
23
|
+
}
|
|
24
|
+
emit(event, testModule) {
|
|
25
|
+
this.sequence += 1;
|
|
26
|
+
this.write(formatStorybookProgressMarker(this.sequence, event, testModule.relativeModuleId || testModule.moduleId, this.prefix));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function createVitestStorybookProgressReporter(options = {}) {
|
|
30
|
+
return new VitestStorybookProgressReporter(options.write ?? ((chunk) => process.stdout.write(chunk)), options.prefix ?? DEFAULT_STORYBOOK_PROGRESS_PREFIX);
|
|
31
|
+
}
|
|
32
|
+
export function formatStorybookProgressMarker(sequence, event, moduleId, prefix = DEFAULT_STORYBOOK_PROGRESS_PREFIX) {
|
|
33
|
+
let boundedModuleId = moduleId.slice(0, MAX_MODULE_ID_CHARS);
|
|
34
|
+
while (boundedModuleId.length > 0) {
|
|
35
|
+
const suffix = boundedModuleId.length < moduleId.length ? '…' : '';
|
|
36
|
+
const marker = `${prefix} seq=${sequence} event=${event} module=${JSON.stringify(`${boundedModuleId}${suffix}`)}\n`;
|
|
37
|
+
if (Buffer.byteLength(marker) <= MAX_MARKER_BYTES)
|
|
38
|
+
return marker;
|
|
39
|
+
boundedModuleId = boundedModuleId.slice(0, -16);
|
|
40
|
+
}
|
|
41
|
+
return `${prefix} seq=${sequence} event=${event} module=""\n`;
|
|
42
|
+
}
|
|
43
|
+
export function latestStorybookProgressSequence(text, prefix = DEFAULT_STORYBOOK_PROGRESS_PREFIX) {
|
|
44
|
+
const escaped = prefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
45
|
+
const pattern = new RegExp(`${escaped} seq=(\\d+) event=module-(?:collected|start|end)\\b`, 'g');
|
|
46
|
+
let latest = null;
|
|
47
|
+
for (const match of text.matchAll(pattern)) {
|
|
48
|
+
const sequence = Number(match[1]);
|
|
49
|
+
if (Number.isSafeInteger(sequence))
|
|
50
|
+
latest = Math.max(latest ?? 0, sequence);
|
|
51
|
+
}
|
|
52
|
+
return latest;
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vouchington-tooling",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.0",
|
|
4
4
|
"description": "Vouchington CLI and extractable tooling libraries.",
|
|
5
5
|
"homepage": "https://github.com/vouchington/vouchington-tooling/tree/main/packages/vouchington-tooling#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -261,6 +261,11 @@
|
|
|
261
261
|
"import": "./dist/gha-check-run/index.mjs",
|
|
262
262
|
"default": "./dist/gha-check-run/index.mjs"
|
|
263
263
|
},
|
|
264
|
+
"./provider-replay": {
|
|
265
|
+
"types": "./dist/provider-replay/index.d.mts",
|
|
266
|
+
"import": "./dist/provider-replay/index.mjs",
|
|
267
|
+
"default": "./dist/provider-replay/index.mjs"
|
|
268
|
+
},
|
|
264
269
|
"./http-link-pagination": {
|
|
265
270
|
"types": "./dist/http-link-pagination/index.d.mts",
|
|
266
271
|
"import": "./dist/http-link-pagination/index.mjs",
|
|
@@ -401,6 +406,11 @@
|
|
|
401
406
|
"import": "./dist/gh-api-shell-quoting/index.mjs",
|
|
402
407
|
"default": "./dist/gh-api-shell-quoting/index.mjs"
|
|
403
408
|
},
|
|
409
|
+
"./postgres-test-faults": {
|
|
410
|
+
"types": "./dist/postgres-test-faults/index.d.mts",
|
|
411
|
+
"import": "./dist/postgres-test-faults/index.mjs",
|
|
412
|
+
"default": "./dist/postgres-test-faults/index.mjs"
|
|
413
|
+
},
|
|
404
414
|
"./package.json": "./package.json",
|
|
405
415
|
"./basic-auth-doc-sync": {
|
|
406
416
|
"types": "./dist/basic-auth-doc-sync/index.d.mts",
|
|
@@ -465,12 +475,14 @@
|
|
|
465
475
|
"@ast-grep/cli": "0.50.0",
|
|
466
476
|
"@modelcontextprotocol/sdk": "1.32.1",
|
|
467
477
|
"@playwright/test": "1.64.1",
|
|
478
|
+
"@types/pg": "8.23.1",
|
|
468
479
|
"@types/picomatch": "^4.0.3",
|
|
469
480
|
"@types/react": "19.3.0",
|
|
470
481
|
"@types/react-dom": "19.3.0",
|
|
471
482
|
"@types/spdx-expression-parse": "4.0.0",
|
|
472
483
|
"next": "16.4.2",
|
|
473
484
|
"no-mistakes": "0.83.0",
|
|
485
|
+
"pg": "8.23.1",
|
|
474
486
|
"react": "19.3.1",
|
|
475
487
|
"react-dom": "19.3.1",
|
|
476
488
|
"smol-toml": "1.9.1",
|
|
@@ -481,6 +493,7 @@
|
|
|
481
493
|
"@playwright/test": ">=1.64.1",
|
|
482
494
|
"next": ">=15",
|
|
483
495
|
"no-mistakes": "*",
|
|
496
|
+
"pg": ">=8",
|
|
484
497
|
"react": ">=18",
|
|
485
498
|
"typescript": ">=5",
|
|
486
499
|
"vitest": ">=5"
|
|
@@ -498,6 +511,9 @@
|
|
|
498
511
|
"no-mistakes": {
|
|
499
512
|
"optional": true
|
|
500
513
|
},
|
|
514
|
+
"pg": {
|
|
515
|
+
"optional": true
|
|
516
|
+
},
|
|
501
517
|
"react": {
|
|
502
518
|
"optional": true
|
|
503
519
|
},
|
|
Binary file
|