req-race 0.2.0 → 1.1.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/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/bin/req-race.js +87 -31
- package/config.schema.json +16 -0
- package/dist/browser/req-race.global.js +1 -0
- package/dist/cjs/browser.cjs +843 -0
- package/dist/cjs/cypress.cjs +618 -0
- package/dist/cjs/index.cjs +1064 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/playwright.cjs +257 -0
- package/dist/cjs/puppeteer.cjs +257 -0
- package/dist/esm/browser.js +813 -0
- package/dist/esm/cypress.js +591 -0
- package/dist/esm/index.js +1002 -0
- package/dist/esm/playwright.js +221 -0
- package/dist/esm/puppeteer.js +221 -0
- package/dist/types/browser.d.cts +9 -0
- package/dist/types/browser.d.ts +9 -0
- package/dist/types/chaos.d.cts +25 -0
- package/dist/types/chaos.d.ts +25 -0
- package/dist/types/config.d.cts +3 -0
- package/dist/types/config.d.ts +3 -0
- package/dist/types/cypress.d.cts +1 -0
- package/dist/types/cypress.d.ts +1 -0
- package/dist/types/index.d.cts +7 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/playwright.d.cts +82 -0
- package/dist/types/playwright.d.ts +82 -0
- package/dist/types/prng.d.cts +1 -0
- package/dist/types/prng.d.ts +1 -0
- package/dist/types/puppeteer.d.cts +2 -0
- package/dist/types/puppeteer.d.ts +2 -0
- package/dist/types/reporters.d.cts +33 -0
- package/dist/types/reporters.d.ts +33 -0
- package/dist/types/safe-fetch.d.cts +24 -0
- package/dist/types/safe-fetch.d.ts +24 -0
- package/dist/types/types.d.cts +215 -0
- package/dist/types/types.d.ts +215 -0
- package/package.json +87 -13
- package/src/index.d.ts +0 -54
- package/src/index.js +0 -322
- package/src/playwright.d.ts +0 -22
- package/src/playwright.js +0 -79
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type RaceChaosOptions } from "./types.js";
|
|
2
|
+
export interface PlaywrightPageLike {
|
|
3
|
+
route: (url: string | RegExp, handler: (route: unknown) => Promise<void>) => Promise<void>;
|
|
4
|
+
unroute: (url: string | RegExp, handler: (route: unknown) => Promise<void>) => Promise<void>;
|
|
5
|
+
waitForTimeout: (ms: number) => Promise<void>;
|
|
6
|
+
locator: (selector: string) => {
|
|
7
|
+
first: () => {
|
|
8
|
+
click: (opts?: {
|
|
9
|
+
force?: boolean;
|
|
10
|
+
}) => Promise<void>;
|
|
11
|
+
textContent: () => Promise<string | null>;
|
|
12
|
+
isVisible: () => Promise<boolean>;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
on: (event: string, fn: (...args: unknown[]) => void) => void;
|
|
16
|
+
off: (event: string, fn: (...args: unknown[]) => void) => void;
|
|
17
|
+
evaluate: <T, A = unknown>(fn: (arg: A) => T, arg?: A) => Promise<T>;
|
|
18
|
+
}
|
|
19
|
+
export declare function assertNoStaleRace(page: PlaywrightPageLike, options: {
|
|
20
|
+
url: string | RegExp;
|
|
21
|
+
trigger: () => Promise<void>;
|
|
22
|
+
selector: string;
|
|
23
|
+
expectedText: string;
|
|
24
|
+
delayMs?: number;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
export declare function assertNoDoubleSubmit(page: PlaywrightPageLike, options: {
|
|
27
|
+
button: string;
|
|
28
|
+
url: string | RegExp;
|
|
29
|
+
maxRequests?: number;
|
|
30
|
+
windowMs?: number;
|
|
31
|
+
}): Promise<{
|
|
32
|
+
mutationCount: number;
|
|
33
|
+
}>;
|
|
34
|
+
export declare function assertNoLoadingHang(page: PlaywrightPageLike, options: {
|
|
35
|
+
url: string | RegExp;
|
|
36
|
+
trigger: () => Promise<void>;
|
|
37
|
+
loadingSelector: string;
|
|
38
|
+
timeoutMs?: number;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
export declare function assertHandlesServerError(page: PlaywrightPageLike, options: {
|
|
41
|
+
url: string | RegExp;
|
|
42
|
+
trigger: () => Promise<void>;
|
|
43
|
+
errorSelector: string;
|
|
44
|
+
status?: number;
|
|
45
|
+
expectNoSuccessSelector?: string;
|
|
46
|
+
}): Promise<void>;
|
|
47
|
+
export declare function assertHandlesOffline(page: PlaywrightPageLike, options: {
|
|
48
|
+
url: string | RegExp;
|
|
49
|
+
trigger: () => Promise<void>;
|
|
50
|
+
errorSelector: string;
|
|
51
|
+
}): Promise<void>;
|
|
52
|
+
export declare function assertNoRetryStorm(page: PlaywrightPageLike, options: {
|
|
53
|
+
url: string | RegExp;
|
|
54
|
+
trigger: () => Promise<void>;
|
|
55
|
+
maxRequests: number;
|
|
56
|
+
windowMs?: number;
|
|
57
|
+
status?: number;
|
|
58
|
+
}): Promise<{
|
|
59
|
+
count: number;
|
|
60
|
+
}>;
|
|
61
|
+
export declare function assertNoStaleAfterNavigation(page: PlaywrightPageLike, options: {
|
|
62
|
+
url: string | RegExp;
|
|
63
|
+
trigger: () => Promise<void>;
|
|
64
|
+
navigateTo: () => Promise<void>;
|
|
65
|
+
forbiddenSelector: string;
|
|
66
|
+
delayMs?: number;
|
|
67
|
+
}): Promise<void>;
|
|
68
|
+
export declare function assertNoUnhandledRejections(page: PlaywrightPageLike, options: {
|
|
69
|
+
trigger: () => Promise<void>;
|
|
70
|
+
windowMs?: number;
|
|
71
|
+
}): Promise<void>;
|
|
72
|
+
export declare function assertNoOutOfOrderSequence(page: PlaywrightPageLike, options: {
|
|
73
|
+
url: string | RegExp;
|
|
74
|
+
trigger: () => Promise<void>;
|
|
75
|
+
selector: string;
|
|
76
|
+
expectedFinalText: string;
|
|
77
|
+
delayMs?: number;
|
|
78
|
+
}): Promise<void>;
|
|
79
|
+
export declare function withChaos(page: PlaywrightPageLike, options?: RaceChaosOptions): Promise<{
|
|
80
|
+
stats: unknown;
|
|
81
|
+
dispose: () => Promise<void>;
|
|
82
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createSeededRandom(seed?: number | string): () => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createSeededRandom(seed?: number | string): () => number;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { assertNoStaleRace, assertNoDoubleSubmit, assertNoLoadingHang, assertHandlesServerError, assertHandlesOffline, assertNoRetryStorm, assertNoStaleAfterNavigation, assertNoUnhandledRejections, assertNoOutOfOrderSequence, withChaos, } from "./playwright.cjs";
|
|
2
|
+
export type { PlaywrightPageLike as PuppeteerPageLike } from "./playwright.cjs";
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { assertNoStaleRace, assertNoDoubleSubmit, assertNoLoadingHang, assertHandlesServerError, assertHandlesOffline, assertNoRetryStorm, assertNoStaleAfterNavigation, assertNoUnhandledRejections, assertNoOutOfOrderSequence, withChaos, } from "./playwright.js";
|
|
2
|
+
export type { PlaywrightPageLike as PuppeteerPageLike } from "./playwright.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { RaceLogEntry, RaceStats } from "./types.cjs";
|
|
2
|
+
export declare function formatRaceReport(stats: RaceStats, options?: {
|
|
3
|
+
color?: boolean;
|
|
4
|
+
verbose?: boolean;
|
|
5
|
+
logs?: RaceLogEntry[];
|
|
6
|
+
}): string;
|
|
7
|
+
export declare function toJson(stats: RaceStats, logs?: RaceLogEntry[]): {
|
|
8
|
+
version: string;
|
|
9
|
+
seed: string | number;
|
|
10
|
+
stats: RaceStats;
|
|
11
|
+
logs: RaceLogEntry[];
|
|
12
|
+
};
|
|
13
|
+
export declare function toMarkdown(stats: RaceStats, logs?: RaceLogEntry[]): string;
|
|
14
|
+
export declare function toJUnit(stats: RaceStats, _logs?: RaceLogEntry[]): string;
|
|
15
|
+
export declare function toSarif(stats: RaceStats, _logs?: RaceLogEntry[]): {
|
|
16
|
+
$schema: string;
|
|
17
|
+
version: string;
|
|
18
|
+
runs: {
|
|
19
|
+
tool: {
|
|
20
|
+
driver: {
|
|
21
|
+
name: string;
|
|
22
|
+
version: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
results: {
|
|
26
|
+
ruleId: string;
|
|
27
|
+
level: string;
|
|
28
|
+
message: {
|
|
29
|
+
text: string;
|
|
30
|
+
};
|
|
31
|
+
}[];
|
|
32
|
+
}[];
|
|
33
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { RaceLogEntry, RaceStats } from "./types.js";
|
|
2
|
+
export declare function formatRaceReport(stats: RaceStats, options?: {
|
|
3
|
+
color?: boolean;
|
|
4
|
+
verbose?: boolean;
|
|
5
|
+
logs?: RaceLogEntry[];
|
|
6
|
+
}): string;
|
|
7
|
+
export declare function toJson(stats: RaceStats, logs?: RaceLogEntry[]): {
|
|
8
|
+
version: string;
|
|
9
|
+
seed: string | number;
|
|
10
|
+
stats: RaceStats;
|
|
11
|
+
logs: RaceLogEntry[];
|
|
12
|
+
};
|
|
13
|
+
export declare function toMarkdown(stats: RaceStats, logs?: RaceLogEntry[]): string;
|
|
14
|
+
export declare function toJUnit(stats: RaceStats, _logs?: RaceLogEntry[]): string;
|
|
15
|
+
export declare function toSarif(stats: RaceStats, _logs?: RaceLogEntry[]): {
|
|
16
|
+
$schema: string;
|
|
17
|
+
version: string;
|
|
18
|
+
runs: {
|
|
19
|
+
tool: {
|
|
20
|
+
driver: {
|
|
21
|
+
name: string;
|
|
22
|
+
version: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
results: {
|
|
26
|
+
ruleId: string;
|
|
27
|
+
level: string;
|
|
28
|
+
message: {
|
|
29
|
+
text: string;
|
|
30
|
+
};
|
|
31
|
+
}[];
|
|
32
|
+
}[];
|
|
33
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type RaceSafeFetchOptions } from "./types.cjs";
|
|
2
|
+
export declare function createRaceSafeFetch(fetchImpl?: typeof fetch, optionsOrNormalizeKey?: ((url: string, method: string) => string) | RaceSafeFetchOptions): typeof fetch;
|
|
3
|
+
export declare function createLatestGuard(): {
|
|
4
|
+
next(): {
|
|
5
|
+
id: number;
|
|
6
|
+
signal: AbortSignal;
|
|
7
|
+
isLatest: () => boolean;
|
|
8
|
+
};
|
|
9
|
+
run<T>(fn: (signal: AbortSignal) => Promise<T>): Promise<{
|
|
10
|
+
stale: boolean;
|
|
11
|
+
value?: T;
|
|
12
|
+
}>;
|
|
13
|
+
reset(): void;
|
|
14
|
+
};
|
|
15
|
+
export declare function createLatestOnly<T extends (...args: never[]) => Promise<unknown>>(fn: T, options?: {
|
|
16
|
+
onSuperseded?: "reject" | "resolve-undefined";
|
|
17
|
+
}): T & {
|
|
18
|
+
cancel: () => void;
|
|
19
|
+
};
|
|
20
|
+
export declare function createMutationLock<T extends (...args: never[]) => Promise<unknown>>(fn: T, options?: {
|
|
21
|
+
mode?: "ignore" | "share" | "queue";
|
|
22
|
+
}): T & {
|
|
23
|
+
isPending: () => boolean;
|
|
24
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type RaceSafeFetchOptions } from "./types.js";
|
|
2
|
+
export declare function createRaceSafeFetch(fetchImpl?: typeof fetch, optionsOrNormalizeKey?: ((url: string, method: string) => string) | RaceSafeFetchOptions): typeof fetch;
|
|
3
|
+
export declare function createLatestGuard(): {
|
|
4
|
+
next(): {
|
|
5
|
+
id: number;
|
|
6
|
+
signal: AbortSignal;
|
|
7
|
+
isLatest: () => boolean;
|
|
8
|
+
};
|
|
9
|
+
run<T>(fn: (signal: AbortSignal) => Promise<T>): Promise<{
|
|
10
|
+
stale: boolean;
|
|
11
|
+
value?: T;
|
|
12
|
+
}>;
|
|
13
|
+
reset(): void;
|
|
14
|
+
};
|
|
15
|
+
export declare function createLatestOnly<T extends (...args: never[]) => Promise<unknown>>(fn: T, options?: {
|
|
16
|
+
onSuperseded?: "reject" | "resolve-undefined";
|
|
17
|
+
}): T & {
|
|
18
|
+
cancel: () => void;
|
|
19
|
+
};
|
|
20
|
+
export declare function createMutationLock<T extends (...args: never[]) => Promise<unknown>>(fn: T, options?: {
|
|
21
|
+
mode?: "ignore" | "share" | "queue";
|
|
22
|
+
}): T & {
|
|
23
|
+
isPending: () => boolean;
|
|
24
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
export type ChaosMode = "reverse-order" | "jitter" | "throttle-mutations" | "timeout" | "slow" | "flaky" | "error-status" | "rate-limit" | "offline" | "hang" | "abort-mid-body" | "shuffle" | "custom";
|
|
2
|
+
export declare class SupersededError extends Error {
|
|
3
|
+
readonly code = "ERR_SUPERSEDED";
|
|
4
|
+
readonly reason = "superseded";
|
|
5
|
+
constructor(message?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class TimeoutError extends Error {
|
|
8
|
+
readonly code = "ETIMEDOUT";
|
|
9
|
+
constructor(message?: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class RaceAssertionError extends Error {
|
|
12
|
+
readonly code = "ERR_RACE_ASSERTION";
|
|
13
|
+
constructor(message: string, options?: {
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export declare class AlreadyEnabledError extends Error {
|
|
18
|
+
readonly code = "ALREADY_ENABLED";
|
|
19
|
+
constructor(message?: string);
|
|
20
|
+
}
|
|
21
|
+
export declare class ChaosCallbackError extends Error {
|
|
22
|
+
readonly code = "ERR_CHAOS_CALLBACK";
|
|
23
|
+
constructor(message: string, options?: {
|
|
24
|
+
cause?: unknown;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export declare class UnknownModeError extends Error {
|
|
28
|
+
readonly code = "ERR_UNKNOWN_MODE";
|
|
29
|
+
constructor(mode: string);
|
|
30
|
+
}
|
|
31
|
+
export declare function isSupersededError(err: unknown): boolean;
|
|
32
|
+
export declare function isTimeoutError(err: unknown): boolean;
|
|
33
|
+
export interface Clock {
|
|
34
|
+
now: () => number;
|
|
35
|
+
setTimeout: (fn: () => void, ms: number) => ReturnType<typeof setTimeout>;
|
|
36
|
+
clearTimeout: (id: ReturnType<typeof setTimeout>) => void;
|
|
37
|
+
}
|
|
38
|
+
export interface KeyStats {
|
|
39
|
+
requests: number;
|
|
40
|
+
reordered: number;
|
|
41
|
+
unabortedStale: number;
|
|
42
|
+
}
|
|
43
|
+
export interface RaceStats {
|
|
44
|
+
totalRequests: number;
|
|
45
|
+
reorderedResponses: number;
|
|
46
|
+
abortedCount: number;
|
|
47
|
+
unabortedStaleCount: number;
|
|
48
|
+
duplicateMutations: number;
|
|
49
|
+
timeouts: number;
|
|
50
|
+
failedRequests: number;
|
|
51
|
+
injectedErrors: number;
|
|
52
|
+
rateLimited: number;
|
|
53
|
+
hungRequests: number;
|
|
54
|
+
partialBodies: number;
|
|
55
|
+
retriedCount: number;
|
|
56
|
+
deduplicatedCount: number;
|
|
57
|
+
maxConcurrentPerKey: Record<string, number>;
|
|
58
|
+
byKey: Record<string, KeyStats>;
|
|
59
|
+
seed: number | string;
|
|
60
|
+
}
|
|
61
|
+
export interface RaceLogEntry {
|
|
62
|
+
id: number;
|
|
63
|
+
key: string;
|
|
64
|
+
method: string;
|
|
65
|
+
url: string;
|
|
66
|
+
startedAt: number;
|
|
67
|
+
endedAt: number | null;
|
|
68
|
+
delayApplied: number;
|
|
69
|
+
action: string;
|
|
70
|
+
status: number | null;
|
|
71
|
+
aborted: boolean;
|
|
72
|
+
reordered: boolean;
|
|
73
|
+
staleRisk: boolean;
|
|
74
|
+
error?: string;
|
|
75
|
+
mode: string;
|
|
76
|
+
}
|
|
77
|
+
export interface RaceEvent {
|
|
78
|
+
type: "stale-response" | "unaborted-stale" | "duplicate-mutation" | "timeout" | "hang" | "rate-limited";
|
|
79
|
+
key: string;
|
|
80
|
+
method: string;
|
|
81
|
+
url: string;
|
|
82
|
+
requestId: number;
|
|
83
|
+
supersededBy?: number;
|
|
84
|
+
detail: string;
|
|
85
|
+
}
|
|
86
|
+
export type CustomChaosDecision = undefined | {
|
|
87
|
+
delayMs: number;
|
|
88
|
+
} | {
|
|
89
|
+
fail: "network" | "timeout" | "abort";
|
|
90
|
+
} | {
|
|
91
|
+
respond: {
|
|
92
|
+
status: number;
|
|
93
|
+
headers?: Record<string, string>;
|
|
94
|
+
body?: string;
|
|
95
|
+
};
|
|
96
|
+
} | {
|
|
97
|
+
hang: true;
|
|
98
|
+
};
|
|
99
|
+
export interface ChaosRequestInfo {
|
|
100
|
+
method: string;
|
|
101
|
+
url: string;
|
|
102
|
+
key: string;
|
|
103
|
+
headers: Record<string, string>;
|
|
104
|
+
attempt: number;
|
|
105
|
+
index: number;
|
|
106
|
+
indexForKey: number;
|
|
107
|
+
signal?: AbortSignal;
|
|
108
|
+
}
|
|
109
|
+
export interface ChaosRule {
|
|
110
|
+
urlPattern?: RegExp | string | ((url: string) => boolean);
|
|
111
|
+
methods?: string[];
|
|
112
|
+
mode: ChaosMode | ChaosMode[];
|
|
113
|
+
delayMs?: number;
|
|
114
|
+
timeoutMs?: number;
|
|
115
|
+
minDelayMs?: number;
|
|
116
|
+
maxDelayMs?: number;
|
|
117
|
+
errorRate?: number;
|
|
118
|
+
status?: number;
|
|
119
|
+
statusText?: string;
|
|
120
|
+
body?: string;
|
|
121
|
+
headers?: Record<string, string>;
|
|
122
|
+
}
|
|
123
|
+
export interface RaceChaosOptions {
|
|
124
|
+
target?: {
|
|
125
|
+
fetch: typeof fetch;
|
|
126
|
+
};
|
|
127
|
+
mode?: ChaosMode | ChaosMode[];
|
|
128
|
+
rules?: ChaosRule[];
|
|
129
|
+
delayMs?: number;
|
|
130
|
+
timeoutMs?: number;
|
|
131
|
+
minDelayMs?: number;
|
|
132
|
+
maxDelayMs?: number;
|
|
133
|
+
doubleSubmitWindowMs?: number;
|
|
134
|
+
errorRate?: number;
|
|
135
|
+
status?: number;
|
|
136
|
+
statusText?: string;
|
|
137
|
+
body?: string;
|
|
138
|
+
headers?: Record<string, string>;
|
|
139
|
+
rateLimitAfter?: number;
|
|
140
|
+
rateLimitWindowMs?: number;
|
|
141
|
+
retryAfterSeconds?: number;
|
|
142
|
+
partialBytes?: number;
|
|
143
|
+
shuffleWindowMs?: number;
|
|
144
|
+
seed?: number | string;
|
|
145
|
+
urlPattern?: RegExp | string | ((url: string) => boolean) | null;
|
|
146
|
+
methods?: string[];
|
|
147
|
+
normalizeKey?: (url: string, method: string) => string;
|
|
148
|
+
patchXhr?: boolean;
|
|
149
|
+
patchBeacon?: boolean;
|
|
150
|
+
maxLogs?: number;
|
|
151
|
+
clock?: Clock;
|
|
152
|
+
chaos?: (req: ChaosRequestInfo, ctx: {
|
|
153
|
+
random: () => number;
|
|
154
|
+
now: () => number;
|
|
155
|
+
}) => CustomChaosDecision | Promise<CustomChaosDecision>;
|
|
156
|
+
onRaceDetected?: (event: RaceEvent) => void;
|
|
157
|
+
onRequest?: (entry: RaceLogEntry) => void;
|
|
158
|
+
onResponse?: (entry: RaceLogEntry) => void;
|
|
159
|
+
}
|
|
160
|
+
export interface RaceChaosController {
|
|
161
|
+
disable: () => void;
|
|
162
|
+
getStats: () => RaceStats;
|
|
163
|
+
getLogs: () => RaceLogEntry[];
|
|
164
|
+
resetStats: () => void;
|
|
165
|
+
setOffline: (offline: boolean) => void;
|
|
166
|
+
setMode: (mode: ChaosMode | ChaosMode[]) => void;
|
|
167
|
+
getSeed: () => number | string;
|
|
168
|
+
isEnabled: () => boolean;
|
|
169
|
+
}
|
|
170
|
+
export interface RaceSafeFetchOptions {
|
|
171
|
+
normalizeKey?: (url: string, method: string) => string;
|
|
172
|
+
keyBy?: (url: string, method: string) => string;
|
|
173
|
+
supersedeMethods?: string[];
|
|
174
|
+
dedupeMutations?: boolean;
|
|
175
|
+
dedupeWindowMs?: number;
|
|
176
|
+
idempotencyKey?: boolean | ((url: string, method: string) => string);
|
|
177
|
+
timeoutMs?: number;
|
|
178
|
+
totalTimeoutMs?: number;
|
|
179
|
+
retries?: number;
|
|
180
|
+
retryMethods?: string[];
|
|
181
|
+
retryOn?: (resOrErr: Response | Error, attempt: number) => boolean;
|
|
182
|
+
retryDelayMs?: number;
|
|
183
|
+
retryBackoff?: number;
|
|
184
|
+
maxRetryDelayMs?: number;
|
|
185
|
+
retryJitter?: boolean | number;
|
|
186
|
+
respectRetryAfter?: boolean;
|
|
187
|
+
onAbort?: (info: {
|
|
188
|
+
key: string;
|
|
189
|
+
url: string;
|
|
190
|
+
method: string;
|
|
191
|
+
}) => void;
|
|
192
|
+
onRetry?: (info: {
|
|
193
|
+
key: string;
|
|
194
|
+
attempt: number;
|
|
195
|
+
delayMs: number;
|
|
196
|
+
}) => void;
|
|
197
|
+
onDedupe?: (info: {
|
|
198
|
+
key: string;
|
|
199
|
+
url: string;
|
|
200
|
+
}) => void;
|
|
201
|
+
onTimeout?: (info: {
|
|
202
|
+
key: string;
|
|
203
|
+
timeoutMs: number;
|
|
204
|
+
}) => void;
|
|
205
|
+
}
|
|
206
|
+
export interface ReqRaceConfig {
|
|
207
|
+
urls?: string[];
|
|
208
|
+
mode?: ChaosMode | ChaosMode[];
|
|
209
|
+
delay?: number;
|
|
210
|
+
timeout?: number;
|
|
211
|
+
wait?: number;
|
|
212
|
+
seed?: number | string;
|
|
213
|
+
failOn?: string[];
|
|
214
|
+
format?: "text" | "json" | "sarif" | "junit" | "markdown" | "github";
|
|
215
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
export type ChaosMode = "reverse-order" | "jitter" | "throttle-mutations" | "timeout" | "slow" | "flaky" | "error-status" | "rate-limit" | "offline" | "hang" | "abort-mid-body" | "shuffle" | "custom";
|
|
2
|
+
export declare class SupersededError extends Error {
|
|
3
|
+
readonly code = "ERR_SUPERSEDED";
|
|
4
|
+
readonly reason = "superseded";
|
|
5
|
+
constructor(message?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class TimeoutError extends Error {
|
|
8
|
+
readonly code = "ETIMEDOUT";
|
|
9
|
+
constructor(message?: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class RaceAssertionError extends Error {
|
|
12
|
+
readonly code = "ERR_RACE_ASSERTION";
|
|
13
|
+
constructor(message: string, options?: {
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export declare class AlreadyEnabledError extends Error {
|
|
18
|
+
readonly code = "ALREADY_ENABLED";
|
|
19
|
+
constructor(message?: string);
|
|
20
|
+
}
|
|
21
|
+
export declare class ChaosCallbackError extends Error {
|
|
22
|
+
readonly code = "ERR_CHAOS_CALLBACK";
|
|
23
|
+
constructor(message: string, options?: {
|
|
24
|
+
cause?: unknown;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export declare class UnknownModeError extends Error {
|
|
28
|
+
readonly code = "ERR_UNKNOWN_MODE";
|
|
29
|
+
constructor(mode: string);
|
|
30
|
+
}
|
|
31
|
+
export declare function isSupersededError(err: unknown): boolean;
|
|
32
|
+
export declare function isTimeoutError(err: unknown): boolean;
|
|
33
|
+
export interface Clock {
|
|
34
|
+
now: () => number;
|
|
35
|
+
setTimeout: (fn: () => void, ms: number) => ReturnType<typeof setTimeout>;
|
|
36
|
+
clearTimeout: (id: ReturnType<typeof setTimeout>) => void;
|
|
37
|
+
}
|
|
38
|
+
export interface KeyStats {
|
|
39
|
+
requests: number;
|
|
40
|
+
reordered: number;
|
|
41
|
+
unabortedStale: number;
|
|
42
|
+
}
|
|
43
|
+
export interface RaceStats {
|
|
44
|
+
totalRequests: number;
|
|
45
|
+
reorderedResponses: number;
|
|
46
|
+
abortedCount: number;
|
|
47
|
+
unabortedStaleCount: number;
|
|
48
|
+
duplicateMutations: number;
|
|
49
|
+
timeouts: number;
|
|
50
|
+
failedRequests: number;
|
|
51
|
+
injectedErrors: number;
|
|
52
|
+
rateLimited: number;
|
|
53
|
+
hungRequests: number;
|
|
54
|
+
partialBodies: number;
|
|
55
|
+
retriedCount: number;
|
|
56
|
+
deduplicatedCount: number;
|
|
57
|
+
maxConcurrentPerKey: Record<string, number>;
|
|
58
|
+
byKey: Record<string, KeyStats>;
|
|
59
|
+
seed: number | string;
|
|
60
|
+
}
|
|
61
|
+
export interface RaceLogEntry {
|
|
62
|
+
id: number;
|
|
63
|
+
key: string;
|
|
64
|
+
method: string;
|
|
65
|
+
url: string;
|
|
66
|
+
startedAt: number;
|
|
67
|
+
endedAt: number | null;
|
|
68
|
+
delayApplied: number;
|
|
69
|
+
action: string;
|
|
70
|
+
status: number | null;
|
|
71
|
+
aborted: boolean;
|
|
72
|
+
reordered: boolean;
|
|
73
|
+
staleRisk: boolean;
|
|
74
|
+
error?: string;
|
|
75
|
+
mode: string;
|
|
76
|
+
}
|
|
77
|
+
export interface RaceEvent {
|
|
78
|
+
type: "stale-response" | "unaborted-stale" | "duplicate-mutation" | "timeout" | "hang" | "rate-limited";
|
|
79
|
+
key: string;
|
|
80
|
+
method: string;
|
|
81
|
+
url: string;
|
|
82
|
+
requestId: number;
|
|
83
|
+
supersededBy?: number;
|
|
84
|
+
detail: string;
|
|
85
|
+
}
|
|
86
|
+
export type CustomChaosDecision = undefined | {
|
|
87
|
+
delayMs: number;
|
|
88
|
+
} | {
|
|
89
|
+
fail: "network" | "timeout" | "abort";
|
|
90
|
+
} | {
|
|
91
|
+
respond: {
|
|
92
|
+
status: number;
|
|
93
|
+
headers?: Record<string, string>;
|
|
94
|
+
body?: string;
|
|
95
|
+
};
|
|
96
|
+
} | {
|
|
97
|
+
hang: true;
|
|
98
|
+
};
|
|
99
|
+
export interface ChaosRequestInfo {
|
|
100
|
+
method: string;
|
|
101
|
+
url: string;
|
|
102
|
+
key: string;
|
|
103
|
+
headers: Record<string, string>;
|
|
104
|
+
attempt: number;
|
|
105
|
+
index: number;
|
|
106
|
+
indexForKey: number;
|
|
107
|
+
signal?: AbortSignal;
|
|
108
|
+
}
|
|
109
|
+
export interface ChaosRule {
|
|
110
|
+
urlPattern?: RegExp | string | ((url: string) => boolean);
|
|
111
|
+
methods?: string[];
|
|
112
|
+
mode: ChaosMode | ChaosMode[];
|
|
113
|
+
delayMs?: number;
|
|
114
|
+
timeoutMs?: number;
|
|
115
|
+
minDelayMs?: number;
|
|
116
|
+
maxDelayMs?: number;
|
|
117
|
+
errorRate?: number;
|
|
118
|
+
status?: number;
|
|
119
|
+
statusText?: string;
|
|
120
|
+
body?: string;
|
|
121
|
+
headers?: Record<string, string>;
|
|
122
|
+
}
|
|
123
|
+
export interface RaceChaosOptions {
|
|
124
|
+
target?: {
|
|
125
|
+
fetch: typeof fetch;
|
|
126
|
+
};
|
|
127
|
+
mode?: ChaosMode | ChaosMode[];
|
|
128
|
+
rules?: ChaosRule[];
|
|
129
|
+
delayMs?: number;
|
|
130
|
+
timeoutMs?: number;
|
|
131
|
+
minDelayMs?: number;
|
|
132
|
+
maxDelayMs?: number;
|
|
133
|
+
doubleSubmitWindowMs?: number;
|
|
134
|
+
errorRate?: number;
|
|
135
|
+
status?: number;
|
|
136
|
+
statusText?: string;
|
|
137
|
+
body?: string;
|
|
138
|
+
headers?: Record<string, string>;
|
|
139
|
+
rateLimitAfter?: number;
|
|
140
|
+
rateLimitWindowMs?: number;
|
|
141
|
+
retryAfterSeconds?: number;
|
|
142
|
+
partialBytes?: number;
|
|
143
|
+
shuffleWindowMs?: number;
|
|
144
|
+
seed?: number | string;
|
|
145
|
+
urlPattern?: RegExp | string | ((url: string) => boolean) | null;
|
|
146
|
+
methods?: string[];
|
|
147
|
+
normalizeKey?: (url: string, method: string) => string;
|
|
148
|
+
patchXhr?: boolean;
|
|
149
|
+
patchBeacon?: boolean;
|
|
150
|
+
maxLogs?: number;
|
|
151
|
+
clock?: Clock;
|
|
152
|
+
chaos?: (req: ChaosRequestInfo, ctx: {
|
|
153
|
+
random: () => number;
|
|
154
|
+
now: () => number;
|
|
155
|
+
}) => CustomChaosDecision | Promise<CustomChaosDecision>;
|
|
156
|
+
onRaceDetected?: (event: RaceEvent) => void;
|
|
157
|
+
onRequest?: (entry: RaceLogEntry) => void;
|
|
158
|
+
onResponse?: (entry: RaceLogEntry) => void;
|
|
159
|
+
}
|
|
160
|
+
export interface RaceChaosController {
|
|
161
|
+
disable: () => void;
|
|
162
|
+
getStats: () => RaceStats;
|
|
163
|
+
getLogs: () => RaceLogEntry[];
|
|
164
|
+
resetStats: () => void;
|
|
165
|
+
setOffline: (offline: boolean) => void;
|
|
166
|
+
setMode: (mode: ChaosMode | ChaosMode[]) => void;
|
|
167
|
+
getSeed: () => number | string;
|
|
168
|
+
isEnabled: () => boolean;
|
|
169
|
+
}
|
|
170
|
+
export interface RaceSafeFetchOptions {
|
|
171
|
+
normalizeKey?: (url: string, method: string) => string;
|
|
172
|
+
keyBy?: (url: string, method: string) => string;
|
|
173
|
+
supersedeMethods?: string[];
|
|
174
|
+
dedupeMutations?: boolean;
|
|
175
|
+
dedupeWindowMs?: number;
|
|
176
|
+
idempotencyKey?: boolean | ((url: string, method: string) => string);
|
|
177
|
+
timeoutMs?: number;
|
|
178
|
+
totalTimeoutMs?: number;
|
|
179
|
+
retries?: number;
|
|
180
|
+
retryMethods?: string[];
|
|
181
|
+
retryOn?: (resOrErr: Response | Error, attempt: number) => boolean;
|
|
182
|
+
retryDelayMs?: number;
|
|
183
|
+
retryBackoff?: number;
|
|
184
|
+
maxRetryDelayMs?: number;
|
|
185
|
+
retryJitter?: boolean | number;
|
|
186
|
+
respectRetryAfter?: boolean;
|
|
187
|
+
onAbort?: (info: {
|
|
188
|
+
key: string;
|
|
189
|
+
url: string;
|
|
190
|
+
method: string;
|
|
191
|
+
}) => void;
|
|
192
|
+
onRetry?: (info: {
|
|
193
|
+
key: string;
|
|
194
|
+
attempt: number;
|
|
195
|
+
delayMs: number;
|
|
196
|
+
}) => void;
|
|
197
|
+
onDedupe?: (info: {
|
|
198
|
+
key: string;
|
|
199
|
+
url: string;
|
|
200
|
+
}) => void;
|
|
201
|
+
onTimeout?: (info: {
|
|
202
|
+
key: string;
|
|
203
|
+
timeoutMs: number;
|
|
204
|
+
}) => void;
|
|
205
|
+
}
|
|
206
|
+
export interface ReqRaceConfig {
|
|
207
|
+
urls?: string[];
|
|
208
|
+
mode?: ChaosMode | ChaosMode[];
|
|
209
|
+
delay?: number;
|
|
210
|
+
timeout?: number;
|
|
211
|
+
wait?: number;
|
|
212
|
+
seed?: number | string;
|
|
213
|
+
failOn?: string[];
|
|
214
|
+
format?: "text" | "json" | "sarif" | "junit" | "markdown" | "github";
|
|
215
|
+
}
|