@zukhruf/testing 0.8.25 → 0.8.27
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 +39 -2
- package/dist/async/index.d.ts +1 -1
- package/dist/async/index.d.ts.map +1 -1
- package/dist/async/index.js +1 -1
- package/dist/async/index.js.map +1 -1
- package/dist/async/wait-for.d.ts +15 -0
- package/dist/async/wait-for.d.ts.map +1 -0
- package/dist/async/wait-for.js +34 -0
- package/dist/async/wait-for.js.map +1 -0
- package/dist/process/index.d.ts +2 -0
- package/dist/process/index.d.ts.map +1 -0
- package/dist/process/index.js +2 -0
- package/dist/process/index.js.map +1 -0
- package/dist/process/worker-process.d.ts +45 -0
- package/dist/process/worker-process.d.ts.map +1 -0
- package/dist/process/worker-process.js +84 -0
- package/dist/process/worker-process.js.map +1 -0
- package/package.json +10 -4
- package/dist/async/settle-within.d.ts +0 -2
- package/dist/async/settle-within.d.ts.map +0 -1
- package/dist/async/settle-within.js +0 -11
- package/dist/async/settle-within.js.map +0 -1
package/README.md
CHANGED
|
@@ -11,7 +11,8 @@ Each area has its own import path, so a test loads only the drivers it uses. The
|
|
|
11
11
|
| Import | Gives | Needs |
|
|
12
12
|
| ----------------------------- | ------------------------------------------------------ | ------------------------ |
|
|
13
13
|
| `@zukhruf/testing/node` | Native `test`, `it`, `suite`, `describe` with `.each` | |
|
|
14
|
-
| `@zukhruf/testing/async` | `
|
|
14
|
+
| `@zukhruf/testing/async` | `waitFor`, `timebox` | |
|
|
15
|
+
| `@zukhruf/testing/process` | `startWorker` | |
|
|
15
16
|
| `@zukhruf/testing/docker` | `DockerTestbed`, `ServiceContainer`, `DockerDirectory` | a Docker engine |
|
|
16
17
|
| `@zukhruf/testing/postgres` | `Postgres` | a Docker engine |
|
|
17
18
|
| `@zukhruf/testing/mysql` | `Mysql` | a Docker engine |
|
|
@@ -222,7 +223,43 @@ The handler is a Node.js request listener. A web framework gives one for its fet
|
|
|
222
223
|
|
|
223
224
|
## Waiting
|
|
224
225
|
|
|
225
|
-
`
|
|
226
|
+
`waitFor(check, { signal, interval })` calls `check` until it returns without an error, and resolves with its value. `check` can be async. The signal is the limit of the wait: pass `t.signal`, so the test's own timeout ends it, and the test has no number of its own. When the signal aborts, also during a check, the wait stops its timer and rejects with `signal.reason`, with the last error of `check` as its `cause`. The interval is 50 ms by default. The waits run on real time, so a test that moves a fake clock does not move them, and the check can read that clock's timers.
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
await waitFor(() => assert.equal(clock.countTimers(), 1), { signal: t.signal });
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Wait for an event when one exists; `waitFor` is for a fact that only a read shows. Precedent: vitest `vi.waitFor` and Testing Library `waitFor` also retry while the check throws, and keep its last error. They take a timeout; `waitFor` takes a signal. Node's `t.waitFor` takes no signal.
|
|
233
|
+
|
|
234
|
+
A wait for an event in a test is `untilAborted(promise, t.signal)` of `@zukhruf/async`, and an operation that accepts an `AbortSignal` gets `t.signal`. A test sets no number of its own. `AbortSignal.timeout(ms)` sets one, and `zukhruf/no-own-wait-limit` of `@zukhruf/eslint` reports it in a test, as it reports `t.waitFor`. `t.signal` aborts only when the runner has a test limit, so a direct `node --test` run needs `--test-timeout=<ms>` (the nx test target sets 300000). Then a hung wait ends.
|
|
235
|
+
|
|
236
|
+
`timebox(fn, options)` retries `fn` until it stops throwing, every 250 ms for at most 30 seconds by default. It takes every p-retry option.
|
|
237
|
+
|
|
238
|
+
## Worker processes
|
|
239
|
+
|
|
240
|
+
`startWorker(source, name, { admit, nodeOptions })` runs `source` as an ES module in its own Node process, with `name` as `argv[1]` and an IPC channel back to the test. Disposal kills the worker. The worker also exits when the test process ends, even by SIGKILL, because it reads the end of its stdin. `admit` runs with the child before it can send anything, for example to join it to a coordinator.
|
|
241
|
+
|
|
242
|
+
The handle records each message whose `type` is a string, in `messages`, and the worker's stderr, in `stderr`. `exit` is how the worker exited, `closed` resolves when it closed. `has(type)` and `find(type)` read the messages so far.
|
|
243
|
+
|
|
244
|
+
`next(match, { signal })` resolves with the first message that `match` selects, sent before or after the call. It rejects with the worker's stderr when the worker closes first, and with `signal.reason` when the signal aborts. `match` is a type, or a predicate over the message. The predicate sees each message once, in the order the worker sent it, and none after it selected one, so it can count:
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
await worker.next('ready', { signal: t.signal });
|
|
248
|
+
await worker.next(
|
|
249
|
+
(message) => message.type === 'leader' || message.type === 'follower',
|
|
250
|
+
{ signal: t.signal },
|
|
251
|
+
);
|
|
252
|
+
await worker.next(
|
|
253
|
+
(message) => message.type === 'answer' && message.call === 2,
|
|
254
|
+
{ signal: t.signal },
|
|
255
|
+
);
|
|
256
|
+
let roles = 0;
|
|
257
|
+
await worker.next((message) => message.type === 'role' && ++roles === 2, {
|
|
258
|
+
signal: t.signal,
|
|
259
|
+
});
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Precedent: Playwright's `waitForEvent(event, predicate)` and Node's `events.once(emitter, name, { signal })`.
|
|
226
263
|
|
|
227
264
|
## Temporary directories
|
|
228
265
|
|
package/dist/async/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/async/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/async/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,KAAK,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/async/index.js
CHANGED
package/dist/async/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/async/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/async/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAuB,OAAO,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface WaitForOptions {
|
|
2
|
+
/** The limit of the wait, for example `t.signal`. The wait rejects with its reason. */
|
|
3
|
+
signal: AbortSignal;
|
|
4
|
+
/** Milliseconds between the end of a failed check and the next check. 50 by default. */
|
|
5
|
+
interval?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Calls `check` until it returns without an error, and resolves with its
|
|
9
|
+
* value. When `signal` aborts, also during a check, the wait stops its timer
|
|
10
|
+
* and rejects with `signal.reason`, with the last error of `check` as its
|
|
11
|
+
* `cause`. The waits run on real time, so a test that moves a fake clock does
|
|
12
|
+
* not move them.
|
|
13
|
+
*/
|
|
14
|
+
export declare function waitFor<T>(check: () => T | PromiseLike<T>, { signal, interval }: WaitForOptions): Promise<T>;
|
|
15
|
+
//# sourceMappingURL=wait-for.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wait-for.d.ts","sourceRoot":"","sources":["../../src/async/wait-for.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,uFAAuF;IACvF,MAAM,EAAE,WAAW,CAAC;IACpB,wFAAwF;IACxF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,KAAK,EAAE,MAAM,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,EAC/B,EAAE,MAAM,EAAE,QAAa,EAAE,EAAE,cAAc,GACxC,OAAO,CAAC,CAAC,CAAC,CA0BZ"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { poll, untilAborted } from '@zukhruf/async';
|
|
2
|
+
/**
|
|
3
|
+
* Calls `check` until it returns without an error, and resolves with its
|
|
4
|
+
* value. When `signal` aborts, also during a check, the wait stops its timer
|
|
5
|
+
* and rejects with `signal.reason`, with the last error of `check` as its
|
|
6
|
+
* `cause`. The waits run on real time, so a test that moves a fake clock does
|
|
7
|
+
* not move them.
|
|
8
|
+
*/
|
|
9
|
+
export async function waitFor(check, { signal, interval = 50 }) {
|
|
10
|
+
let failure;
|
|
11
|
+
try {
|
|
12
|
+
const passed = await poll(async () => {
|
|
13
|
+
try {
|
|
14
|
+
return { value: await untilAborted(Promise.try(check), signal) };
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (signal.aborted)
|
|
18
|
+
throw error;
|
|
19
|
+
failure = { error };
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}, { interval, signal, clock: globalThis });
|
|
23
|
+
return passed.value;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (failure !== undefined &&
|
|
27
|
+
error === signal.reason &&
|
|
28
|
+
typeof error === 'object' &&
|
|
29
|
+
error !== null)
|
|
30
|
+
Object.assign(error, { cause: failure.error });
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=wait-for.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wait-for.js","sourceRoot":"","sources":["../../src/async/wait-for.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AASpD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,KAA+B,EAC/B,EAAE,MAAM,EAAE,QAAQ,GAAG,EAAE,EAAkB;IAEzC,IAAI,OAAuC,CAAC;IAC5C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,IAAI,CACvB,KAAK,IAAI,EAAE;YACT,IAAI,CAAC;gBACH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC;YACnE,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,MAAM,CAAC,OAAO;oBAAE,MAAM,KAAK,CAAC;gBAChC,OAAO,GAAG,EAAE,KAAK,EAAE,CAAC;gBACpB,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC,EACD,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,CACxC,CAAC;QACF,OAAO,MAAM,CAAC,KAAK,CAAC;IACtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IACE,OAAO,KAAK,SAAS;YACrB,KAAK,KAAK,MAAM,CAAC,MAAM;YACvB,OAAO,KAAK,KAAK,QAAQ;YACzB,KAAK,KAAK,IAAI;YAEd,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QACjD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/process/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,WAAW,GACZ,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/process/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,GACZ,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type ChildProcess } from 'node:child_process';
|
|
2
|
+
export interface WorkerMessage {
|
|
3
|
+
type: string;
|
|
4
|
+
[field: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
/** Selects a message: its `type`, or a predicate over the whole message. */
|
|
7
|
+
export type MessageMatch = string | ((message: WorkerMessage) => boolean);
|
|
8
|
+
export interface WorkerProcess extends AsyncDisposable {
|
|
9
|
+
readonly child: ChildProcess;
|
|
10
|
+
/** Resolves when the child exited and closed its pipes. */
|
|
11
|
+
readonly closed: Promise<void>;
|
|
12
|
+
/** Each message the child sent, in order. */
|
|
13
|
+
readonly messages: WorkerMessage[];
|
|
14
|
+
/** The child's stderr, each chunk prefixed with the worker's name. */
|
|
15
|
+
stderr: string;
|
|
16
|
+
/** How the child exited, or `null` while it runs. */
|
|
17
|
+
exit: {
|
|
18
|
+
code: number | null;
|
|
19
|
+
signal: NodeJS.Signals | null;
|
|
20
|
+
} | null;
|
|
21
|
+
has(type: string): boolean;
|
|
22
|
+
find(type: string): WorkerMessage | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* The first message that `match` selects, sent before or after the call.
|
|
25
|
+
* A predicate sees each message once, in the order the child sent it, so it
|
|
26
|
+
* can count. Rejects with the child's stderr when the child closes first,
|
|
27
|
+
* and with the reason of `signal` when it aborts.
|
|
28
|
+
*/
|
|
29
|
+
next(match: MessageMatch, options: {
|
|
30
|
+
signal: AbortSignal;
|
|
31
|
+
}): Promise<WorkerMessage>;
|
|
32
|
+
}
|
|
33
|
+
export interface WorkerOptions {
|
|
34
|
+
/** Runs with the child before it can send anything, for example to join it to a coordinator. */
|
|
35
|
+
admit?: (child: ChildProcess) => void;
|
|
36
|
+
/** Node flags before `--eval`. */
|
|
37
|
+
nodeOptions?: string[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Runs `source` as an ES module in its own Node process, with `name` as
|
|
41
|
+
* argv[1] and an IPC channel back to this process. Disposing kills it, and
|
|
42
|
+
* the child exits when this process ends.
|
|
43
|
+
*/
|
|
44
|
+
export declare function startWorker(source: string, name: string, { admit, nodeOptions }?: WorkerOptions): WorkerProcess;
|
|
45
|
+
//# sourceMappingURL=worker-process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-process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ACzB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,EAAE,KAAK,EAAE,WAAgB,EAAE,GAAE,aAAkB,GAC9C,aAAa,CAwEf"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { untilAborted } from '@zukhruf/async';
|
|
3
|
+
const isWorkerMessage = (message) => typeof message === 'object' &&
|
|
4
|
+
message !== null &&
|
|
5
|
+
'type' in message &&
|
|
6
|
+
typeof message.type === 'string';
|
|
7
|
+
/**
|
|
8
|
+
* Ends the child when this process ends, even by SIGKILL: the OS closes the
|
|
9
|
+
* write end of the child's stdin, and the child reads its end. A `disconnect`
|
|
10
|
+
* listener on the IPC channel would keep each child alive until its parent
|
|
11
|
+
* ends, and an unref of the channel would let a child exit while it waits for
|
|
12
|
+
* a message of the parent. The unref stdin keeps nothing alive. ESM hoists the
|
|
13
|
+
* imports of `source` above it.
|
|
14
|
+
*/
|
|
15
|
+
const exitWithParent = "process.stdin.once('end', () => process.exit(1)).resume().unref();\n";
|
|
16
|
+
/**
|
|
17
|
+
* Runs `source` as an ES module in its own Node process, with `name` as
|
|
18
|
+
* argv[1] and an IPC channel back to this process. Disposing kills it, and
|
|
19
|
+
* the child exits when this process ends.
|
|
20
|
+
*/
|
|
21
|
+
export function startWorker(source, name, { admit, nodeOptions = [] } = {}) {
|
|
22
|
+
const child = spawn(process.execPath, [
|
|
23
|
+
...nodeOptions,
|
|
24
|
+
'--input-type=module',
|
|
25
|
+
'--eval',
|
|
26
|
+
exitWithParent + source,
|
|
27
|
+
name,
|
|
28
|
+
], { stdio: ['pipe', 'ignore', 'pipe', 'ipc'] });
|
|
29
|
+
admit?.(child);
|
|
30
|
+
const closed = Promise.withResolvers();
|
|
31
|
+
const worker = {
|
|
32
|
+
child,
|
|
33
|
+
closed: closed.promise,
|
|
34
|
+
messages: [],
|
|
35
|
+
stderr: '',
|
|
36
|
+
exit: null,
|
|
37
|
+
has(type) {
|
|
38
|
+
return worker.messages.some((message) => message.type === type);
|
|
39
|
+
},
|
|
40
|
+
find(type) {
|
|
41
|
+
return worker.messages.find((message) => message.type === type);
|
|
42
|
+
},
|
|
43
|
+
next(match, { signal }) {
|
|
44
|
+
const selects = typeof match === 'string'
|
|
45
|
+
? (message) => message.type === match
|
|
46
|
+
: match;
|
|
47
|
+
const arrived = worker.messages.find(selects);
|
|
48
|
+
if (arrived)
|
|
49
|
+
return Promise.resolve(arrived);
|
|
50
|
+
const message = Promise.withResolvers();
|
|
51
|
+
const onMessage = (sent) => {
|
|
52
|
+
if (!isWorkerMessage(sent) || !selects(sent))
|
|
53
|
+
return;
|
|
54
|
+
child.off('message', onMessage);
|
|
55
|
+
message.resolve(sent);
|
|
56
|
+
};
|
|
57
|
+
child.on('message', onMessage);
|
|
58
|
+
void closed.promise.then(() => message.reject(new Error(`${name} closed with ${JSON.stringify(worker.exit)} before it sent ${typeof match === 'string' ? `'${match}'` : 'a selected message'}.\n${worker.stderr}`)));
|
|
59
|
+
return untilAborted(message.promise, signal).finally(() => child.off('message', onMessage));
|
|
60
|
+
},
|
|
61
|
+
async [Symbol.asyncDispose]() {
|
|
62
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
63
|
+
child.kill('SIGKILL');
|
|
64
|
+
await closed.promise;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
child.stderr?.setEncoding('utf8');
|
|
68
|
+
child.stderr?.on('data', (chunk) => {
|
|
69
|
+
worker.stderr += `${name}: ${chunk}`;
|
|
70
|
+
});
|
|
71
|
+
child.once('error', (error) => {
|
|
72
|
+
worker.stderr += `${name}: ${error.message}\n`;
|
|
73
|
+
});
|
|
74
|
+
child.once('close', (code, signal) => {
|
|
75
|
+
worker.exit = { code, signal };
|
|
76
|
+
closed.resolve();
|
|
77
|
+
});
|
|
78
|
+
child.on('message', (message) => {
|
|
79
|
+
if (isWorkerMessage(message))
|
|
80
|
+
worker.messages.push(message);
|
|
81
|
+
});
|
|
82
|
+
return worker;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=worker-process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-process.js","sourceRoot":"","sources":["../../src/process/worker-process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAyC9C,MAAM,eAAe,GAAG,CAAC,OAAgB,EAA4B,EAAE,CACrE,OAAO,OAAO,KAAK,QAAQ;IAC3B,OAAO,KAAK,IAAI;IAChB,MAAM,IAAI,OAAO;IACjB,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC;AAEnC;;;;;;;GAOG;AACH,MAAM,cAAc,GAClB,sEAAsE,CAAC;AAEzE;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACzB,MAAc,EACd,IAAY,EACZ,EAAE,KAAK,EAAE,WAAW,GAAG,EAAE,KAAoB,EAAE;IAE/C,MAAM,KAAK,GAAG,KAAK,CACjB,OAAO,CAAC,QAAQ,EAChB;QACE,GAAG,WAAW;QACd,qBAAqB;QACrB,QAAQ;QACR,cAAc,GAAG,MAAM;QACvB,IAAI;KACL,EACD,EAAE,KAAK,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,CAC7C,CAAC;IACF,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;IACf,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,EAAQ,CAAC;IAC7C,MAAM,MAAM,GAAkB;QAC5B,KAAK;QACL,MAAM,EAAE,MAAM,CAAC,OAAO;QACtB,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,IAAI;QACV,GAAG,CAAC,IAAI;YACN,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KA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MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/testing",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.27",
|
|
4
4
|
"description": "Disposable fixtures for integration tests: Docker containers, database servers, SQLite and DuckDB databases, HTTP servers, streams, temporary directories and intercepted requests. Node's global setup and teardown remove what a killed test run left behind.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,6 +38,12 @@
|
|
|
38
38
|
"import": "./dist/async/index.js",
|
|
39
39
|
"default": "./dist/async/index.js"
|
|
40
40
|
},
|
|
41
|
+
"./process": {
|
|
42
|
+
"@zukhruf/source": "./src/process/index.ts",
|
|
43
|
+
"types": "./dist/process/index.d.ts",
|
|
44
|
+
"import": "./dist/process/index.js",
|
|
45
|
+
"default": "./dist/process/index.js"
|
|
46
|
+
},
|
|
41
47
|
"./docker": {
|
|
42
48
|
"@zukhruf/source": "./src/docker/index.ts",
|
|
43
49
|
"types": "./dist/docker/index.d.ts",
|
|
@@ -145,9 +151,9 @@
|
|
|
145
151
|
"pg": "^8.23.1"
|
|
146
152
|
},
|
|
147
153
|
"dependencies": {
|
|
148
|
-
"@zukhruf/async": "^0.8.
|
|
149
|
-
"@zukhruf/docker": "^0.8.
|
|
150
|
-
"@zukhruf/fs": "^0.8.
|
|
154
|
+
"@zukhruf/async": "^0.8.27",
|
|
155
|
+
"@zukhruf/docker": "^0.8.27",
|
|
156
|
+
"@zukhruf/fs": "^0.8.27",
|
|
151
157
|
"nano-spawn": "^2.1.0",
|
|
152
158
|
"p-memoize": "^8.0.0",
|
|
153
159
|
"p-retry": "^8.0.1"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"settle-within.d.ts","sourceRoot":"","sources":["../../src/async/settle-within.ts"],"names":[],"mappings":"AAEA,wBAAsB,YAAY,CAAC,CAAC,EAClC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,EACvB,KAAK,EAAE,MAAM,EACb,SAAS,SAAQ,GAChB,OAAO,CAAC,CAAC,CAAC,CAYZ"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { timeout } from '@zukhruf/async';
|
|
2
|
-
export async function settleWithin(promise, label, timeoutMs = 5_000) {
|
|
3
|
-
// A real deadline: it bounds how long the test waits, so a fake clock that
|
|
4
|
-
// the test moves must not end it. It keeps the process alive, so a promise
|
|
5
|
-
// that never settles fails with the label.
|
|
6
|
-
using limit = timeout(timeoutMs, { clock: globalThis, ref: true });
|
|
7
|
-
const expired = Promise.withResolvers();
|
|
8
|
-
limit.signal.addEventListener('abort', () => expired.reject(new Error(`timed out waiting for: ${label}`)), { once: true });
|
|
9
|
-
return await Promise.race([promise, expired.promise]);
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=settle-within.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"settle-within.js","sourceRoot":"","sources":["../../src/async/settle-within.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAAuB,EACvB,KAAa,EACb,SAAS,GAAG,KAAK;IAEjB,2EAA2E;IAC3E,2EAA2E;IAC3E,2CAA2C;IAC3C,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;IACnE,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,EAAS,CAAC;IAC/C,KAAK,CAAC,MAAM,CAAC,gBAAgB,CAC3B,OAAO,EACP,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,0BAA0B,KAAK,EAAE,CAAC,CAAC,EAClE,EAAE,IAAI,EAAE,IAAI,EAAE,CACf,CAAC;IACF,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;AACxD,CAAC"}
|