| ... | ... | @@ -27,11 +27,16 @@ const encode = (value: string) => Stream.make(new TextEncoder().encode(value)); |
| 27 | 27 | * test set the outcome of the `off` (pre-clear) and `serve` calls separately — |
| 28 | 28 | * they are the same subcommand and are told apart by the trailing `off`. |
| 29 | 29 | */ |
| 30 | | const spawnerLayer = (input: { readonly off?: CallResult; readonly serve?: CallResult }) => |
| 30 | const spawnerLayer = (input: { |
| 31 | readonly off?: CallResult; |
| 32 | readonly serve?: CallResult; |
| 33 | readonly calls?: Array<ReadonlyArray<string>>; |
| 34 | }) => |
| 31 | 35 | Layer.succeed( |
| 32 | 36 | ChildProcessSpawner.ChildProcessSpawner, |
| 33 | 37 | ChildProcessSpawner.make((command) => { |
| 34 | 38 | const args = "args" in command ? (command.args as ReadonlyArray<string>) : []; |
| 39 | input.calls?.push(args); |
| 35 | 40 | const result: CallResult = args.includes("status") |
| 36 | 41 | ? { exitCode: 0 } |
| 37 | 42 | : args.includes("off") |
| ... | ... | @@ -102,6 +107,20 @@ describe("shareDevServer", () => { |
| 102 | 107 | }), |
| 103 | 108 | ); |
| 104 | 109 | |
| 110 | // Vite binds `localhost`, which modern Node resolves to `::1` first, so a |
| 111 | // 127.0.0.1 target would proxy to a loopback nothing listens on. |
| 112 | it.effect("proxies to the localhost name Vite binds, not 127.0.0.1", () => |
| 113 | Effect.gen(function* () { |
| 114 | const calls: Array<ReadonlyArray<string>> = []; |
| 115 | yield* shareDevServer({ webPort: 5788 }).pipe( |
| 116 | Effect.provide(spawnerLayer({ off: { exitCode: 0 }, calls })), |
| 117 | ); |
| 118 | |
| 119 | const serveCall = calls.find((args) => args.includes("--bg")); |
| 120 | assert.deepEqual(serveCall, ["serve", "--bg", "--https=5788", "http://localhost:5788"]); |
| 121 | }), |
| 122 | ); |
| 123 | |
| 105 | 124 | // The stale-mapping clear runs before serve, so a failure here leaves the |
| 106 | 125 | // port serving nothing. Saying only "serve failed" would let an operator |
| 107 | 126 | // assume their previous mapping survived. |