summaryrefslogtreecommitdiff
path: root/packages/integrations/cloudflare/test/_test-utils.js
diff options
context:
space:
mode:
authorGravatar Alexander Niebuhr <alexander@nbhr.io> 2023-10-13 09:53:40 +0200
committerGravatar Alexander Niebuhr <alexander@nbhr.io> 2023-10-16 16:24:07 +0200
commit5ce6ac0b7d2bdc44f4c5083a8e8457892dcdf64d (patch)
tree62b86aecf8b27e9c1a6969acc6068b95a49c4bd3 /packages/integrations/cloudflare/test/_test-utils.js
parent2c5fc57322ee42bb505aca72cd9b2e27b273b7eb (diff)
downloadastro-5ce6ac0b7d2bdc44f4c5083a8e8457892dcdf64d.tar.gz
astro-5ce6ac0b7d2bdc44f4c5083a8e8457892dcdf64d.tar.zst
astro-5ce6ac0b7d2bdc44f4c5083a8e8457892dcdf64d.zip
chore(cloudflare): fixup migration issues
Diffstat (limited to 'packages/integrations/cloudflare/test/_test-utils.js')
-rw-r--r--packages/integrations/cloudflare/test/_test-utils.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/packages/integrations/cloudflare/test/_test-utils.js b/packages/integrations/cloudflare/test/_test-utils.js
new file mode 100644
index 000000000..04946cbfa
--- /dev/null
+++ b/packages/integrations/cloudflare/test/_test-utils.js
@@ -0,0 +1,50 @@
+import { fileURLToPath } from "node:url";
+import { execa } from "execa";
+/**
+ * @typedef {{ stop: Promise<void>, port: number }} WranglerCLI
+ */
+
+const astroPath = fileURLToPath(
+ new URL("../node_modules/.bin/astro", import.meta.url)
+);
+/** Returns a process running the Astro CLI. */
+export function astroCli(cwd, /** @type {string[]} */ ...args) {
+ const spawned = execa(astroPath, [...args], {
+ env: { ASTRO_TELEMETRY_DISABLED: true },
+ cwd: cwd,
+ });
+
+ spawned.stdout.setEncoding("utf8");
+
+ return spawned;
+}
+
+const wranglerPath = fileURLToPath(
+ new URL("../node_modules/wrangler/bin/wrangler.js", import.meta.url)
+);
+/** Returns a process running the Astro CLI. */
+export function wranglerCli(cwd) {
+ const spawned = execa(
+ wranglerPath,
+ [
+ "pages",
+ "dev",
+ "dist",
+ "--port",
+ "8788",
+ "--compatibility-date",
+ new Date().toISOString().slice(0, 10),
+ "--log-level",
+ "info",
+ ],
+ {
+ env: { CI: 1, CF_PAGES: 1 },
+ cwd: cwd,
+ }
+ );
+
+ spawned.stdout.setEncoding("utf8");
+ spawned.stderr.setEncoding("utf8");
+
+ return spawned;
+}