@zukhruf/testing 0.8.19 → 0.8.21
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 +3 -22
- package/dist/databases/sqlite.js +1 -1
- package/dist/databases/sqlite.js.map +1 -1
- package/package.json +4 -9
- package/dist/fs/temporary-files.d.ts +0 -15
- package/dist/fs/temporary-files.d.ts.map +0 -1
- package/dist/fs/temporary-files.js +0 -21
- package/dist/fs/temporary-files.js.map +0 -1
package/README.md
CHANGED
|
@@ -23,7 +23,6 @@ Each area has its own import path, so a test loads only the drivers it uses. The
|
|
|
23
23
|
| `@zukhruf/testing/bigquery` | `BigQuery` | `@google-cloud/bigquery` |
|
|
24
24
|
| `@zukhruf/testing/http` | `HttpServer` | |
|
|
25
25
|
| `@zukhruf/testing/streams` | `StreamHarness` | |
|
|
26
|
-
| `@zukhruf/testing/fs` | `TemporaryFiles` | |
|
|
27
26
|
| `@zukhruf/testing/msw` | `Msw` | `msw` |
|
|
28
27
|
| `@zukhruf/testing/preload` | `notInstalled` | |
|
|
29
28
|
|
|
@@ -227,25 +226,7 @@ The handler is a Node.js request listener. A web framework gives one for its fet
|
|
|
227
226
|
|
|
228
227
|
## Temporary directories
|
|
229
228
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
```ts
|
|
233
|
-
import { TemporaryFiles } from '@zukhruf/testing/fs';
|
|
234
|
-
|
|
235
|
-
const files = new TemporaryFiles();
|
|
236
|
-
|
|
237
|
-
test('writes the report', async (t) => {
|
|
238
|
-
await using directory = await files.directory('report-');
|
|
239
|
-
await writeReport(join(directory.path, 'report.json'));
|
|
240
|
-
t.assert.ok(existsSync(join(directory.path, 'report.json')));
|
|
241
|
-
});
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
`path` is the real path: the acquisition resolves symbolic links. On macOS, `os.tmpdir()` is below `/var`, and `/var` is a link to `/private/var`. git, a child process and a bind mount give the resolved path. Thus a test can compare their output with `path` directly.
|
|
245
|
-
|
|
246
|
-
On Windows, a process that still holds a file open stops its removal for a short time. Thus disposal retries the removal on `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY` and `EPERM`. It retries 8 times, and it waits 50 ms longer before each retry: 50 + 100 + … + 400 = 1.8 s at most. A removal that does not fail does not wait. When the last retry fails, disposal rejects with the error.
|
|
247
|
-
|
|
248
|
-
The only option is `parent`, the directory that holds the new directory. The default is `os.tmpdir()`. A Unix socket path has a limit of 104 bytes on macOS and 108 bytes on Linux. On macOS, the real path of `os.tmpdir()` uses 56 of them. Thus give a short parent, such as `/tmp`, for a socket. Node resolves a package from the parent directories of the file that imports it. Thus give a parent in the repository when a file in the directory imports a package of the repository.
|
|
229
|
+
A test makes its temporary directory with `TemporaryFiles` of [`@zukhruf/fs`](../fs/README.md#make-a-temporary-directory), the same class that production code uses.
|
|
249
230
|
|
|
250
231
|
## Environment variables
|
|
251
232
|
|
|
@@ -285,13 +266,13 @@ import spawn from 'nano-spawn';
|
|
|
285
266
|
|
|
286
267
|
import { notInstalled } from '@zukhruf/testing/preload';
|
|
287
268
|
|
|
288
|
-
test('the
|
|
269
|
+
test('the http area loads without msw', async () => {
|
|
289
270
|
await spawn(process.execPath, [
|
|
290
271
|
'--import',
|
|
291
272
|
notInstalled('msw'),
|
|
292
273
|
'--input-type=module',
|
|
293
274
|
'--eval',
|
|
294
|
-
"await import('@zukhruf/testing/
|
|
275
|
+
"await import('@zukhruf/testing/http');",
|
|
295
276
|
]);
|
|
296
277
|
});
|
|
297
278
|
```
|
package/dist/databases/sqlite.js
CHANGED
|
@@ -2,7 +2,7 @@ import { once } from 'node:events';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { DatabaseSync } from 'node:sqlite';
|
|
4
4
|
import spawn, { SubprocessError } from 'nano-spawn';
|
|
5
|
-
import { TemporaryFiles } from
|
|
5
|
+
import { TemporaryFiles } from '@zukhruf/fs';
|
|
6
6
|
/** Each acquisition owns an independent, temporary SQLite database. */
|
|
7
7
|
export class Sqlite {
|
|
8
8
|
/** Holds a write lock in another process, which releases even while the caller blocks. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../src/databases/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,KAAK,EAAE,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../src/databases/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,KAAK,EAAE,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAS7C,uEAAuE;AACvE,MAAM,OAAO,MAAM;IACjB,0FAA0F;IAC1F,KAAK,CAAC,SAAS,CAAC,IAAY,EAAE,UAAkB;QAC9C,MAAM,MAAM,GAAG,KAAK,CAClB,OAAO,CAAC,QAAQ,EAChB;YACE,qBAAqB;YACrB,QAAQ;YACR;;;;;;;;;;;SAWC;YACD,IAAI;YACJ,MAAM,CAAC,UAAU,CAAC;SACnB,EACD,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,CAC/C,CAAC;QACF,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1E,CAAC,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AAK,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;QAE3C,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,CAAC;IACvE,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/testing",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.21",
|
|
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": {
|
|
@@ -104,12 +104,6 @@
|
|
|
104
104
|
"import": "./dist/streams/stream-harness.js",
|
|
105
105
|
"default": "./dist/streams/stream-harness.js"
|
|
106
106
|
},
|
|
107
|
-
"./fs": {
|
|
108
|
-
"@zukhruf/source": "./src/fs/temporary-files.ts",
|
|
109
|
-
"types": "./dist/fs/temporary-files.d.ts",
|
|
110
|
-
"import": "./dist/fs/temporary-files.js",
|
|
111
|
-
"default": "./dist/fs/temporary-files.js"
|
|
112
|
-
},
|
|
113
107
|
"./msw": {
|
|
114
108
|
"@zukhruf/source": "./src/msw/msw.ts",
|
|
115
109
|
"types": "./dist/msw/msw.d.ts",
|
|
@@ -151,8 +145,9 @@
|
|
|
151
145
|
"pg": "^8.23.1"
|
|
152
146
|
},
|
|
153
147
|
"dependencies": {
|
|
154
|
-
"@zukhruf/async": "^0.8.
|
|
155
|
-
"@zukhruf/docker": "^0.8.
|
|
148
|
+
"@zukhruf/async": "^0.8.21",
|
|
149
|
+
"@zukhruf/docker": "^0.8.21",
|
|
150
|
+
"@zukhruf/fs": "^0.8.21",
|
|
156
151
|
"nano-spawn": "^2.1.0",
|
|
157
152
|
"p-memoize": "^8.0.0",
|
|
158
153
|
"p-retry": "^8.0.1"
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface TemporaryDirectory extends AsyncDisposable {
|
|
2
|
-
/** The real path: symbolic links are resolved. */
|
|
3
|
-
path: string;
|
|
4
|
-
/** Remove the directory and its contents, with retries for a file that is held open. */
|
|
5
|
-
cleanup: () => Promise<void>;
|
|
6
|
-
}
|
|
7
|
-
export interface TemporaryDirectoryOptions {
|
|
8
|
-
/** The directory that holds the new directory. Default: `os.tmpdir()`. */
|
|
9
|
-
parent?: string;
|
|
10
|
-
}
|
|
11
|
-
/** Each acquisition owns an empty directory, removed with all that it holds. */
|
|
12
|
-
export declare class TemporaryFiles {
|
|
13
|
-
directory(prefix: string, { parent }?: TemporaryDirectoryOptions): Promise<TemporaryDirectory>;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=temporary-files.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"temporary-files.d.ts","sourceRoot":"","sources":["../../src/fs/temporary-files.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IACzD,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,wFAAwF;IACxF,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,yBAAyB;IACxC,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,gFAAgF;AAChF,qBAAa,cAAc;IACnB,SAAS,CACb,MAAM,EAAE,MAAM,EACd,EAAE,MAAiB,EAAE,GAAE,yBAA8B,GACpD,OAAO,CAAC,kBAAkB,CAAC;CAiB/B"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { mkdtemp, realpath, rm } from 'node:fs/promises';
|
|
2
|
-
import { tmpdir } from 'node:os';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
/** Each acquisition owns an empty directory, removed with all that it holds. */
|
|
5
|
-
export class TemporaryFiles {
|
|
6
|
-
async directory(prefix, { parent = tmpdir() } = {}) {
|
|
7
|
-
await using resources = new AsyncDisposableStack();
|
|
8
|
-
const created = await mkdtemp(join(parent, prefix));
|
|
9
|
-
resources.defer(() => rm(created, {
|
|
10
|
-
recursive: true,
|
|
11
|
-
force: true,
|
|
12
|
-
maxRetries: 8,
|
|
13
|
-
retryDelay: 50,
|
|
14
|
-
}));
|
|
15
|
-
const path = await realpath(created);
|
|
16
|
-
const owned = resources.move();
|
|
17
|
-
const cleanup = () => owned.disposeAsync();
|
|
18
|
-
return { path, cleanup, [Symbol.asyncDispose]: cleanup };
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=temporary-files.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"temporary-files.js","sourceRoot":"","sources":["../../src/fs/temporary-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAcjC,gFAAgF;AAChF,MAAM,OAAO,cAAc;IACzB,KAAK,CAAC,SAAS,CACb,MAAc,EACd,EAAE,MAAM,GAAG,MAAM,EAAE,KAAgC,EAAE;QAErD,YAAY,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;QACnD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;QACpD,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,CACnB,EAAE,CAAC,OAAO,EAAE;YACV,SAAS,EAAE,IAAI;YACf,KAAK,EAAE,IAAI;YACX,UAAU,EAAE,CAAC;YACb,UAAU,EAAE,EAAE;SACf,CAAC,CACH,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAC;QACrC,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;QAE3C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,CAAC;IAC3D,CAAC;CACF"}
|