summaryrefslogtreecommitdiff
path: root/packages/integrations/cloudflare/test/test-utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/cloudflare/test/test-utils.js')
-rw-r--r--packages/integrations/cloudflare/test/test-utils.js36
1 files changed, 27 insertions, 9 deletions
diff --git a/packages/integrations/cloudflare/test/test-utils.js b/packages/integrations/cloudflare/test/test-utils.js
index 90147a7f6..36515f831 100644
--- a/packages/integrations/cloudflare/test/test-utils.js
+++ b/packages/integrations/cloudflare/test/test-utils.js
@@ -1,5 +1,6 @@
import { spawn } from 'node:child_process';
import { fileURLToPath } from 'node:url';
+import kill from 'kill-port';
import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js';
export { fixLineEndings } from '../../../astro/test/test-utils.js';
@@ -21,22 +22,39 @@ const wranglerPath = fileURLToPath(
);
/**
- * @returns {WranglerCLI}
+ * @returns {Promise<WranglerCLI>}
*/
-export function runCLI(basePath, { silent, port = 8787 }) {
+export async function runCLI(basePath, { silent, port }) {
+ // Hack: force existing process on port to be killed
+ try {
+ await kill(port, 'tcp');
+ } catch {
+ // Will throw if port is not in use, but that's fine
+ }
+
const script = fileURLToPath(new URL(`${basePath}/dist/_worker.js`, import.meta.url));
- const p = spawn('node', [wranglerPath, 'dev', '-l', script, '--port', port]);
+ const p = spawn('node', [
+ wranglerPath,
+ 'dev',
+ script,
+ '--port',
+ port,
+ '--log-level',
+ 'info',
+ '--persist-to',
+ `${basePath}/.wrangler/state`,
+ ]);
p.stderr.setEncoding('utf-8');
p.stdout.setEncoding('utf-8');
- const timeout = 10000;
+ const timeout = 20_000;
const ready = new Promise(async (resolve, reject) => {
- const failed = setTimeout(
- () => reject(new Error(`Timed out starting the wrangler CLI`)),
- timeout
- );
+ const failed = setTimeout(() => {
+ p.kill();
+ reject(new Error(`Timed out starting the wrangler CLI`));
+ }, timeout);
(async function () {
for (const msg of p.stderr) {
@@ -50,7 +68,7 @@ export function runCLI(basePath, { silent, port = 8787 }) {
if (!silent) {
console.log(msg);
}
- if (msg.includes(`Listening on`)) {
+ if (msg.includes(`[mf:inf] Ready on`)) {
break;
}
}