-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctx-features.test.ts
More file actions
51 lines (44 loc) · 1.45 KB
/
ctx-features.test.ts
File metadata and controls
51 lines (44 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { describe, it } from "bun:test"
import { retry, run, signal, timeout, wrap } from "../index"
const typecheckOnly = (): boolean => false
describe("context feature typing", () => {
it("does not expose ctx.retry without retry()", () => {
if (typecheckOnly()) {
run((ctx) => {
// @ts-expect-error retry metadata is only available after retry()
void ctx.retry.attempt
return 1
})
}
})
it("does not expose ctx.retry for timeout/signal/wrap alone", () => {
if (typecheckOnly()) {
timeout(100).run((ctx) => {
// @ts-expect-error retry metadata is only available after retry()
void ctx.retry.attempt
return 1
})
signal(new AbortController().signal).run((ctx) => {
// @ts-expect-error retry metadata is only available after retry()
void ctx.retry.attempt
return 1
})
wrap(() => null).run((ctx) => {
// @ts-expect-error retry metadata is only available after retry()
void ctx.retry.attempt
return 1
})
}
})
it("exposes ctx.retry after retry() for run and runAsync", () => {
retry(3).run((ctx) => ctx.retry.attempt)
void retry(3).runAsync((ctx) => Promise.resolve(ctx.retry.limit))
})
it("preserves retry ctx feature across chained options", () => {
retry(3)
.timeout(100)
.signal(new AbortController().signal)
.wrap(() => null)
.run((ctx) => ctx.retry.attempt)
})
})