-
-
Notifications
You must be signed in to change notification settings - Fork 268
/
index.ts
51 lines (47 loc) · 1.04 KB
/
index.ts
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 {
parseTestArgs,
PromiseWithSubtest,
Stdin,
StdinOpts,
TapPlugin,
TestBase,
} from '@tapjs/core'
export type PromiseWithStdin = PromiseWithSubtest<Stdin>
/* c8 ignore start */
const stdinCB = () => {
throw new Error('this should not be called')
}
/* c8 ignore stop */
export class StdinPlugin {
#t: TestBase
constructor(t: TestBase) {
this.#t = t
}
/**
* Parse standard input as a child test
*
* @group Subtest Methods
*/
stdin(): PromiseWithStdin
stdin(name: string): PromiseWithStdin
stdin(name: string, extra: StdinOpts): PromiseWithStdin
stdin(extra: StdinOpts): PromiseWithStdin
stdin(
name?: string | StdinOpts,
extra?: StdinOpts
): PromiseWithStdin {
if (name && typeof name === 'object') {
extra = name
name = undefined
}
name ??= '/dev/stdin'
extra ??= {}
return this.#t.sub(
Stdin,
parseTestArgs<Stdin>(name, extra, stdinCB),
this.#t.t.stdin
)
}
}
export const plugin: TapPlugin<StdinPlugin> = (t: TestBase) =>
new StdinPlugin(t)