@zukhruf/testing 0.3.5 → 0.3.6
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
CHANGED
|
@@ -141,7 +141,7 @@ process.env.KEYS_URL = keys.origin;
|
|
|
141
141
|
const { verify } = await import('./verify.ts');
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
-
The handler is a Node.js request listener. A web framework gives one for its fetch handler: `getRequestListener((request) => app.fetch(request))` from `@hono/node-server`, or `toNodeHandler((request) => auth.handler(request))` from `better-auth/node`. A handler that needs the origin can read a `const` that the test declares after the acquisition: no request arrives before the test gives the origin to a client.
|
|
144
|
+
The handler is a Node.js request listener. A web framework gives one for its fetch handler: `getRequestListener((request) => app.fetch(request))` from `@hono/node-server`, or `toNodeHandler((request) => auth.handler(request))` from `better-auth/node`. The handler can be async. When it rejects, the rejection stays unhandled and fails the process, as a throw does. The server never answers for a handler that failed. A handler that needs the origin can read a `const` that the test declares after the acquisition: no request arrives before the test gives the origin to a client.
|
|
145
145
|
|
|
146
146
|
`StreamHarness` gives a controlled producer, `source<T>()`, with `enqueue`, `close`, `error` and a read-only `state`, and a disposable `reader(stream)` that locks a stream without reading ahead. `collectUntilError()` returns the remaining chunks and either `completed` or `errored` with the error.
|
|
147
147
|
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type IncomingMessage, type Server, type ServerResponse } from 'node:http';
|
|
2
|
+
/**
|
|
3
|
+
* Answers one request. It may be async: a rejection stays unhandled and fails
|
|
4
|
+
* the process, as a throw in a synchronous handler does.
|
|
5
|
+
*/
|
|
6
|
+
export type HttpHandler = (request: IncomingMessage, response: ServerResponse) => unknown;
|
|
2
7
|
export interface HttpServerHandle extends AsyncDisposable {
|
|
3
8
|
origin: string;
|
|
4
9
|
server: Server;
|
|
@@ -11,8 +16,8 @@ export interface BackgroundHttpServer {
|
|
|
11
16
|
}
|
|
12
17
|
/** Each acquisition owns a loopback HTTP server on an available port. */
|
|
13
18
|
export declare class HttpServer {
|
|
14
|
-
start(handler:
|
|
19
|
+
start(handler: HttpHandler): Promise<HttpServerHandle>;
|
|
15
20
|
/** Serves until the process exits and never keeps it running, even while a connection is open. */
|
|
16
|
-
background(handler:
|
|
21
|
+
background(handler: HttpHandler): Promise<BackgroundHttpServer>;
|
|
17
22
|
}
|
|
18
23
|
//# sourceMappingURL=http-server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-server.d.ts","sourceRoot":"","sources":["../../src/http/http-server.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"http-server.d.ts","sourceRoot":"","sources":["../../src/http/http-server.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,cAAc,EAEpB,MAAM,WAAW,CAAC;AAEnB;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,CACxB,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,cAAc,KACrB,OAAO,CAAC;AAEb,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,iEAAiE;IACjE,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED,gEAAgE;AAChE,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,yEAAyE;AACzE,qBAAa,UAAU;IACf,KAAK,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAsB5D,kGAAkG;IAC5F,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAOtE"}
|
package/dist/http/http-server.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import assert from 'node:assert/strict';
|
|
2
2
|
import { once } from 'node:events';
|
|
3
|
-
import { createServer } from 'node:http';
|
|
3
|
+
import { createServer, } from 'node:http';
|
|
4
4
|
/** Each acquisition owns a loopback HTTP server on an available port. */
|
|
5
5
|
export class HttpServer {
|
|
6
6
|
async start(handler) {
|
|
7
7
|
await using resources = new AsyncDisposableStack();
|
|
8
|
-
const server =
|
|
8
|
+
const server = serve(handler);
|
|
9
9
|
await listen(server);
|
|
10
10
|
resources.defer(async () => {
|
|
11
11
|
const closed = server[Symbol.asyncDispose]();
|
|
@@ -24,13 +24,18 @@ export class HttpServer {
|
|
|
24
24
|
}
|
|
25
25
|
/** Serves until the process exits and never keeps it running, even while a connection is open. */
|
|
26
26
|
async background(handler) {
|
|
27
|
-
const server =
|
|
27
|
+
const server = serve(handler);
|
|
28
28
|
server.on('connection', (socket) => socket.unref());
|
|
29
29
|
await listen(server);
|
|
30
30
|
server.unref();
|
|
31
31
|
return { origin: originOf(server) };
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
+
function serve(handler) {
|
|
35
|
+
return createServer((request, response) => {
|
|
36
|
+
void handler(request, response);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
34
39
|
async function listen(server) {
|
|
35
40
|
const listening = once(server, 'listening');
|
|
36
41
|
server.listen(0, '127.0.0.1');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-server.js","sourceRoot":"","sources":["../../src/http/http-server.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,
|
|
1
|
+
{"version":3,"file":"http-server.js","sourceRoot":"","sources":["../../src/http/http-server.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAIL,YAAY,GACb,MAAM,WAAW,CAAC;AAuBnB,yEAAyE;AACzE,MAAM,OAAO,UAAU;IACrB,KAAK,CAAC,K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AAED,KAAK,UAAU,MAAM,CAAC,MAAc;IAClC,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC5C,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IAC9B,MAAM,SAAS,CAAC;AAClB,CAAC;AAED,SAAS,QAAQ,CAAC,MAAc;IAC9B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IACjC,MAAM,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC;IAC/C,OAAO,oBAAoB,OAAO,CAAC,IAAI,EAAE,CAAC;AAC5C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/testing",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
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": {
|