@zukhruf/testing 0.3.8 → 0.3.9
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 +21 -30
- package/dist/docker/index.d.ts +0 -1
- package/dist/docker/index.d.ts.map +1 -1
- package/dist/docker/index.js +0 -1
- package/dist/docker/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/docker/skip-without-docker.d.ts +0 -12
- package/dist/docker/skip-without-docker.d.ts.map +0 -1
- package/dist/docker/skip-without-docker.js +0 -31
- package/dist/docker/skip-without-docker.js.map +0 -1
package/README.md
CHANGED
|
@@ -8,32 +8,33 @@ The words in these documents have one meaning each. See the glossary in [CONTEXT
|
|
|
8
8
|
|
|
9
9
|
Each area has its own import path, so a test loads only the drivers it uses. The three drivers are optional peer dependencies: install the one an area names.
|
|
10
10
|
|
|
11
|
-
| Import | Gives
|
|
12
|
-
| ----------------------------- |
|
|
13
|
-
| `@zukhruf/testing/async` | `timebox`, `settleWithin`
|
|
14
|
-
| `@zukhruf/testing/docker` | `Docker`, `Container`, `ServiceContainer`, `DockerVolume`, `DockerDirectory`, `TestRun
|
|
15
|
-
| `@zukhruf/testing/postgres` | `Postgres`
|
|
16
|
-
| `@zukhruf/testing/mysql` | `Mysql`
|
|
17
|
-
| `@zukhruf/testing/mariadb` | `Mariadb`
|
|
18
|
-
| `@zukhruf/testing/sqlserver` | `SqlServer`, `SQL_SERVER_FULL_IMAGE`, `SQL_SERVER_EDGE_IMAGE`
|
|
19
|
-
| `@zukhruf/testing/clickhouse` | `ClickHouse`
|
|
20
|
-
| `@zukhruf/testing/sqlite` | `Sqlite`
|
|
21
|
-
| `@zukhruf/testing/duckdb` | `DuckDB`
|
|
22
|
-
| `@zukhruf/testing/bigquery` | `BigQuery`
|
|
23
|
-
| `@zukhruf/testing/http` | `HttpServer`
|
|
24
|
-
| `@zukhruf/testing/streams` | `StreamHarness`
|
|
11
|
+
| Import | Gives | Needs |
|
|
12
|
+
| ----------------------------- | --------------------------------------------------------------------------------------- | ------------------------ |
|
|
13
|
+
| `@zukhruf/testing/async` | `timebox`, `settleWithin` | |
|
|
14
|
+
| `@zukhruf/testing/docker` | `Docker`, `Container`, `ServiceContainer`, `DockerVolume`, `DockerDirectory`, `TestRun` | Docker CLI |
|
|
15
|
+
| `@zukhruf/testing/postgres` | `Postgres` | Docker CLI |
|
|
16
|
+
| `@zukhruf/testing/mysql` | `Mysql` | Docker CLI |
|
|
17
|
+
| `@zukhruf/testing/mariadb` | `Mariadb` | Docker CLI |
|
|
18
|
+
| `@zukhruf/testing/sqlserver` | `SqlServer`, `SQL_SERVER_FULL_IMAGE`, `SQL_SERVER_EDGE_IMAGE` | Docker CLI, `mssql` |
|
|
19
|
+
| `@zukhruf/testing/clickhouse` | `ClickHouse` | Docker CLI |
|
|
20
|
+
| `@zukhruf/testing/sqlite` | `Sqlite` | |
|
|
21
|
+
| `@zukhruf/testing/duckdb` | `DuckDB` | `@duckdb/node-api` |
|
|
22
|
+
| `@zukhruf/testing/bigquery` | `BigQuery` | `@google-cloud/bigquery` |
|
|
23
|
+
| `@zukhruf/testing/http` | `HttpServer` | |
|
|
24
|
+
| `@zukhruf/testing/streams` | `StreamHarness` | |
|
|
25
25
|
|
|
26
26
|
## Docker
|
|
27
27
|
|
|
28
|
-
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://`).
|
|
28
|
+
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://`).
|
|
29
|
+
|
|
30
|
+
A test that needs Docker has no skip option. When the engine does not answer, the first acquisition fails with "Docker is required for container-backed tests" and the engine's error as the cause. Start Docker to run these tests.
|
|
29
31
|
|
|
30
32
|
```ts
|
|
31
|
-
import { Docker, TestRun
|
|
33
|
+
import { Docker, TestRun } from '@zukhruf/testing/docker';
|
|
32
34
|
|
|
33
35
|
const docker = new Docker({ testRun: TestRun.fromEnvironment(process.env) });
|
|
34
|
-
const skip = await skipWithoutDocker(docker, process.env);
|
|
35
36
|
|
|
36
|
-
test('a holder in another container',
|
|
37
|
+
test('a holder in another container', async () => {
|
|
37
38
|
await using volume = await docker.volume();
|
|
38
39
|
await using holder = await docker.start({
|
|
39
40
|
image: 'node:lts-alpine',
|
|
@@ -76,16 +77,6 @@ docker stop <container-id>
|
|
|
76
77
|
|
|
77
78
|
They run with `--rm`, so stopping also removes them. The image tag is part of the configuration: stop the server to pick up a newer image behind the same tag.
|
|
78
79
|
|
|
79
|
-
### Skipping without Docker
|
|
80
|
-
|
|
81
|
-
`skipWithoutDocker(docker, process.env)` returns the `skip` option of a test that needs Docker. `ZUKHRUF_TESTING_DOCKER` decides:
|
|
82
|
-
|
|
83
|
-
| Value | Result |
|
|
84
|
-
| ---------- | ------------------------------------------------------------------------------------- |
|
|
85
|
-
| `required` | Runs. Throws when Docker does not answer, so a machine that must run the tests fails. |
|
|
86
|
-
| `skip` | Skips. |
|
|
87
|
-
| unset | Runs when Docker answers, skips with a reason when it does not. |
|
|
88
|
-
|
|
89
80
|
## The supervisor
|
|
90
81
|
|
|
91
82
|
Disposal cleans up after a test that ends. A test process that is killed (a timeout, Ctrl-C, `--test-force-exit`) never disposes its handles, and a running container does not stop by itself. The `zukhruf-docker-tests` command runs `node --test` as one supervised run:
|
|
@@ -111,7 +102,7 @@ import { Postgres } from '@zukhruf/testing/postgres';
|
|
|
111
102
|
|
|
112
103
|
const postgres = new Postgres({ docker });
|
|
113
104
|
|
|
114
|
-
test('stores a record',
|
|
105
|
+
test('stores a record', async () => {
|
|
115
106
|
await using database = await postgres.database();
|
|
116
107
|
// database.connectionString. Close your clients before the scope ends.
|
|
117
108
|
});
|
|
@@ -156,4 +147,4 @@ npx nx run testing:test # builds, then runs the tests
|
|
|
156
147
|
npx nx run testing:typecheck # formats, lints, then type checks
|
|
157
148
|
```
|
|
158
149
|
|
|
159
|
-
The
|
|
150
|
+
The tests that need Docker run on every machine, and fail when the engine does not answer. CI runs every test on Linux, where Docker runs Linux containers. The `test` target runs alone (`parallelism: false`): Nx starts no other task while it runs, because its database servers slow down the timing tests of the other projects.
|
package/dist/docker/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { Container, type DockerCommand, ServiceContainer, } from './container.ts';
|
|
2
2
|
export { DockerDirectory } from './directory.ts';
|
|
3
3
|
export { type ContainerOptions, Docker, type DockerOptions, type Mount, type ServiceOptions, } from './docker.ts';
|
|
4
|
-
export { DOCKER_TESTS, skipWithoutDocker } from './skip-without-docker.ts';
|
|
5
4
|
export { TestRun } from './test-run.ts';
|
|
6
5
|
export { DockerVolume } from './volume.ts';
|
|
7
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/docker/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,KAAK,aAAa,EAClB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EACL,KAAK,gBAAgB,EACrB,MAAM,EACN,KAAK,aAAa,EAClB,KAAK,KAAK,EACV,KAAK,cAAc,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/docker/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,KAAK,aAAa,EAClB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EACL,KAAK,gBAAgB,EACrB,MAAM,EACN,KAAK,aAAa,EAClB,KAAK,KAAK,EACV,KAAK,cAAc,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/docker/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { Container, ServiceContainer, } from "./container.js";
|
|
2
2
|
export { DockerDirectory } from "./directory.js";
|
|
3
3
|
export { Docker, } from "./docker.js";
|
|
4
|
-
export { DOCKER_TESTS, skipWithoutDocker } from "./skip-without-docker.js";
|
|
5
4
|
export { TestRun } from "./test-run.js";
|
|
6
5
|
export { DockerVolume } from "./volume.js";
|
|
7
6
|
//# sourceMappingURL=index.js.map
|
package/dist/docker/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/docker/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAET,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAEL,MAAM,GAIP,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/docker/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAET,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAEL,MAAM,GAIP,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/testing",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
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": {
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Docker } from './docker.ts';
|
|
2
|
-
/** How tests treat Docker: `required`, `skip`, or unset to run when Docker answers. */
|
|
3
|
-
export declare const DOCKER_TESTS = "ZUKHRUF_TESTING_DOCKER";
|
|
4
|
-
/**
|
|
5
|
-
* The `skip` option of a test that needs Docker, read from the environment the
|
|
6
|
-
* host passes (`process.env`). With `ZUKHRUF_TESTING_DOCKER=required` it
|
|
7
|
-
* throws when Docker does not answer, so a machine that must run the tests
|
|
8
|
-
* fails instead of skipping them. With `skip` it always skips. Unset, it skips
|
|
9
|
-
* only when Docker does not answer.
|
|
10
|
-
*/
|
|
11
|
-
export declare function skipWithoutDocker(docker: Docker, environment: Readonly<Record<string, string | undefined>>): Promise<string | false>;
|
|
12
|
-
//# sourceMappingURL=skip-without-docker.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"skip-without-docker.d.ts","sourceRoot":"","sources":["../../src/docker/skip-without-docker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,uFAAuF;AACvF,eAAO,MAAM,YAAY,2BAA2B,CAAC;AAErD;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,GACxD,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAuBzB"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/** How tests treat Docker: `required`, `skip`, or unset to run when Docker answers. */
|
|
2
|
-
export const DOCKER_TESTS = 'ZUKHRUF_TESTING_DOCKER';
|
|
3
|
-
/**
|
|
4
|
-
* The `skip` option of a test that needs Docker, read from the environment the
|
|
5
|
-
* host passes (`process.env`). With `ZUKHRUF_TESTING_DOCKER=required` it
|
|
6
|
-
* throws when Docker does not answer, so a machine that must run the tests
|
|
7
|
-
* fails instead of skipping them. With `skip` it always skips. Unset, it skips
|
|
8
|
-
* only when Docker does not answer.
|
|
9
|
-
*/
|
|
10
|
-
export async function skipWithoutDocker(docker, environment) {
|
|
11
|
-
const mode = environment[DOCKER_TESTS];
|
|
12
|
-
switch (mode) {
|
|
13
|
-
case 'skip':
|
|
14
|
-
return `${DOCKER_TESTS}=skip`;
|
|
15
|
-
case 'required':
|
|
16
|
-
await docker.command(['info']).catch((cause) => {
|
|
17
|
-
throw new Error(`${DOCKER_TESTS}=required, but Docker does not answer`, {
|
|
18
|
-
cause,
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
return false;
|
|
22
|
-
case undefined:
|
|
23
|
-
case '':
|
|
24
|
-
return (await docker.isAvailable())
|
|
25
|
-
? false
|
|
26
|
-
: `needs Docker; set ${DOCKER_TESTS}=required to fail instead of skipping`;
|
|
27
|
-
default:
|
|
28
|
-
throw new Error(`${DOCKER_TESTS} is "required" or "skip", not "${mode}"`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=skip-without-docker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"skip-without-docker.js","sourceRoot":"","sources":["../../src/docker/skip-without-docker.ts"],"names":[],"mappings":"AAEA,uFAAuF;AACvF,MAAM,CAAC,MAAM,YAAY,GAAG,wBAAwB,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAc,EACd,WAAyD;IAEzD,MAAM,IAAI,GAAG,WAAW,CAAC,YAAY,CAAC,CAAC;IACvC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,MAAM;YACT,OAAO,GAAG,YAAY,OAAO,CAAC;QAChC,KAAK,UAAU;YACb,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;gBACtD,MAAM,IAAI,KAAK,CACb,GAAG,YAAY,uCAAuC,EACtD;oBACE,KAAK;iBACN,CACF,CAAC;YACJ,CAAC,CAAC,CAAC;YACH,OAAO,KAAK,CAAC;QACf,KAAK,SAAS,CAAC;QACf,KAAK,EAAE;YACL,OAAO,CAAC,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC;gBACjC,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,qBAAqB,YAAY,uCAAuC,CAAC;QAC/E;YACE,MAAM,IAAI,KAAK,CAAC,GAAG,YAAY,kCAAkC,IAAI,GAAG,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC"}
|