@lushly-dev/afd-auth 3.0.0 → 3.1.0
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 +15 -4
- package/dist/testing/index.d.ts +165 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +294 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +17 -12
package/README.md
CHANGED
|
@@ -198,9 +198,13 @@ const adapter = useConvexAuthAdapter({
|
|
|
198
198
|
`PROVIDER_ERROR`, with the wait in its suggestion. An `OTHER_ERROR` is mapped
|
|
199
199
|
from its `cause`, so a failed fetch is `NETWORK_ERROR`.
|
|
200
200
|
|
|
201
|
-
The 2.x support is checked against the types of `@convex-dev/auth` 2.1.0
|
|
202
|
-
|
|
203
|
-
is tracked in #3006.
|
|
201
|
+
The 2.x support is checked against the types of `@convex-dev/auth` 2.1.0, by
|
|
202
|
+
unit tests, and by the hosted Convex fixture, which runs on 2.x. A credentialed
|
|
203
|
+
hosted run is tracked in #3006.
|
|
204
|
+
|
|
205
|
+
2.x email and password sign-up sends a link that must be opened before the first
|
|
206
|
+
sign-in, so a test without an inbox needs a stand-in for the Resend component's
|
|
207
|
+
`sendEmail`; the hosted fixture's `convex/mail.ts` is one.
|
|
204
208
|
|
|
205
209
|
**0.0.x**, through `useAuthActions().signIn`:
|
|
206
210
|
|
|
@@ -374,7 +378,14 @@ remain tracked in [#362](https://github.com/lushly-dev/afd/issues/362).
|
|
|
374
378
|
|
|
375
379
|
The additional [Better Auth HTTPS/OAuth fixture](hosted/better-auth/README.md)
|
|
376
380
|
uses a local test OAuth provider and SQLite-backed Better Auth. It exercises the
|
|
377
|
-
callback, Secure cookies and restart persistence without a hosted account.
|
|
381
|
+
callback, Secure cookies and restart persistence without a hosted account. Its
|
|
382
|
+
child-process lifecycle, scratch-directory cleanup, loopback port allocation,
|
|
383
|
+
SQLite WAL/FK initialization and HTTP/HTTPS server helpers are exported from the
|
|
384
|
+
Node-only `@lushly-dev/afd-auth/testing` subpath (excluded from the browser
|
|
385
|
+
entries; `openTestSqliteDatabase` loads `node:sqlite` lazily for Node 22.13+ /
|
|
386
|
+
24+, while the other helpers run on Node 22.12+) so downstream Better Auth test
|
|
387
|
+
hosts (such as Loam's `@lushly-dev/loam-identity/testing`) share the same host
|
|
388
|
+
machinery. The
|
|
378
389
|
[Convex fixture](hosted/convex/README.md) bundles actual React/provider SDKs and
|
|
379
390
|
deployable backend functions; its local checks do not execute a Convex deployment.
|
|
380
391
|
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shared Node-only test-host primitives for Better Auth fixtures (`@lushly-dev/afd-auth/testing`).
|
|
3
|
+
*
|
|
4
|
+
* Used by both `packages/auth/hosted/better-auth` and `@lushly-dev/loam-identity/testing` to manage
|
|
5
|
+
* disposable child-process auth servers, scratch directories, loopback ports, SQLite databases and
|
|
6
|
+
* HTTP/HTTPS listeners. Never imported from browser entries.
|
|
7
|
+
*/
|
|
8
|
+
import { type ChildProcess } from 'node:child_process';
|
|
9
|
+
import { type Server as HttpServer, type RequestListener } from 'node:http';
|
|
10
|
+
import { type Server as HttpsServer } from 'node:https';
|
|
11
|
+
import type { DatabaseSync } from 'node:sqlite';
|
|
12
|
+
/** IPC message sent by a test-host child once startup settles. */
|
|
13
|
+
export type TestHostReadyMessage<TPayload extends object = Record<string, unknown>> = ({
|
|
14
|
+
ready: true;
|
|
15
|
+
} & TPayload) | {
|
|
16
|
+
ready: false;
|
|
17
|
+
message?: string;
|
|
18
|
+
};
|
|
19
|
+
/** Options for starting a single test-host child process and awaiting its IPC ready message. */
|
|
20
|
+
export interface StartTestHostChildOptions {
|
|
21
|
+
/** Absolute path to the child entry script. */
|
|
22
|
+
entryPath: string;
|
|
23
|
+
/** Environment variable name used to pass the serialized JSON configuration to the child. */
|
|
24
|
+
envVar: string;
|
|
25
|
+
/** JSON-serializable configuration passed to the child via `envVar`. */
|
|
26
|
+
config: unknown;
|
|
27
|
+
/** Maximum milliseconds to wait for the child's ready message. */
|
|
28
|
+
timeoutMs: number;
|
|
29
|
+
/** Optional abort signal to cancel startup. */
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
/** Optional working directory for the child process. */
|
|
32
|
+
cwd?: string;
|
|
33
|
+
/** Optional Node execArgv passed to `fork`. */
|
|
34
|
+
execArgv?: string[];
|
|
35
|
+
/** Base environment for the child process. Defaults to `process.env`. */
|
|
36
|
+
env?: NodeJS.ProcessEnv;
|
|
37
|
+
/** Prefix for startup error messages (never includes config or secrets). */
|
|
38
|
+
errorPrefix?: string;
|
|
39
|
+
/** Grace period in milliseconds between SIGTERM and SIGKILL when stopping a failed child. */
|
|
40
|
+
graceMs?: number;
|
|
41
|
+
}
|
|
42
|
+
/** Context supplied to {@link StartManagedTestHostOptions.prepare}. */
|
|
43
|
+
export interface ManagedTestHostContext {
|
|
44
|
+
readonly port: number;
|
|
45
|
+
readonly scratch: string;
|
|
46
|
+
readonly databasePath: string;
|
|
47
|
+
}
|
|
48
|
+
/** Options for {@link startManagedTestHost}. */
|
|
49
|
+
export interface StartManagedTestHostOptions<TConfig> {
|
|
50
|
+
/** Prefix passed to `mkdtemp` in the OS temporary directory. */
|
|
51
|
+
scratchPrefix: string;
|
|
52
|
+
/** Filename of the SQLite database inside the scratch directory. Defaults to `auth.sqlite`. */
|
|
53
|
+
databaseFilename?: string;
|
|
54
|
+
/** Loopback host for port allocation. Defaults to `127.0.0.1`. */
|
|
55
|
+
host?: string;
|
|
56
|
+
/** Absolute path to the child entry script. */
|
|
57
|
+
entryPath: string;
|
|
58
|
+
/** Environment variable name used to pass the serialized JSON configuration to the child. */
|
|
59
|
+
envVar: string;
|
|
60
|
+
/** Maximum milliseconds to wait for the child's ready message. */
|
|
61
|
+
timeoutMs: number;
|
|
62
|
+
/** Optional abort signal to cancel preparation, startup or restart. */
|
|
63
|
+
signal?: AbortSignal;
|
|
64
|
+
/** Optional working directory for the child process. */
|
|
65
|
+
cwd?: string;
|
|
66
|
+
/** Optional Node execArgv passed to `fork`. */
|
|
67
|
+
execArgv?: string[];
|
|
68
|
+
/** Base environment for the child process. Defaults to `process.env`. */
|
|
69
|
+
env?: NodeJS.ProcessEnv;
|
|
70
|
+
/** Prefix for startup error messages (never includes config or secrets). */
|
|
71
|
+
errorPrefix?: string;
|
|
72
|
+
/** Grace period in milliseconds between SIGTERM and SIGKILL when stopping the child. */
|
|
73
|
+
graceMs?: number;
|
|
74
|
+
/** Build the child configuration once the scratch directory and loopback port are allocated. */
|
|
75
|
+
prepare(context: ManagedTestHostContext): Promise<TConfig> | TConfig;
|
|
76
|
+
/** Optional cleanup hook run in `close()` (and on startup failure) before removing the scratch directory. */
|
|
77
|
+
onClose?: () => Promise<void> | void;
|
|
78
|
+
}
|
|
79
|
+
/** Running test host with restart and idempotent scratch cleanup. */
|
|
80
|
+
export interface ManagedTestHost<TPayload extends object = Record<string, unknown>> {
|
|
81
|
+
readonly port: number;
|
|
82
|
+
readonly scratch: string;
|
|
83
|
+
readonly databasePath: string;
|
|
84
|
+
readonly ready: {
|
|
85
|
+
ready: true;
|
|
86
|
+
} & TPayload;
|
|
87
|
+
/** Stop the current child and start a new one against the same scratch directory and config. */
|
|
88
|
+
restart(timeoutMs?: number): Promise<{
|
|
89
|
+
ready: true;
|
|
90
|
+
} & TPayload>;
|
|
91
|
+
/** Stop the child, invoke `onClose`, and remove the scratch directory. Idempotent. */
|
|
92
|
+
close(): Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
/** Options for {@link listenTestHttpServer}. */
|
|
95
|
+
export interface ListenTestHttpServerOptions {
|
|
96
|
+
port: number;
|
|
97
|
+
host?: string;
|
|
98
|
+
handler: RequestListener;
|
|
99
|
+
tls?: {
|
|
100
|
+
cert: Buffer | string;
|
|
101
|
+
key: Buffer | string;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** Listening HTTP or HTTPS test server with connection-draining shutdown. */
|
|
105
|
+
export interface ListeningTestServer {
|
|
106
|
+
readonly server: HttpServer | HttpsServer;
|
|
107
|
+
close(): Promise<void>;
|
|
108
|
+
}
|
|
109
|
+
/** Runtime hooks for {@link runTestHostChild}, exposed so tests can exercise signal and IPC branches in-process. */
|
|
110
|
+
export interface TestHostChildRuntime {
|
|
111
|
+
env: NodeJS.ProcessEnv;
|
|
112
|
+
send(message: TestHostReadyMessage): void;
|
|
113
|
+
onSignal(signal: 'SIGTERM' | 'SIGINT', listener: () => void): void;
|
|
114
|
+
exit(code: number): void;
|
|
115
|
+
setExitCode(code: number): void;
|
|
116
|
+
}
|
|
117
|
+
/** Options for {@link runTestHostChild}. */
|
|
118
|
+
export interface RunTestHostChildOptions<TConfig, TPayload extends object = Record<string, unknown>> {
|
|
119
|
+
/** Environment variable holding the JSON-serialized configuration. Deleted immediately after reading. */
|
|
120
|
+
envVar: string;
|
|
121
|
+
/** Start the child server and return its ready payload and shutdown callback. */
|
|
122
|
+
start(config: TConfig): Promise<{
|
|
123
|
+
payload: TPayload;
|
|
124
|
+
close(): Promise<void> | void;
|
|
125
|
+
}>;
|
|
126
|
+
/**
|
|
127
|
+
* Whether to include the caught error message in `{ ready: false, message }`.
|
|
128
|
+
* Defaults to `false` so fixtures that handle sensitive config cannot leak it over IPC.
|
|
129
|
+
*/
|
|
130
|
+
includeErrorMessage?: boolean;
|
|
131
|
+
/** Optional process hooks, for unit testing. */
|
|
132
|
+
runtime?: TestHostChildRuntime;
|
|
133
|
+
}
|
|
134
|
+
/** Reserve an ephemeral TCP port on loopback (default `127.0.0.1`) and release it for the child to bind. */
|
|
135
|
+
export declare function allocateLoopbackPort(host?: string): Promise<number>;
|
|
136
|
+
/** Stop a child process with SIGTERM, escalating to SIGKILL after `graceMs` (default 1,000 ms). */
|
|
137
|
+
export declare function stopTestHostChild(child: ChildProcess, graceMs?: number): Promise<void>;
|
|
138
|
+
/** Fork a test-host child process, wait for its IPC ready message, and stop it if startup fails. */
|
|
139
|
+
export declare function startTestHostChild<TPayload extends object = Record<string, unknown>>(options: StartTestHostChildOptions): Promise<{
|
|
140
|
+
child: ChildProcess;
|
|
141
|
+
ready: {
|
|
142
|
+
ready: true;
|
|
143
|
+
} & TPayload;
|
|
144
|
+
}>;
|
|
145
|
+
/**
|
|
146
|
+
* Allocate a scratch directory and loopback port, prepare a child configuration, fork the test-host
|
|
147
|
+
* child, and return a handle with `restart()` and idempotent `close()`. Any failure during
|
|
148
|
+
* preparation or startup stops the child, runs `onClose`, and removes the scratch directory.
|
|
149
|
+
*/
|
|
150
|
+
export declare function startManagedTestHost<TConfig, TPayload extends object = Record<string, unknown>>(options: StartManagedTestHostOptions<TConfig>): Promise<ManagedTestHost<TPayload>>;
|
|
151
|
+
/**
|
|
152
|
+
* Open a test SQLite database via `node:sqlite`, enabling WAL mode and foreign keys.
|
|
153
|
+
* Loaded lazily so other helpers in this module work on Node 22.12; calling this helper
|
|
154
|
+
* requires Node 22.13+ (or 24+ without experimental warnings).
|
|
155
|
+
*/
|
|
156
|
+
export declare function openTestSqliteDatabase(databasePath: string): DatabaseSync;
|
|
157
|
+
/** Start an HTTP or HTTPS test server and return a handle whose `close()` drains all connections. */
|
|
158
|
+
export declare function listenTestHttpServer(options: ListenTestHttpServerOptions): Promise<ListeningTestServer>;
|
|
159
|
+
/**
|
|
160
|
+
* Bootstrap a forked test-host child process: read and immediately scrub its JSON config from
|
|
161
|
+
* `envVar`, run `start(config)`, register idempotent SIGTERM/SIGINT shutdown handlers, and notify
|
|
162
|
+
* the parent via IPC.
|
|
163
|
+
*/
|
|
164
|
+
export declare function runTestHostChild<TConfig, TPayload extends object = Record<string, unknown>>(options: RunTestHostChildOptions<TConfig, TPayload>): Promise<void>;
|
|
165
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,YAAY,EAA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|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shared Node-only test-host primitives for Better Auth fixtures (`@lushly-dev/afd-auth/testing`).
|
|
3
|
+
*
|
|
4
|
+
* Used by both `packages/auth/hosted/better-auth` and `@lushly-dev/loam-identity/testing` to manage
|
|
5
|
+
* disposable child-process auth servers, scratch directories, loopback ports, SQLite databases and
|
|
6
|
+
* HTTP/HTTPS listeners. Never imported from browser entries.
|
|
7
|
+
*/
|
|
8
|
+
import { fork } from 'node:child_process';
|
|
9
|
+
import { once } from 'node:events';
|
|
10
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
11
|
+
import { createServer as createHttpServer, } from 'node:http';
|
|
12
|
+
import { createServer as createHttpsServer } from 'node:https';
|
|
13
|
+
import { createRequire } from 'node:module';
|
|
14
|
+
import { createServer as createNetServer } from 'node:net';
|
|
15
|
+
import { tmpdir } from 'node:os';
|
|
16
|
+
import { join, resolve } from 'node:path';
|
|
17
|
+
const requireModule = createRequire(import.meta.url);
|
|
18
|
+
/** Reserve an ephemeral TCP port on loopback (default `127.0.0.1`) and release it for the child to bind. */
|
|
19
|
+
export async function allocateLoopbackPort(host = '127.0.0.1') {
|
|
20
|
+
const socket = createNetServer();
|
|
21
|
+
socket.listen(0, host);
|
|
22
|
+
await once(socket, 'listening');
|
|
23
|
+
const address = socket.address();
|
|
24
|
+
await new Promise((done) => socket.close(() => done()));
|
|
25
|
+
if (!address || typeof address === 'string')
|
|
26
|
+
throw new Error('Port allocation failed');
|
|
27
|
+
return address.port;
|
|
28
|
+
}
|
|
29
|
+
/** Stop a child process with SIGTERM, escalating to SIGKILL after `graceMs` (default 1,000 ms). */
|
|
30
|
+
export async function stopTestHostChild(child, graceMs = 1_000) {
|
|
31
|
+
if (!child.pid || child.exitCode !== null || child.signalCode !== null)
|
|
32
|
+
return;
|
|
33
|
+
const exited = once(child, 'exit');
|
|
34
|
+
child.kill('SIGTERM');
|
|
35
|
+
const timer = setTimeout(() => child.kill('SIGKILL'), graceMs);
|
|
36
|
+
try {
|
|
37
|
+
await exited;
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
clearTimeout(timer);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Fork a test-host child process, wait for its IPC ready message, and stop it if startup fails. */
|
|
44
|
+
export async function startTestHostChild(options) {
|
|
45
|
+
const prefix = options.errorPrefix ?? 'Test host startup';
|
|
46
|
+
if (options.signal?.aborted)
|
|
47
|
+
throw new Error(`${prefix} interrupted`);
|
|
48
|
+
const child = fork(options.entryPath, [], {
|
|
49
|
+
...(options.cwd ? { cwd: options.cwd } : {}),
|
|
50
|
+
...(options.execArgv ? { execArgv: options.execArgv } : {}),
|
|
51
|
+
env: { ...(options.env ?? process.env), [options.envVar]: JSON.stringify(options.config) },
|
|
52
|
+
stdio: ['ignore', 'ignore', 'ignore', 'ipc'],
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
const ready = await new Promise((resolveReady, reject) => {
|
|
56
|
+
let settled = false;
|
|
57
|
+
const finish = (action) => {
|
|
58
|
+
if (settled)
|
|
59
|
+
return;
|
|
60
|
+
settled = true;
|
|
61
|
+
clearTimeout(timer);
|
|
62
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
63
|
+
child.off('error', onError);
|
|
64
|
+
child.off('exit', onExit);
|
|
65
|
+
child.off('message', onMessage);
|
|
66
|
+
action();
|
|
67
|
+
};
|
|
68
|
+
const onAbort = () => finish(() => reject(new Error(`${prefix} interrupted`)));
|
|
69
|
+
const onError = () => finish(() => reject(new Error(`${prefix} launch failed`)));
|
|
70
|
+
const onExit = () => finish(() => reject(new Error(`${prefix} exited before ready`)));
|
|
71
|
+
const onMessage = (message) => {
|
|
72
|
+
finish(() => {
|
|
73
|
+
if (message?.ready) {
|
|
74
|
+
resolveReady(message);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const detail = message && !message.ready && typeof message.message === 'string' && message.message
|
|
78
|
+
? `: ${message.message}`
|
|
79
|
+
: ' failed';
|
|
80
|
+
reject(new Error(`${prefix}${detail}`));
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
const timer = setTimeout(() => finish(() => reject(new Error(`${prefix} deadline`))), options.timeoutMs);
|
|
84
|
+
options.signal?.addEventListener('abort', onAbort, { once: true });
|
|
85
|
+
child.once('error', onError);
|
|
86
|
+
child.once('exit', onExit);
|
|
87
|
+
child.once('message', onMessage);
|
|
88
|
+
});
|
|
89
|
+
return { child, ready };
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
const ignoreLateError = () => { };
|
|
93
|
+
child.on('error', ignoreLateError);
|
|
94
|
+
try {
|
|
95
|
+
await stopTestHostChild(child, options.graceMs);
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
child.off('error', ignoreLateError);
|
|
99
|
+
}
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Allocate a scratch directory and loopback port, prepare a child configuration, fork the test-host
|
|
105
|
+
* child, and return a handle with `restart()` and idempotent `close()`. Any failure during
|
|
106
|
+
* preparation or startup stops the child, runs `onClose`, and removes the scratch directory.
|
|
107
|
+
*/
|
|
108
|
+
export async function startManagedTestHost(options) {
|
|
109
|
+
options.signal?.throwIfAborted();
|
|
110
|
+
const scratch = await mkdtemp(resolve(tmpdir(), options.scratchPrefix));
|
|
111
|
+
const databasePath = join(scratch, options.databaseFilename ?? 'auth.sqlite');
|
|
112
|
+
const closeController = new AbortController();
|
|
113
|
+
const startSignal = options.signal
|
|
114
|
+
? AbortSignal.any([options.signal, closeController.signal])
|
|
115
|
+
: closeController.signal;
|
|
116
|
+
let child;
|
|
117
|
+
let pendingRestart;
|
|
118
|
+
let closePromise;
|
|
119
|
+
let config;
|
|
120
|
+
const close = () => {
|
|
121
|
+
closePromise ??= (async () => {
|
|
122
|
+
closeController.abort();
|
|
123
|
+
try {
|
|
124
|
+
await pendingRestart?.catch(() => { });
|
|
125
|
+
if (child) {
|
|
126
|
+
const running = child;
|
|
127
|
+
child = undefined;
|
|
128
|
+
await stopTestHostChild(running, options.graceMs);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
try {
|
|
133
|
+
await options.onClose?.();
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
await rm(scratch, { recursive: true, force: true });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
})();
|
|
140
|
+
return closePromise;
|
|
141
|
+
};
|
|
142
|
+
try {
|
|
143
|
+
const port = await allocateLoopbackPort(options.host);
|
|
144
|
+
options.signal?.throwIfAborted();
|
|
145
|
+
config = await options.prepare({ port, scratch, databasePath });
|
|
146
|
+
options.signal?.throwIfAborted();
|
|
147
|
+
const start = (timeoutMs) => startTestHostChild({
|
|
148
|
+
entryPath: options.entryPath,
|
|
149
|
+
envVar: options.envVar,
|
|
150
|
+
config,
|
|
151
|
+
timeoutMs,
|
|
152
|
+
signal: startSignal,
|
|
153
|
+
...(options.cwd ? { cwd: options.cwd } : {}),
|
|
154
|
+
...(options.execArgv ? { execArgv: options.execArgv } : {}),
|
|
155
|
+
...(options.env ? { env: options.env } : {}),
|
|
156
|
+
...(options.errorPrefix ? { errorPrefix: options.errorPrefix } : {}),
|
|
157
|
+
...(options.graceMs !== undefined ? { graceMs: options.graceMs } : {}),
|
|
158
|
+
});
|
|
159
|
+
const started = await start(options.timeoutMs);
|
|
160
|
+
child = started.child;
|
|
161
|
+
options.signal?.throwIfAborted();
|
|
162
|
+
let currentReady = started.ready;
|
|
163
|
+
return {
|
|
164
|
+
port,
|
|
165
|
+
scratch,
|
|
166
|
+
databasePath,
|
|
167
|
+
get ready() {
|
|
168
|
+
return currentReady;
|
|
169
|
+
},
|
|
170
|
+
restart(timeoutMs = options.timeoutMs) {
|
|
171
|
+
if (closePromise)
|
|
172
|
+
return Promise.reject(new Error('Test host is closed'));
|
|
173
|
+
if (pendingRestart) {
|
|
174
|
+
return Promise.reject(new Error('Test host restart already in progress'));
|
|
175
|
+
}
|
|
176
|
+
const run = (async () => {
|
|
177
|
+
try {
|
|
178
|
+
if (child) {
|
|
179
|
+
const previous = child;
|
|
180
|
+
child = undefined;
|
|
181
|
+
await stopTestHostChild(previous, options.graceMs);
|
|
182
|
+
}
|
|
183
|
+
if (closePromise)
|
|
184
|
+
throw new Error('Test host is closed');
|
|
185
|
+
const restarted = await start(timeoutMs);
|
|
186
|
+
if (closePromise) {
|
|
187
|
+
await stopTestHostChild(restarted.child, options.graceMs);
|
|
188
|
+
throw new Error('Test host is closed');
|
|
189
|
+
}
|
|
190
|
+
child = restarted.child;
|
|
191
|
+
currentReady = restarted.ready;
|
|
192
|
+
return currentReady;
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
pendingRestart = undefined;
|
|
196
|
+
}
|
|
197
|
+
})();
|
|
198
|
+
pendingRestart = run;
|
|
199
|
+
return run;
|
|
200
|
+
},
|
|
201
|
+
close,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
await close();
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Open a test SQLite database via `node:sqlite`, enabling WAL mode and foreign keys.
|
|
211
|
+
* Loaded lazily so other helpers in this module work on Node 22.12; calling this helper
|
|
212
|
+
* requires Node 22.13+ (or 24+ without experimental warnings).
|
|
213
|
+
*/
|
|
214
|
+
export function openTestSqliteDatabase(databasePath) {
|
|
215
|
+
const { DatabaseSync: SqliteDatabaseSync } = requireModule('node:sqlite');
|
|
216
|
+
const database = new SqliteDatabaseSync(databasePath);
|
|
217
|
+
try {
|
|
218
|
+
database.exec('PRAGMA journal_mode = WAL; PRAGMA foreign_keys = ON;');
|
|
219
|
+
return database;
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
database.close();
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/** Start an HTTP or HTTPS test server and return a handle whose `close()` drains all connections. */
|
|
227
|
+
export async function listenTestHttpServer(options) {
|
|
228
|
+
const server = options.tls
|
|
229
|
+
? createHttpsServer(options.tls, options.handler)
|
|
230
|
+
: createHttpServer(options.handler);
|
|
231
|
+
await new Promise((resolveListening, reject) => {
|
|
232
|
+
server.once('error', reject);
|
|
233
|
+
server.listen(options.port, options.host ?? '127.0.0.1', () => {
|
|
234
|
+
server.off('error', reject);
|
|
235
|
+
resolveListening();
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
return {
|
|
239
|
+
server,
|
|
240
|
+
async close() {
|
|
241
|
+
server.closeAllConnections();
|
|
242
|
+
await new Promise((resolveClose) => server.close(() => resolveClose()));
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
const defaultChildRuntime = {
|
|
247
|
+
env: process.env,
|
|
248
|
+
send: (message) => {
|
|
249
|
+
process.send?.(message);
|
|
250
|
+
},
|
|
251
|
+
onSignal: (signal, listener) => {
|
|
252
|
+
process.once(signal, listener);
|
|
253
|
+
},
|
|
254
|
+
exit: (code) => {
|
|
255
|
+
process.exit(code);
|
|
256
|
+
},
|
|
257
|
+
setExitCode: (code) => {
|
|
258
|
+
process.exitCode = code;
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* Bootstrap a forked test-host child process: read and immediately scrub its JSON config from
|
|
263
|
+
* `envVar`, run `start(config)`, register idempotent SIGTERM/SIGINT shutdown handlers, and notify
|
|
264
|
+
* the parent via IPC.
|
|
265
|
+
*/
|
|
266
|
+
export async function runTestHostChild(options) {
|
|
267
|
+
const runtime = options.runtime ?? defaultChildRuntime;
|
|
268
|
+
try {
|
|
269
|
+
const raw = runtime.env[options.envVar] ?? '';
|
|
270
|
+
delete runtime.env[options.envVar];
|
|
271
|
+
const config = JSON.parse(raw);
|
|
272
|
+
const started = await options.start(config);
|
|
273
|
+
let closing = false;
|
|
274
|
+
const shutdown = () => {
|
|
275
|
+
if (closing)
|
|
276
|
+
return;
|
|
277
|
+
closing = true;
|
|
278
|
+
void Promise.resolve()
|
|
279
|
+
.then(() => started.close())
|
|
280
|
+
.catch(() => { })
|
|
281
|
+
.finally(() => runtime.exit(0));
|
|
282
|
+
};
|
|
283
|
+
runtime.onSignal('SIGTERM', shutdown);
|
|
284
|
+
runtime.onSignal('SIGINT', shutdown);
|
|
285
|
+
runtime.send({ ...started.payload, ready: true });
|
|
286
|
+
}
|
|
287
|
+
catch (cause) {
|
|
288
|
+
runtime.send(options.includeErrorMessage
|
|
289
|
+
? { ready: false, message: String(cause?.message ?? cause) }
|
|
290
|
+
: { ready: false });
|
|
291
|
+
runtime.setExitCode(1);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAqB,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACN,YAAY,IAAI,gBAAgB,GAGhC,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAA8B,MAAM,YAAY,CAAC;AAC3F,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAG1C,MAAM,aAAa,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,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AC,CAAC;iBACf,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAClC,CAAC,CAAC;QACF,OAAO,CAAC,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,IAAI,CACX,OAAO,CAAC,mBAAmB;YAC1B,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAE,KAAe,EAAE,OAAO,IAAI,KAAK,CAAC,EAAE;YACvE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CACnB,CAAC;QACF,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lushly-dev/afd-auth",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Provider-agnostic authentication adapter for AFD applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
"./mock-capabilities": {
|
|
22
22
|
"types": "./dist/mock-capabilities.d.ts",
|
|
23
23
|
"import": "./dist/mock-capabilities.js"
|
|
24
|
+
},
|
|
25
|
+
"./testing": {
|
|
26
|
+
"types": "./dist/testing/index.d.ts",
|
|
27
|
+
"import": "./dist/testing/index.js"
|
|
24
28
|
}
|
|
25
29
|
},
|
|
26
30
|
"files": [
|
|
@@ -28,12 +32,12 @@
|
|
|
28
32
|
"README.md"
|
|
29
33
|
],
|
|
30
34
|
"dependencies": {
|
|
31
|
-
"@lushly-dev/afd-core": "3.
|
|
35
|
+
"@lushly-dev/afd-core": "3.1.0"
|
|
32
36
|
},
|
|
33
37
|
"peerDependencies": {
|
|
34
38
|
"@better-auth/passkey": "^1.7.18",
|
|
35
39
|
"@convex-dev/auth": ">=0.0.95 <3",
|
|
36
|
-
"@lushly-dev/afd-server": "^3.
|
|
40
|
+
"@lushly-dev/afd-server": "^3.1.0",
|
|
37
41
|
"better-auth": "^1.7.18",
|
|
38
42
|
"react": "^18.0.0 || ^19.0.0",
|
|
39
43
|
"zod": "^4.6.6"
|
|
@@ -60,22 +64,23 @@
|
|
|
60
64
|
},
|
|
61
65
|
"devDependencies": {
|
|
62
66
|
"@auth/core": "^0.41.3",
|
|
63
|
-
"@convex-dev/auth
|
|
64
|
-
"@
|
|
65
|
-
"@
|
|
67
|
+
"@convex-dev/auth": "2.1.0",
|
|
68
|
+
"@convex-dev/auth-v0": "npm:@convex-dev/auth@0.0.96",
|
|
69
|
+
"@better-auth/passkey": "1.7.28",
|
|
70
|
+
"@lushly-dev/afd-server": "3.1.0",
|
|
66
71
|
"@testing-library/react": "^16.3.3",
|
|
67
|
-
"@types/react": "^19.3.
|
|
72
|
+
"@types/react": "^19.3.3",
|
|
68
73
|
"@types/react-dom": "19.3.0",
|
|
69
|
-
"@vitest/coverage-v8": "^5.1.
|
|
70
|
-
"better-auth": "1.7.
|
|
74
|
+
"@vitest/coverage-v8": "^5.1.2",
|
|
75
|
+
"better-auth": "1.7.28",
|
|
71
76
|
"convex": "1.51.0",
|
|
72
77
|
"esbuild": "0.28.2",
|
|
73
78
|
"jsdom": "^31.0.1",
|
|
74
|
-
"playwright": "1.
|
|
79
|
+
"playwright": "1.65.1",
|
|
75
80
|
"react": "^19.3.0",
|
|
76
81
|
"react-dom": "^19.3.0",
|
|
77
82
|
"typescript": "^7.0.2",
|
|
78
|
-
"vitest": "^5.1.
|
|
83
|
+
"vitest": "^5.1.2",
|
|
79
84
|
"zod": "^4.6.6"
|
|
80
85
|
},
|
|
81
86
|
"keywords": [
|
|
@@ -104,7 +109,7 @@
|
|
|
104
109
|
"access": "public"
|
|
105
110
|
},
|
|
106
111
|
"scripts": {
|
|
107
|
-
"build": "tsc",
|
|
112
|
+
"build": "tsc && tsc -p tsconfig.testing.json",
|
|
108
113
|
"typecheck": "tsc -p tsconfig.typecheck.json",
|
|
109
114
|
"dev": "tsc --watch",
|
|
110
115
|
"test": "vitest run",
|