@hot-updater/test-utils 1.0.0-rc.15
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/LICENSE +33 -0
- package/README.md +64 -0
- package/dist/index.d.mts +452 -0
- package/dist/index.mjs +3569 -0
- package/dist/node.cjs +20442 -0
- package/dist/node.d.cts +107 -0
- package/dist/node.d.mts +107 -0
- package/dist/node.mjs +20392 -0
- package/package.json +91 -0
package/dist/node.d.cts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ChildProcessByStdio } from "node:child_process";
|
|
2
|
+
import { Readable } from "node:stream";
|
|
3
|
+
import { ArtifactInfo } from "@hot-updater/core";
|
|
4
|
+
import { BundleRow, StoragePlugin } from "@hot-updater/plugin-core";
|
|
5
|
+
import { execa } from "execa";
|
|
6
|
+
//#region src/mockReactNativeProjectRoot.d.ts
|
|
7
|
+
interface MockedReactNativeProjectRoot {
|
|
8
|
+
rootDir: string;
|
|
9
|
+
}
|
|
10
|
+
type Example = "rn-77";
|
|
11
|
+
declare const mockReactNativeProjectRoot: ({ example }: {
|
|
12
|
+
example: Example;
|
|
13
|
+
}) => Promise<MockedReactNativeProjectRoot>;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/runtimeProcess.d.ts
|
|
16
|
+
type RuntimeChild = ChildProcessByStdio<null, Readable, Readable>;
|
|
17
|
+
interface RuntimeLogs {
|
|
18
|
+
stdout: string[];
|
|
19
|
+
stderr: string[];
|
|
20
|
+
}
|
|
21
|
+
interface SpawnRuntimeOptions {
|
|
22
|
+
command: string;
|
|
23
|
+
args: string[];
|
|
24
|
+
cwd: string;
|
|
25
|
+
env?: Record<string, string | undefined>;
|
|
26
|
+
}
|
|
27
|
+
declare const runCheckedCommand: ({ command, args, cwd, env }: SpawnRuntimeOptions) => void;
|
|
28
|
+
declare const hasCommand: (command: string, args: string[]) => boolean;
|
|
29
|
+
declare const hasDockerDaemon: () => boolean;
|
|
30
|
+
declare const hasDockerCompose: () => boolean;
|
|
31
|
+
declare const assertCommandAvailable: (command: string, args: string[], message?: string) => void;
|
|
32
|
+
declare const assertDockerDaemonAvailable: (message?: string) => void;
|
|
33
|
+
declare const assertDockerComposeAvailable: (message?: string) => void;
|
|
34
|
+
declare const assertEnvFlagEnabled: (name: string, message?: string) => void;
|
|
35
|
+
declare const findOpenPort: () => Promise<number>;
|
|
36
|
+
declare const spawnRuntime: ({ command, args, cwd, env }: SpawnRuntimeOptions) => {
|
|
37
|
+
child: RuntimeChild;
|
|
38
|
+
logs: RuntimeLogs;
|
|
39
|
+
};
|
|
40
|
+
declare const waitForHttpOk: ({ url, child, logs, timeoutMs }: {
|
|
41
|
+
url: string;
|
|
42
|
+
child: RuntimeChild;
|
|
43
|
+
logs: RuntimeLogs;
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
}) => Promise<void>;
|
|
46
|
+
declare const stopRuntime: (child: RuntimeChild) => Promise<void>;
|
|
47
|
+
declare const formatRuntimeLogs: (logs: RuntimeLogs) => string;
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/httpTestClient.d.ts
|
|
50
|
+
type HttpTestRequestInit = NonNullable<ConstructorParameters<typeof Request>[1]>;
|
|
51
|
+
type HttpTestRequest = (path: string, init?: HttpTestRequestInit) => Promise<Response>;
|
|
52
|
+
interface HttpTestClient {
|
|
53
|
+
readonly client: HttpTestRequest;
|
|
54
|
+
readonly admin: HttpTestRequest;
|
|
55
|
+
}
|
|
56
|
+
interface HttpTestServer extends HttpTestClient {
|
|
57
|
+
readonly close: () => Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
type HttpTestHandlers = Record<"client" | "admin", (request: Request) => Promise<Response>>;
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/httpTestServer.d.ts
|
|
62
|
+
/** Serve Web handlers over loopback TCP; contract tests use real fetch requests. */
|
|
63
|
+
declare function startHttpTestServer(handlers: HttpTestHandlers): Promise<HttpTestServer>;
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/releaseCatalogHttpFixtures.d.ts
|
|
66
|
+
declare const releaseCatalogDownloadUrl: (uri: string) => string;
|
|
67
|
+
declare const RELEASE_CATALOG_MANIFEST_URIS: {
|
|
68
|
+
small: string;
|
|
69
|
+
large: string;
|
|
70
|
+
};
|
|
71
|
+
declare const RELEASE_CATALOG_DOWNLOAD_HASH: string;
|
|
72
|
+
declare const releaseCatalogArtifact: (bundle: BundleRow) => ArtifactInfo;
|
|
73
|
+
/** Install these storage objects in the test server, independently of its DB. */
|
|
74
|
+
declare const RELEASE_CATALOG_STORAGE_FIXTURES: Readonly<Record<string, string>>;
|
|
75
|
+
/** Storage boundary shared by provider and separately spawned server tests. */
|
|
76
|
+
declare const createReleaseCatalogTestStorage: () => StoragePlugin;
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/setupHandlerIntegrationTestSuite.d.ts
|
|
79
|
+
declare const TEST_ADMIN_AUTH_TOKEN = "hot-updater-test-token";
|
|
80
|
+
/**
|
|
81
|
+
* Kills any process using the specified port
|
|
82
|
+
*/
|
|
83
|
+
declare function killPort(port: number): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Helper to wait for server to be ready
|
|
86
|
+
*/
|
|
87
|
+
declare function waitForServer(url: string, maxAttempts?: number): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Creates test database path with timestamp isolation
|
|
90
|
+
*/
|
|
91
|
+
declare function createTestDbPath(projectRoot: string): string;
|
|
92
|
+
/**
|
|
93
|
+
* Spawns a server process for testing
|
|
94
|
+
*/
|
|
95
|
+
declare function spawnServerProcess(options: {
|
|
96
|
+
serverCommand: string[];
|
|
97
|
+
port: number;
|
|
98
|
+
testDbPath: string;
|
|
99
|
+
projectRoot: string;
|
|
100
|
+
env?: Record<string, string>;
|
|
101
|
+
}): ReturnType<typeof execa>;
|
|
102
|
+
/**
|
|
103
|
+
* Cleans up server process and test database
|
|
104
|
+
*/
|
|
105
|
+
declare function cleanupServer(baseUrl: string, serverProcess: ReturnType<typeof execa> | null, testDbPath: string): Promise<void>;
|
|
106
|
+
//#endregion
|
|
107
|
+
export { MockedReactNativeProjectRoot, RELEASE_CATALOG_DOWNLOAD_HASH, RELEASE_CATALOG_MANIFEST_URIS, RELEASE_CATALOG_STORAGE_FIXTURES, RuntimeChild, RuntimeLogs, SpawnRuntimeOptions, TEST_ADMIN_AUTH_TOKEN, assertCommandAvailable, assertDockerComposeAvailable, assertDockerDaemonAvailable, assertEnvFlagEnabled, cleanupServer, createReleaseCatalogTestStorage, createTestDbPath, findOpenPort, formatRuntimeLogs, hasCommand, hasDockerCompose, hasDockerDaemon, killPort, mockReactNativeProjectRoot, releaseCatalogArtifact, releaseCatalogDownloadUrl, runCheckedCommand, spawnRuntime, spawnServerProcess, startHttpTestServer, stopRuntime, waitForHttpOk, waitForServer };
|
package/dist/node.d.mts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ChildProcessByStdio } from "node:child_process";
|
|
2
|
+
import { execa } from "execa";
|
|
3
|
+
import { Readable } from "node:stream";
|
|
4
|
+
import { ArtifactInfo } from "@hot-updater/core";
|
|
5
|
+
import { BundleRow, StoragePlugin } from "@hot-updater/plugin-core";
|
|
6
|
+
//#region src/mockReactNativeProjectRoot.d.ts
|
|
7
|
+
interface MockedReactNativeProjectRoot {
|
|
8
|
+
rootDir: string;
|
|
9
|
+
}
|
|
10
|
+
type Example = "rn-77";
|
|
11
|
+
declare const mockReactNativeProjectRoot: ({ example }: {
|
|
12
|
+
example: Example;
|
|
13
|
+
}) => Promise<MockedReactNativeProjectRoot>;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/runtimeProcess.d.ts
|
|
16
|
+
type RuntimeChild = ChildProcessByStdio<null, Readable, Readable>;
|
|
17
|
+
interface RuntimeLogs {
|
|
18
|
+
stdout: string[];
|
|
19
|
+
stderr: string[];
|
|
20
|
+
}
|
|
21
|
+
interface SpawnRuntimeOptions {
|
|
22
|
+
command: string;
|
|
23
|
+
args: string[];
|
|
24
|
+
cwd: string;
|
|
25
|
+
env?: Record<string, string | undefined>;
|
|
26
|
+
}
|
|
27
|
+
declare const runCheckedCommand: ({ command, args, cwd, env }: SpawnRuntimeOptions) => void;
|
|
28
|
+
declare const hasCommand: (command: string, args: string[]) => boolean;
|
|
29
|
+
declare const hasDockerDaemon: () => boolean;
|
|
30
|
+
declare const hasDockerCompose: () => boolean;
|
|
31
|
+
declare const assertCommandAvailable: (command: string, args: string[], message?: string) => void;
|
|
32
|
+
declare const assertDockerDaemonAvailable: (message?: string) => void;
|
|
33
|
+
declare const assertDockerComposeAvailable: (message?: string) => void;
|
|
34
|
+
declare const assertEnvFlagEnabled: (name: string, message?: string) => void;
|
|
35
|
+
declare const findOpenPort: () => Promise<number>;
|
|
36
|
+
declare const spawnRuntime: ({ command, args, cwd, env }: SpawnRuntimeOptions) => {
|
|
37
|
+
child: RuntimeChild;
|
|
38
|
+
logs: RuntimeLogs;
|
|
39
|
+
};
|
|
40
|
+
declare const waitForHttpOk: ({ url, child, logs, timeoutMs }: {
|
|
41
|
+
url: string;
|
|
42
|
+
child: RuntimeChild;
|
|
43
|
+
logs: RuntimeLogs;
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
}) => Promise<void>;
|
|
46
|
+
declare const stopRuntime: (child: RuntimeChild) => Promise<void>;
|
|
47
|
+
declare const formatRuntimeLogs: (logs: RuntimeLogs) => string;
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/httpTestClient.d.ts
|
|
50
|
+
type HttpTestRequestInit = NonNullable<ConstructorParameters<typeof Request>[1]>;
|
|
51
|
+
type HttpTestRequest = (path: string, init?: HttpTestRequestInit) => Promise<Response>;
|
|
52
|
+
interface HttpTestClient {
|
|
53
|
+
readonly client: HttpTestRequest;
|
|
54
|
+
readonly admin: HttpTestRequest;
|
|
55
|
+
}
|
|
56
|
+
interface HttpTestServer extends HttpTestClient {
|
|
57
|
+
readonly close: () => Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
type HttpTestHandlers = Record<"client" | "admin", (request: Request) => Promise<Response>>;
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/httpTestServer.d.ts
|
|
62
|
+
/** Serve Web handlers over loopback TCP; contract tests use real fetch requests. */
|
|
63
|
+
declare function startHttpTestServer(handlers: HttpTestHandlers): Promise<HttpTestServer>;
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/releaseCatalogHttpFixtures.d.ts
|
|
66
|
+
declare const releaseCatalogDownloadUrl: (uri: string) => string;
|
|
67
|
+
declare const RELEASE_CATALOG_MANIFEST_URIS: {
|
|
68
|
+
small: string;
|
|
69
|
+
large: string;
|
|
70
|
+
};
|
|
71
|
+
declare const RELEASE_CATALOG_DOWNLOAD_HASH: string;
|
|
72
|
+
declare const releaseCatalogArtifact: (bundle: BundleRow) => ArtifactInfo;
|
|
73
|
+
/** Install these storage objects in the test server, independently of its DB. */
|
|
74
|
+
declare const RELEASE_CATALOG_STORAGE_FIXTURES: Readonly<Record<string, string>>;
|
|
75
|
+
/** Storage boundary shared by provider and separately spawned server tests. */
|
|
76
|
+
declare const createReleaseCatalogTestStorage: () => StoragePlugin;
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/setupHandlerIntegrationTestSuite.d.ts
|
|
79
|
+
declare const TEST_ADMIN_AUTH_TOKEN = "hot-updater-test-token";
|
|
80
|
+
/**
|
|
81
|
+
* Kills any process using the specified port
|
|
82
|
+
*/
|
|
83
|
+
declare function killPort(port: number): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Helper to wait for server to be ready
|
|
86
|
+
*/
|
|
87
|
+
declare function waitForServer(url: string, maxAttempts?: number): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Creates test database path with timestamp isolation
|
|
90
|
+
*/
|
|
91
|
+
declare function createTestDbPath(projectRoot: string): string;
|
|
92
|
+
/**
|
|
93
|
+
* Spawns a server process for testing
|
|
94
|
+
*/
|
|
95
|
+
declare function spawnServerProcess(options: {
|
|
96
|
+
serverCommand: string[];
|
|
97
|
+
port: number;
|
|
98
|
+
testDbPath: string;
|
|
99
|
+
projectRoot: string;
|
|
100
|
+
env?: Record<string, string>;
|
|
101
|
+
}): ReturnType<typeof execa>;
|
|
102
|
+
/**
|
|
103
|
+
* Cleans up server process and test database
|
|
104
|
+
*/
|
|
105
|
+
declare function cleanupServer(baseUrl: string, serverProcess: ReturnType<typeof execa> | null, testDbPath: string): Promise<void>;
|
|
106
|
+
//#endregion
|
|
107
|
+
export { MockedReactNativeProjectRoot, RELEASE_CATALOG_DOWNLOAD_HASH, RELEASE_CATALOG_MANIFEST_URIS, RELEASE_CATALOG_STORAGE_FIXTURES, RuntimeChild, RuntimeLogs, SpawnRuntimeOptions, TEST_ADMIN_AUTH_TOKEN, assertCommandAvailable, assertDockerComposeAvailable, assertDockerDaemonAvailable, assertEnvFlagEnabled, cleanupServer, createReleaseCatalogTestStorage, createTestDbPath, findOpenPort, formatRuntimeLogs, hasCommand, hasDockerCompose, hasDockerDaemon, killPort, mockReactNativeProjectRoot, releaseCatalogArtifact, releaseCatalogDownloadUrl, runCheckedCommand, spawnRuntime, spawnServerProcess, startHttpTestServer, stopRuntime, waitForHttpOk, waitForServer };
|