@livestore/utils-dev 0.4.0-dev.7 → 0.4.0-dev.8

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.
Files changed (68) hide show
  1. package/dist/.tsbuildinfo.json +1 -1
  2. package/dist/node/DockerComposeService/DockerComposeService.d.ts +14 -4
  3. package/dist/node/DockerComposeService/DockerComposeService.d.ts.map +1 -1
  4. package/dist/node/DockerComposeService/DockerComposeService.js +27 -10
  5. package/dist/node/DockerComposeService/DockerComposeService.js.map +1 -1
  6. package/dist/node/mod.d.ts +0 -2
  7. package/dist/node/mod.d.ts.map +1 -1
  8. package/dist/node/mod.js +0 -2
  9. package/dist/node/mod.js.map +1 -1
  10. package/dist/node-vitest/Vitest.d.ts +6 -6
  11. package/dist/node-vitest/Vitest.d.ts.map +1 -1
  12. package/dist/node-vitest/Vitest.js +2 -2
  13. package/dist/node-vitest/Vitest.js.map +1 -1
  14. package/dist/node-vitest/Vitest.test.js +12 -1
  15. package/dist/node-vitest/Vitest.test.js.map +1 -1
  16. package/dist/{node/WranglerDevServer → wrangler}/WranglerDevServer.d.ts +6 -6
  17. package/dist/wrangler/WranglerDevServer.d.ts.map +1 -0
  18. package/dist/wrangler/WranglerDevServer.js +90 -0
  19. package/dist/wrangler/WranglerDevServer.js.map +1 -0
  20. package/dist/wrangler/WranglerDevServer.test.d.ts.map +1 -0
  21. package/dist/wrangler/WranglerDevServer.test.js +77 -0
  22. package/dist/wrangler/WranglerDevServer.test.js.map +1 -0
  23. package/dist/wrangler/fixtures/cf-worker.d.ts.map +1 -0
  24. package/dist/wrangler/fixtures/cf-worker.js.map +1 -0
  25. package/dist/wrangler/mod.d.ts +2 -0
  26. package/dist/wrangler/mod.d.ts.map +1 -0
  27. package/dist/wrangler/mod.js +2 -0
  28. package/dist/wrangler/mod.js.map +1 -0
  29. package/package.json +7 -4
  30. package/src/node/DockerComposeService/DockerComposeService.ts +50 -10
  31. package/src/node/mod.ts +0 -7
  32. package/src/node-vitest/Vitest.test.ts +12 -1
  33. package/src/node-vitest/Vitest.ts +31 -19
  34. package/src/wrangler/WranglerDevServer.test.ts +133 -0
  35. package/src/wrangler/WranglerDevServer.ts +180 -0
  36. package/src/wrangler/mod.ts +6 -0
  37. package/dist/node/WranglerDevServer/WranglerDevServer.d.ts.map +0 -1
  38. package/dist/node/WranglerDevServer/WranglerDevServer.js +0 -122
  39. package/dist/node/WranglerDevServer/WranglerDevServer.js.map +0 -1
  40. package/dist/node/WranglerDevServer/WranglerDevServer.test.d.ts.map +0 -1
  41. package/dist/node/WranglerDevServer/WranglerDevServer.test.js +0 -179
  42. package/dist/node/WranglerDevServer/WranglerDevServer.test.js.map +0 -1
  43. package/dist/node/WranglerDevServer/fixtures/cf-worker.d.ts.map +0 -1
  44. package/dist/node/WranglerDevServer/fixtures/cf-worker.js.map +0 -1
  45. package/dist/node/WranglerDevServer/process-tree-manager.d.ts +0 -55
  46. package/dist/node/WranglerDevServer/process-tree-manager.d.ts.map +0 -1
  47. package/dist/node/WranglerDevServer/process-tree-manager.js +0 -178
  48. package/dist/node/WranglerDevServer/process-tree-manager.js.map +0 -1
  49. package/dist/node/vitest-docker-compose-setup.d.ts +0 -32
  50. package/dist/node/vitest-docker-compose-setup.d.ts.map +0 -1
  51. package/dist/node/vitest-docker-compose-setup.js +0 -131
  52. package/dist/node/vitest-docker-compose-setup.js.map +0 -1
  53. package/dist/node/vitest-wrangler-setup.d.ts +0 -27
  54. package/dist/node/vitest-wrangler-setup.d.ts.map +0 -1
  55. package/dist/node/vitest-wrangler-setup.js +0 -96
  56. package/dist/node/vitest-wrangler-setup.js.map +0 -1
  57. package/dist/node-vitest/polyfill.d.ts +0 -2
  58. package/dist/node-vitest/polyfill.d.ts.map +0 -1
  59. package/dist/node-vitest/polyfill.js +0 -3
  60. package/dist/node-vitest/polyfill.js.map +0 -1
  61. package/src/node/WranglerDevServer/WranglerDevServer.test.ts +0 -266
  62. package/src/node/WranglerDevServer/WranglerDevServer.ts +0 -266
  63. package/src/node/WranglerDevServer/process-tree-manager.ts +0 -263
  64. /package/dist/{node/WranglerDevServer → wrangler}/WranglerDevServer.test.d.ts +0 -0
  65. /package/dist/{node/WranglerDevServer → wrangler}/fixtures/cf-worker.d.ts +0 -0
  66. /package/dist/{node/WranglerDevServer → wrangler}/fixtures/cf-worker.js +0 -0
  67. /package/src/{node/WranglerDevServer → wrangler}/fixtures/cf-worker.ts +0 -0
  68. /package/src/{node/WranglerDevServer → wrangler}/fixtures/wrangler.toml +0 -0
@@ -1,131 +0,0 @@
1
- import { spawn } from 'node:child_process';
2
- import path from 'node:path';
3
- import { Effect, UnknownError } from '@livestore/utils/effect';
4
- import { cmd } from "./cmd.js";
5
- export const startDockerComposeServices = (args) => Effect.tryPromise({
6
- try: () => startDockerComposeServicesPromise(args),
7
- catch: (error) => UnknownError.make({ cause: new Error(`Failed to start Docker Compose: ${error}`) }),
8
- }).pipe(Effect.withSpan('startDockerComposeServices'));
9
- export const pullDockerComposeImages = ({ cwd, composeFilePath, }) => Effect.gen(function* () {
10
- const resolvedComposeFilePath = path.resolve(composeFilePath ?? path.join(cwd, 'docker-compose.yml'));
11
- yield* cmd(['docker', 'compose', '-f', resolvedComposeFilePath, 'pull'], { cwd });
12
- }).pipe(Effect.withSpan('pullDockerComposeImages'));
13
- /**
14
- * Starts Docker Compose services for testing with automatic cleanup.
15
- * Automatically allocates a free port and passes it as EXPOSED_PORT environment variable.
16
- *
17
- * @param composeFilePath - Path to docker-compose.yml file (defaults to `${cwd}/docker-compose.yml`)
18
- * @param cwd - Working directory for Docker Compose commands
19
- * @param env - Environment variables to pass to the Docker Compose commands (useful for passing ports)
20
- * @param serviceName - Optional specific service to start (omit to start all)
21
- * @param waitForLog - Log pattern to wait for before considering services ready
22
- * @param healthCheck - Health check configuration for waiting until service is ready
23
- */
24
- // TODO refactor implementation with Effect
25
- // TODO add test for this
26
- export const startDockerComposeServicesPromise = async ({ composeFilePath, cwd, serviceName, waitForLog, healthCheck, env, forwardLogs = false, }) => {
27
- let dockerComposeProcess;
28
- const setup = async () => {
29
- const resolvedComposeFilePath = path.resolve(composeFilePath ?? path.join(cwd, 'docker-compose.yml'));
30
- // Build the docker compose command arguments
31
- const composeArgs = ['compose', '-f', resolvedComposeFilePath, 'up'];
32
- // Add service name if specified
33
- if (serviceName) {
34
- composeArgs.push(serviceName);
35
- }
36
- dockerComposeProcess = spawn('docker', composeArgs, {
37
- stdio: ['ignore', 'pipe', 'pipe'],
38
- cwd,
39
- env: { ...process.env, ...env },
40
- });
41
- dockerComposeProcess.stdout?.setEncoding('utf8');
42
- dockerComposeProcess.stderr?.setEncoding('utf8');
43
- if (forwardLogs) {
44
- dockerComposeProcess.stdout?.on('data', (data) => {
45
- console.log(data);
46
- });
47
- dockerComposeProcess.stderr?.on('data', (data) => {
48
- console.error(data);
49
- });
50
- }
51
- // Wait for the service to be ready
52
- if (healthCheck) {
53
- // Use health check approach
54
- const maxAttempts = healthCheck.maxAttempts ?? 30;
55
- const delayMs = healthCheck.delayMs ?? 1000;
56
- const expectedStatus = healthCheck.expectedStatus ?? 200;
57
- const healthUrl = healthCheck.url;
58
- console.log(`Waiting for health check at ${healthUrl}...`);
59
- for (let attempt = 1; attempt <= maxAttempts; attempt++) {
60
- try {
61
- const response = await fetch(healthUrl);
62
- if (response.status === expectedStatus) {
63
- console.log(`Health check passed after ${attempt} attempts`);
64
- break;
65
- }
66
- console.log(`Health check attempt ${attempt}/${maxAttempts}: status ${response.status}`);
67
- }
68
- catch (error) {
69
- console.log(`Health check attempt ${attempt}/${maxAttempts}: ${error instanceof Error ? error.message : 'failed'}`);
70
- }
71
- if (attempt === maxAttempts) {
72
- throw new Error(`Health check failed after ${maxAttempts} attempts at ${healthUrl}`);
73
- }
74
- await new Promise((resolve) => setTimeout(resolve, delayMs));
75
- }
76
- }
77
- else if (waitForLog) {
78
- // Fallback to log-based waiting
79
- await new Promise((resolve) => {
80
- const onData = (data) => {
81
- if (data.includes(waitForLog)) {
82
- dockerComposeProcess?.stdout?.off('data', onData);
83
- resolve();
84
- }
85
- };
86
- dockerComposeProcess?.stdout?.on('data', onData);
87
- dockerComposeProcess?.stderr?.on('data', onData);
88
- });
89
- }
90
- else {
91
- // No wait condition, just give it a moment to start
92
- await new Promise((resolve) => setTimeout(resolve, 2000));
93
- }
94
- console.log(`Docker Compose services ready${serviceName ? ` (${serviceName})` : ''}`);
95
- };
96
- const stopDockerComposeServices = async () => {
97
- if (dockerComposeProcess) {
98
- console.log('Stopping Docker Compose services...');
99
- const resolvedComposeFilePath = path.resolve(composeFilePath ?? path.join(cwd, 'docker-compose.yml'));
100
- // Use docker compose down to properly stop and clean up
101
- const downProcess = spawn('docker', ['compose', '-f', resolvedComposeFilePath, 'down'], {
102
- stdio: 'inherit',
103
- cwd,
104
- });
105
- await new Promise((resolve) => {
106
- downProcess.on('close', () => {
107
- resolve();
108
- });
109
- });
110
- dockerComposeProcess.kill('SIGTERM');
111
- dockerComposeProcess = undefined;
112
- }
113
- };
114
- process.on('exit', () => {
115
- stopDockerComposeServices();
116
- });
117
- process.on('SIGINT', () => {
118
- stopDockerComposeServices();
119
- });
120
- process.on('SIGTERM', () => {
121
- stopDockerComposeServices();
122
- });
123
- // try {
124
- // const { afterAll } = await import('vitest')
125
- // afterAll(async () => {
126
- // await stopDockerComposeServices()
127
- // })
128
- // } catch {}
129
- await setup();
130
- };
131
- //# sourceMappingURL=vitest-docker-compose-setup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vitest-docker-compose-setup.js","sourceRoot":"","sources":["../../src/node/vitest-docker-compose-setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B,MAAM,CAAC,MAAM,0BA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ClC,CAAC;IACH,CAAC,CAAA;IAED,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;QACtB,yBAAyB,EAAE,CAAA;IAC7B,CAAC,CAAC,CAAA;IACF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QACxB,yBAAyB,EAAE,CAAA;IAC7B,CAAC,CAAC,CAAA;IACF,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;QACzB,yBAAyB,EAAE,CAAA;IAC7B,CAAC,CAAC,CAAA;IAEF,QAAQ;IACR,gDAAgD;IAChD,2BAA2B;IAC3B,wCAAwC;IACxC,OAAO;IACP,aAAa;IAEb,MAAM,KAAK,EAAE,CAAA;AACf,CAAC,CAAA"}
@@ -1,27 +0,0 @@
1
- import { Effect, UnknownError } from '@livestore/utils/effect';
2
- export type StartWranglerDevServerArgs = {
3
- wranglerConfigPath?: string;
4
- cwd: string;
5
- port?: number;
6
- };
7
- export declare const startWranglerDevServer: (args: StartWranglerDevServerArgs) => Effect.Effect<{
8
- port: number;
9
- kill: () => void;
10
- }, UnknownError, never>;
11
- /**
12
- * Starts a Wrangler dev server for testing with automatic cleanup.
13
- *
14
- * @param wranglerConfigPath - Path to wrangler.toml file (defaults to `${cwd}/wrangler.toml`)
15
- * @param cwd - Working directory for Wrangler commands
16
- * @returns Object with allocated port for the dev server
17
- */
18
- export declare const startWranglerDevServerPromise: ({ wranglerConfigPath, abortSignal, cwd, port: inputPort, }: {
19
- wranglerConfigPath?: string;
20
- abortSignal?: AbortSignal;
21
- cwd: string;
22
- port?: number;
23
- }) => Promise<{
24
- port: number;
25
- kill: () => void;
26
- }>;
27
- //# sourceMappingURL=vitest-wrangler-setup.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vitest-wrangler-setup.d.ts","sourceRoot":"","sources":["../../src/node/vitest-wrangler-setup.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAE9D,MAAM,MAAM,0BAA0B,GAAG;IACvC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,MAAM,0BAA0B;;;uBAInB,CAAA;AAMpD;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,GAAU,4DAKjD;IACD,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;;;EA6FA,CAAA"}
@@ -1,96 +0,0 @@
1
- import { spawn } from 'node:child_process';
2
- import net from 'node:net';
3
- import path from 'node:path';
4
- import { Effect, UnknownError } from '@livestore/utils/effect';
5
- export const startWranglerDevServer = (args) => Effect.tryPromise({
6
- try: (abortSignal) => startWranglerDevServerPromise({ ...args, abortSignal }),
7
- catch: (error) => UnknownError.make({ cause: new Error(`Failed to start Wrangler: ${error}`) }),
8
- }).pipe(Effect.withSpan('startWranglerDevServer'));
9
- // TODO refactor implementation with Effect
10
- // TODO add test for this
11
- // TODO allow for config to be passed in via code instead of `wrangler.toml` file
12
- // TODO fix zombie workerd processes causing high CPU usage - see https://github.com/livestorejs/livestore/issues/568
13
- /**
14
- * Starts a Wrangler dev server for testing with automatic cleanup.
15
- *
16
- * @param wranglerConfigPath - Path to wrangler.toml file (defaults to `${cwd}/wrangler.toml`)
17
- * @param cwd - Working directory for Wrangler commands
18
- * @returns Object with allocated port for the dev server
19
- */
20
- export const startWranglerDevServerPromise = async ({ wranglerConfigPath, abortSignal, cwd, port: inputPort, }) => {
21
- let wranglerProcess;
22
- const getFreePort = () => {
23
- return new Promise((resolve, reject) => {
24
- const server = net.createServer();
25
- server.listen(0, () => {
26
- const port = server.address()?.port;
27
- server.close(() => {
28
- if (port) {
29
- resolve(port);
30
- }
31
- else {
32
- reject(new Error('Could not get port'));
33
- }
34
- });
35
- });
36
- server.on('error', reject);
37
- });
38
- };
39
- const setup = async () => {
40
- const syncPort = inputPort ?? (await getFreePort());
41
- const resolvedWranglerConfigPath = path.resolve(wranglerConfigPath ?? path.join(cwd, 'wrangler.toml'));
42
- wranglerProcess = spawn('bunx', ['wrangler', 'dev', '--port', syncPort.toString(), '--config', resolvedWranglerConfigPath], {
43
- stdio: ['ignore', 'pipe', 'pipe'],
44
- cwd,
45
- env: {
46
- ...process.env,
47
- // NODE_OPTIONS: '--inspect --inspect-port=9233',
48
- },
49
- signal: abortSignal,
50
- });
51
- wranglerProcess.stdout?.setEncoding('utf8');
52
- wranglerProcess.stderr?.setEncoding('utf8');
53
- wranglerProcess.stdout?.on('data', (data) => {
54
- // console.log(`[wrangler] ${data}`)
55
- console.log(data);
56
- });
57
- wranglerProcess.stderr?.on('data', (data) => {
58
- // console.error(`[wrangler] ${data}`)
59
- console.error(data);
60
- });
61
- await new Promise((resolve) => {
62
- const onData = (data) => {
63
- if (data.includes('Ready on')) {
64
- wranglerProcess?.stdout?.off('data', onData);
65
- resolve();
66
- }
67
- };
68
- wranglerProcess?.stdout?.on('data', onData);
69
- });
70
- console.log(`Wrangler dev server ready on port ${syncPort}`);
71
- // Wait longer for the Cloudflare Workers runtime to fully initialize
72
- // console.log('Waiting for Cloudflare Workers runtime to fully initialize...')
73
- // await new Promise(resolve => setTimeout(resolve, 10000))
74
- return { port: syncPort };
75
- };
76
- const killWranglerProcess = () => {
77
- if (wranglerProcess) {
78
- console.log('Killing wrangler process...');
79
- wranglerProcess.kill('SIGTERM');
80
- wranglerProcess = undefined;
81
- }
82
- };
83
- process.on('exit', killWranglerProcess);
84
- process.on('SIGINT', killWranglerProcess);
85
- process.on('SIGTERM', killWranglerProcess);
86
- try {
87
- const { afterAll } = await import('vitest');
88
- afterAll(() => {
89
- killWranglerProcess();
90
- });
91
- }
92
- catch { }
93
- const { port } = await setup();
94
- return { port, kill: killWranglerProcess };
95
- };
96
- //# sourceMappingURL=vitest-wrangler-setup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vitest-wrangler-setup.js","sourceRoot":"","sources":["../../src/node/vitest-wrangler-setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,GAAG,MAAM,UAAU,CAAA;AAC1B,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAQ9D,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,IAAgC,EAAE,EAAE,CACzE,MAAM,CAAC,UAAU,CAAC;IAChB,GAAG,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,6BAA6B,CAAC,EAAE,GAAG,IAAI,EAAE,WAAW,EAAE,CAAC;IAC7E,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,6BAA6B,KAAK,EAAE,CAAC,EAAE,CAAC;CAChG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAC,CAAA;AAEpD,2CAA2C;AAC3C,yBAAyB;AACzB,iFAAiF;AACjF,qHAAqH;AACrH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,KAAK,EAAE,EAClD,kBAAkB,EAClB,WAAW,EACX,GAAG,EACH,IAAI,EAAE,SAAS,GAMhB,EAAE,EAAE;IACH,IAAI,eAAqD,CAAA;IAEzD,MAAM,WAAW,GAAG,GAAoB,EAAE;QACxC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,MAAM,GAAG,GAAG,CAAC,YAAY,EAAE,CAAA;YACjC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE;gBACp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AM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAA;QAC3C,QAAQ,CAAC,GAAG,EAAE;YACZ,mBAAmB,EAAE,CAAA;QACvB,CAAC,CAAC,CAAA;IACJ,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;IAEV,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,KAAK,EAAE,CAAA;IAE9B,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAA;AAC5C,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=polyfill.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../../src/node-vitest/polyfill.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- process.stdout.isTTY = true;
2
- export {};
3
- //# sourceMappingURL=polyfill.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"polyfill.js","sourceRoot":"","sources":["../../src/node-vitest/polyfill.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAA"}
@@ -1,266 +0,0 @@
1
- import { Effect, Exit, FetchHttpClient, Fiber, Layer, Scope } from '@livestore/utils/effect'
2
- import { PlatformNode } from '@livestore/utils/node'
3
- import { Vitest } from '@livestore/utils-dev/node-vitest'
4
- import { expect } from 'vitest'
5
- import {
6
- type StartWranglerDevServerArgs,
7
- WranglerDevServerError,
8
- WranglerDevServerService,
9
- } from './WranglerDevServer.ts'
10
-
11
- const testTimeout = 60_000
12
-
13
- const withTestCtx = Vitest.makeWithTestCtx({
14
- timeout: testTimeout,
15
- makeLayer: () => PlatformNode.NodeContext.layer,
16
- })
17
-
18
- const WranglerDevServerTest = (args: Partial<StartWranglerDevServerArgs> = {}) =>
19
- WranglerDevServerService.Default({
20
- cwd: `${import.meta.dirname}/fixtures`,
21
- ...args,
22
- }).pipe(Layer.provide(FetchHttpClient.layer))
23
-
24
- Vitest.describe('WranglerDevServer', { timeout: testTimeout }, () => {
25
- Vitest.describe('Basic Operations', () => {
26
- const withBasicTest = (args: Partial<StartWranglerDevServerArgs> = {}) =>
27
- Vitest.makeWithTestCtx({
28
- timeout: testTimeout,
29
- makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
30
- })
31
-
32
- Vitest.scopedLive('should start wrangler dev server and return port', (test) =>
33
- Effect.gen(function* () {
34
- const server = yield* WranglerDevServerService
35
-
36
- expect(server.port).toBeGreaterThan(0)
37
- expect(server.url).toMatch(/http:\/\/localhost:\d+/)
38
- expect(typeof server.processId).toBe('number')
39
- expect(server.processId).toBeGreaterThan(0)
40
- }).pipe(withBasicTest()(test)),
41
- )
42
-
43
- Vitest.scopedLive('should use specified port when provided', (test) =>
44
- Effect.gen(function* () {
45
- const server = yield* WranglerDevServerService
46
-
47
- expect(server.port).toBe(54443)
48
- expect(server.url).toBe(`http://localhost:54443`)
49
- }).pipe(withBasicTest({ port: 54443 })(test)),
50
- )
51
- })
52
-
53
- Vitest.describe('Resource Management', () => {
54
- Vitest.scopedLive('should cleanup processes on scope close', (test) =>
55
- Effect.gen(function* () {
56
- let processId: number | undefined
57
-
58
- // Create a separate scope for the server
59
- const serverScope = yield* Scope.make()
60
-
61
- const server = yield* Effect.provide(
62
- WranglerDevServerService,
63
- WranglerDevServerTest().pipe(Layer.provide(PlatformNode.NodeContext.layer)),
64
- ).pipe(Scope.extend(serverScope))
65
-
66
- processId = server.processId
67
- expect(processId).toBeGreaterThan(0)
68
- expect(server.port).toBeGreaterThan(0)
69
- expect(server.url).toMatch(/http:\/\/localhost:\d+/)
70
-
71
- // Close scope to trigger cleanup
72
- yield* Scope.close(serverScope, Exit.succeed(void 0))
73
-
74
- // Wait for cleanup to complete
75
- yield* Effect.sleep('2 seconds')
76
-
77
- // Verify process is terminated
78
- const isRunning2 = yield* Effect.promise(() => {
79
- try {
80
- process.kill(processId!, 0)
81
- return Promise.resolve(true)
82
- } catch {
83
- return Promise.resolve(false)
84
- }
85
- })
86
- expect(isRunning2).toBe(false)
87
- }).pipe(withTestCtx(test)),
88
- )
89
-
90
- Vitest.scopedLive('should handle interruption with fast cleanup', (test) =>
91
- Effect.gen(function* () {
92
- let processId: number | undefined
93
-
94
- const fiber = yield* Effect.fork(
95
- Effect.provide(
96
- Effect.gen(function* () {
97
- const server = yield* WranglerDevServerService
98
- processId = server.processId
99
- yield* Effect.sleep('30 seconds') // Keep running
100
- return server
101
- }),
102
- WranglerDevServerTest().pipe(Layer.provide(PlatformNode.NodeContext.layer)),
103
- ),
104
- )
105
-
106
- // Wait for server to start
107
- yield* Effect.sleep('3 seconds')
108
-
109
- expect(processId).toBeGreaterThan(0)
110
-
111
- // Interrupt and measure cleanup time
112
- const start = Date.now()
113
- yield* Fiber.interrupt(fiber)
114
- const elapsed = Date.now() - start
115
-
116
- // Should use fast cleanup (500ms timeout) + some overhead
117
- expect(elapsed).toBeLessThan(1500) // Allow some overhead
118
-
119
- // Wait for cleanup to complete
120
- yield* Effect.sleep('1 second')
121
-
122
- // Verify process is terminated
123
- const isRunningAfter = yield* Effect.promise(() => {
124
- try {
125
- process.kill(processId!, 0)
126
- return Promise.resolve(true)
127
- } catch {
128
- return Promise.resolve(false)
129
- }
130
- })
131
- expect(isRunningAfter).toBe(false)
132
- }).pipe(withTestCtx(test)),
133
- )
134
- })
135
-
136
- Vitest.describe('Error Handling', () => {
137
- const withErrorTest = (args: Partial<StartWranglerDevServerArgs> = {}) =>
138
- Vitest.makeWithTestCtx({
139
- timeout: testTimeout,
140
- makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
141
- })
142
-
143
- Vitest.scopedLive('should handle missing wrangler.toml but should timeout', (test) =>
144
- Effect.gen(function* () {
145
- const error = yield* WranglerDevServerService.pipe(
146
- Effect.provide(
147
- WranglerDevServerTest({
148
- cwd: '/tmp',
149
- wranglerConfigPath: '/dev/null',
150
- connectTimeout: '500 millis',
151
- }).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
152
- ),
153
- Effect.flip,
154
- )
155
-
156
- expect(error).toBeInstanceOf(WranglerDevServerError)
157
- }).pipe(Vitest.withTestCtx(test)),
158
- )
159
-
160
- Vitest.scopedLive('should handle invalid working directory', (test) =>
161
- Effect.gen(function* () {
162
- const result = yield* WranglerDevServerService.pipe(
163
- Effect.provide(
164
- WranglerDevServerTest({
165
- cwd: '/completely/nonexistent/directory',
166
- }).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
167
- ),
168
- Effect.either,
169
- )
170
-
171
- expect(result._tag).toBe('Left')
172
- if (result._tag === 'Left') {
173
- expect(result.left).toBeInstanceOf(WranglerDevServerError)
174
- }
175
- }).pipe(Vitest.withTestCtx(test)),
176
- )
177
-
178
- Vitest.scopedLive('should timeout if server fails to start', (test) =>
179
- Effect.gen(function* () {
180
- // Create a command that will never output "Ready on"
181
- const result = yield* WranglerDevServerService.pipe(
182
- // Override the timeout for this test to be shorter
183
- Effect.timeout('5 seconds'),
184
- Effect.either,
185
- )
186
-
187
- // This might succeed or fail depending on actual wrangler behavior
188
- // The main point is testing timeout functionality
189
- expect(['Left', 'Right']).toContain(result._tag)
190
- }).pipe(withErrorTest()(test)),
191
- )
192
- })
193
-
194
- Vitest.describe('Process Tree Cleanup', () => {
195
- const withCleanupTest = (args: Partial<StartWranglerDevServerArgs> = {}) =>
196
- Vitest.makeWithTestCtx({
197
- timeout: testTimeout,
198
- makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
199
- })
200
-
201
- Vitest.scopedLive('should clean up child workerd processes', (test) =>
202
- Effect.gen(function* () {
203
- let processId: number | undefined
204
-
205
- const server = yield* WranglerDevServerService
206
- processId = server.processId
207
-
208
- // Wait for wrangler to spawn workerd children
209
- yield* Effect.sleep('3 seconds')
210
-
211
- // Find any child processes (workerd)
212
- const children = yield* Effect.promise(async () => {
213
- const { exec } = require('node:child_process')
214
- const { promisify } = require('node:util')
215
- const execAsync = promisify(exec)
216
-
217
- try {
218
- if (!processId) throw new Error('processId is undefined')
219
- const { stdout } = await execAsync(`ps -o pid,ppid -ax | grep -E "^\\s*[0-9]+\\s+${processId}\\s*$"`)
220
- return stdout
221
- .trim()
222
- .split('\n')
223
- .map((line: string) => {
224
- const match = line.trim().match(/^\s*(\d+)\s+\d+\s*$/)
225
- return match?.[1] ? Number.parseInt(match[1], 10) : null
226
- })
227
- .filter((pid: number | null): pid is number => pid !== null)
228
- } catch {
229
- return []
230
- }
231
- })
232
-
233
- console.log(`Found ${children.length} child processes:`, children)
234
-
235
- // The scope will close here and should clean up all processes
236
- }).pipe(withCleanupTest()(test)),
237
- )
238
- })
239
-
240
- Vitest.describe('Service Pattern', () => {
241
- const withServiceTest = (args: Partial<StartWranglerDevServerArgs> = {}) =>
242
- Vitest.makeWithTestCtx({
243
- timeout: testTimeout,
244
- makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
245
- })
246
-
247
- Vitest.scopedLive('should work with service pattern', (test) =>
248
- Effect.gen(function* () {
249
- const server = yield* WranglerDevServerService
250
-
251
- expect(server.port).toBeGreaterThan(0)
252
- expect(server.url).toMatch(/http:\/\/localhost:\d+/)
253
- expect(server.processId).toBeGreaterThan(0)
254
- }).pipe(withServiceTest()(test)),
255
- )
256
-
257
- Vitest.scopedLive('should work with custom port via service', (test) =>
258
- Effect.gen(function* () {
259
- const server = yield* WranglerDevServerService
260
-
261
- expect(server.port).toBe(54444)
262
- expect(server.url).toBe('http://localhost:54444')
263
- }).pipe(withServiceTest({ port: 54444 })(test)),
264
- )
265
- })
266
- })