@zukhruf/testing 0.3.18 → 0.3.20
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 +41 -0
- package/dist/node/index.d.ts +13 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +20 -0
- package/dist/node/index.js.map +1 -0
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ Each area has its own import path, so a test loads only the drivers it uses. The
|
|
|
10
10
|
|
|
11
11
|
| Import | Gives | Needs |
|
|
12
12
|
| ----------------------------- | --------------------------------------------------------------------------------------- | ------------------------ |
|
|
13
|
+
| `@zukhruf/testing/node` | Native `test`, `it`, `suite`, `describe` with `.each` | |
|
|
13
14
|
| `@zukhruf/testing/async` | `timebox`, `settleWithin` | |
|
|
14
15
|
| `@zukhruf/testing/docker` | `Docker`, `Container`, `ServiceContainer`, `DockerVolume`, `DockerDirectory`, `TestRun` | Docker CLI |
|
|
15
16
|
| `@zukhruf/testing/postgres` | `Postgres` | Docker CLI |
|
|
@@ -23,6 +24,46 @@ Each area has its own import path, so a test loads only the drivers it uses. The
|
|
|
23
24
|
| `@zukhruf/testing/http` | `HttpServer` | |
|
|
24
25
|
| `@zukhruf/testing/streams` | `StreamHarness` | |
|
|
25
26
|
|
|
27
|
+
## Parameterized tests
|
|
28
|
+
|
|
29
|
+
Import `test` or `it` from `@zukhruf/testing/node` to repeat native test declarations over a table. Use `suite` or `describe` for suites across implementations or configurations.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { describe, test } from '@zukhruf/testing/node';
|
|
33
|
+
|
|
34
|
+
void test.each(
|
|
35
|
+
[
|
|
36
|
+
{ name: 'integer', input: '42', expected: 42 },
|
|
37
|
+
{ name: 'decimal', input: '1.5', expected: 1.5 },
|
|
38
|
+
],
|
|
39
|
+
(row) =>
|
|
40
|
+
test(row.name, { timeout: 1_000 }, (t) => {
|
|
41
|
+
t.assert.equal(Number(row.input), row.expected);
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
void describe.each(['utf8', 'utf16le'] as const, (encoding) =>
|
|
46
|
+
describe(encoding, () => {
|
|
47
|
+
test('round-trips text', (t) => {
|
|
48
|
+
t.assert.equal(
|
|
49
|
+
Buffer.from('hello', encoding).toString(encoding),
|
|
50
|
+
'hello',
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Both methods accept `(rows, register)`. The rows are a readonly array; scalars, objects, tuples, and factories keep their inferred types. `register(row, index)` must return the native `test()` or `suite()` promise. Names, options, modifiers, and contexts belong to that native call. An empty table or a callback that returns no promise throws during registration.
|
|
58
|
+
|
|
59
|
+
Call native `test()` or `suite()` directly in the callback in your test file. This preserves Node's declaration location for reports, navigation, and saved-failure reruns. The earlier `(rows, name, [options], body)` prototype registered inside the shared helper and has been removed because those locations collided across files.
|
|
60
|
+
|
|
61
|
+
Inside an asynchronous parent test, `await test.each(...)` to keep that parent alive until its subtests finish. Call `t.test()` in the registration callback when using the parent's assertion plan. Node controls subtest concurrency through the parent. Inside a suite, native declaration promises fulfill immediately. Acquire and dispose fixtures inside each test body.
|
|
62
|
+
|
|
63
|
+
These are the original native function objects with an added property: `test === it` and `suite === describe`. Their extended types are available through this import, without globally augmenting `node:test`. This area imports only Node built-ins.
|
|
64
|
+
|
|
65
|
+
TAP, spec, simultaneous JUnit output, name filtering, skip/TODO reasons, failure exit status, default snapshots, and saved-failure reruns across multiple files are covered by this area's tests. Snapshots belong to the test entry file. Rerun regression tests check actual body execution through persistent failures, a subsequent fix, and replay of the passing results.
|
|
66
|
+
|
|
26
67
|
## Docker
|
|
27
68
|
|
|
28
69
|
A `Docker` is the engine the Docker CLI selects. It resolves the engine once, on first use, and every handle it returns keeps that engine. It supports local Unix sockets, Docker Desktop's named pipe on Windows (`npipe://`), and SSH engines (`ssh://`).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { suite as nodeSuite, test as nodeTest } from 'node:test';
|
|
2
|
+
/** Calls register synchronously for each row and waits for every native declaration. */
|
|
3
|
+
declare function each<Row>(rows: readonly Row[], register: (row: Row, index: number) => Promise<void>): Promise<void>;
|
|
4
|
+
/** Return a native test() call from the callback to preserve its declaration location. */
|
|
5
|
+
export declare const test: typeof nodeTest & {
|
|
6
|
+
each: typeof each;
|
|
7
|
+
};
|
|
8
|
+
/** Return a native suite() call from the callback; acquire resources inside its tests. */
|
|
9
|
+
export declare const suite: typeof nodeSuite & {
|
|
10
|
+
each: typeof each;
|
|
11
|
+
};
|
|
12
|
+
export { suite as describe, test as it };
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGjE,wFAAwF;AACxF,iBAAS,IAAI,CAAC,GAAG,EACf,IAAI,EAAE,SAAS,GAAG,EAAE,EACpB,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GACnD,OAAO,CAAC,IAAI,CAAC,CAWf;AAED,0FAA0F;AAC1F,eAAO,MAAM,IAAI;;CAAoC,CAAC;AACtD,0FAA0F;AAC1F,eAAO,MAAM,KAAK;;CAAqC,CAAC;AACxD,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { suite as nodeSuite, test as nodeTest } from 'node:test';
|
|
2
|
+
import { isPromise } from 'node:util/types';
|
|
3
|
+
/** Calls register synchronously for each row and waits for every native declaration. */
|
|
4
|
+
function each(rows, register) {
|
|
5
|
+
if (rows.length === 0)
|
|
6
|
+
throw new Error('each() requires at least one case');
|
|
7
|
+
return Promise.all(rows.map((row, index) => {
|
|
8
|
+
const registration = register(row, index);
|
|
9
|
+
if (!isPromise(registration)) {
|
|
10
|
+
throw new TypeError('each() callback must return test() or suite()');
|
|
11
|
+
}
|
|
12
|
+
return registration;
|
|
13
|
+
})).then(() => undefined);
|
|
14
|
+
}
|
|
15
|
+
/** Return a native test() call from the callback to preserve its declaration location. */
|
|
16
|
+
export const test = Object.assign(nodeTest, { each });
|
|
17
|
+
/** Return a native suite() call from the callback; acquire resources inside its tests. */
|
|
18
|
+
export const suite = Object.assign(nodeSuite, { each });
|
|
19
|
+
export { suite as describe, test as it };
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,wFAAwF;AACxF,SAAS,IAAI,CACX,IAAoB,EACpB,QAAoD;IAEpD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAC5E,OAAO,OAAO,CAAC,GAAG,CAChB,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QACtB,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1C,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,SAAS,CAAC,+CAA+C,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,YAAY,CAAC;IACtB,CAAC,CAAC,CACH,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;AAC1B,CAAC;AAED,0FAA0F;AAC1F,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AACtD,0FAA0F;AAC1F,MAAM,CAAC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AACxD,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/testing",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.20",
|
|
4
4
|
"description": "Disposable fixtures for integration tests: Docker containers and database servers, SQLite and DuckDB databases, HTTP servers and streams. A supervisor removes what a killed test run left behind.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,6 +29,12 @@
|
|
|
29
29
|
},
|
|
30
30
|
"exports": {
|
|
31
31
|
"./package.json": "./package.json",
|
|
32
|
+
"./node": {
|
|
33
|
+
"@zukhruf/source": "./src/node/index.ts",
|
|
34
|
+
"types": "./dist/node/index.d.ts",
|
|
35
|
+
"import": "./dist/node/index.js",
|
|
36
|
+
"default": "./dist/node/index.js"
|
|
37
|
+
},
|
|
32
38
|
"./async": {
|
|
33
39
|
"@zukhruf/source": "./src/async/index.ts",
|
|
34
40
|
"types": "./dist/async/index.d.ts",
|