|
1 | | -import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'; |
| 1 | +import { |
| 2 | + copyFileSync, |
| 3 | + cpSync, |
| 4 | + existsSync, |
| 5 | + mkdirSync, |
| 6 | + readFileSync, |
| 7 | + rmSync, |
| 8 | + writeFileSync, |
| 9 | +} from 'node:fs'; |
2 | 10 | import { join } from 'node:path'; |
3 | 11 | import spawn from 'cross-spawn'; |
4 | 12 | import { |
@@ -89,7 +97,13 @@ let savedToken: string | undefined; |
89 | 97 | let savedProject: string | undefined; |
90 | 98 |
|
91 | 99 | type Captured = { |
92 | | - finalizeBody: { manifest?: { pages?: unknown; bindings?: Record<string, unknown> } } | null; |
| 100 | + finalizeBody: { |
| 101 | + manifest?: { |
| 102 | + pages?: unknown; |
| 103 | + bindings?: Record<string, unknown>; |
| 104 | + vars?: Record<string, string>; |
| 105 | + }; |
| 106 | + } | null; |
93 | 107 | }; |
94 | 108 |
|
95 | 109 | // Every asset is reported as present, so the deploy skips uploads and goes straight to finalize. |
@@ -176,7 +190,7 @@ function ndjson(events: Array<unknown>): Response { |
176 | 190 | }); |
177 | 191 | } |
178 | 192 |
|
179 | | -describe('runFullDeploy emits manifest.pages (Void pages app, end-to-end)', () => { |
| 193 | +describe('managed deployment manifests (built Worker)', () => { |
180 | 194 | beforeAll(() => { |
181 | 195 | playground = createIsolatedPlayground(ROOT, SOURCE_PLAYGROUND); |
182 | 196 | fixture = playground.root; |
@@ -318,6 +332,44 @@ describe('runFullDeploy emits manifest.pages (Void pages app, end-to-end)', () = |
318 | 332 | } |
319 | 333 | }); |
320 | 334 |
|
| 335 | + it.each([ |
| 336 | + ['Void', undefined], |
| 337 | + ['Class A', { name: 'vinext-pages', class: 'a' }], |
| 338 | + ['Class C', { name: 'astro', class: 'c' }], |
| 339 | + ] as const)( |
| 340 | + 'includes configured worker.vars in the %s deployment request', |
| 341 | + async (_, detected) => { |
| 342 | + mockDetectFramework.mockReturnValue(detected); |
| 343 | + const configPath = join(fixture, 'void.config.ts'); |
| 344 | + const original = readFileSync(configPath, 'utf8'); |
| 345 | + const dotenvPath = join(fixture, '.env'); |
| 346 | + const originalDotenv = existsSync(dotenvPath) ? readFileSync(dotenvPath) : undefined; |
| 347 | + const vars = { API_URL: 'https://api.example.test', EMPTY_SETTING: '' }; |
| 348 | + writeFileSync( |
| 349 | + configPath, |
| 350 | + original.replace('worker: {', `worker: { vars: ${JSON.stringify(vars)},`), |
| 351 | + ); |
| 352 | + writeFileSync(dotenvPath, 'API_URL=https://local.example.test\nADMIN_TOKEN=local-secret\n'); |
| 353 | + if (detected?.name === 'astro') { |
| 354 | + // Reuse the built Worker at the Class C preset's output paths. |
| 355 | + cpSync(join(fixture, 'dist/ssr'), join(fixture, 'dist/server'), { recursive: true }); |
| 356 | + copyFileSync(join(fixture, 'dist/server/index.js'), join(fixture, 'dist/server/entry.mjs')); |
| 357 | + } |
| 358 | + try { |
| 359 | + const captured = installPlatformMocks(); |
| 360 | + await runDeploy(fixture, { skipBuild: true }); |
| 361 | + expect(captured.finalizeBody?.manifest?.vars).toEqual(vars); |
| 362 | + } finally { |
| 363 | + writeFileSync(configPath, original); |
| 364 | + if (originalDotenv === undefined) { |
| 365 | + rmSync(dotenvPath, { force: true }); |
| 366 | + } else { |
| 367 | + writeFileSync(dotenvPath, originalDotenv); |
| 368 | + } |
| 369 | + } |
| 370 | + }, |
| 371 | + ); |
| 372 | + |
321 | 373 | it('uses the alternate project for Worker packaging and prerendering while retaining the saved link', async () => { |
322 | 374 | const original = readFileSync(projectJson, 'utf8'); |
323 | 375 | const saved = JSON.stringify({ |
|
0 commit comments