summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/integrations/cloudflare/package.json3
-rw-r--r--packages/integrations/cloudflare/test/basics.test.js4
-rw-r--r--packages/integrations/cloudflare/test/cf.test.js8
-rw-r--r--packages/integrations/cloudflare/test/runtime.test.js4
-rw-r--r--packages/integrations/cloudflare/test/test-utils.js23
-rw-r--r--packages/integrations/cloudflare/test/with-solid-js.test.js4
-rw-r--r--packages/integrations/cloudflare/test/wrangler.toml2
7 files changed, 31 insertions, 17 deletions
diff --git a/packages/integrations/cloudflare/package.json b/packages/integrations/cloudflare/package.json
index a37174257..9439ade6c 100644
--- a/packages/integrations/cloudflare/package.json
+++ b/packages/integrations/cloudflare/package.json
@@ -52,7 +52,8 @@
"astro-scripts": "workspace:*",
"chai": "^4.3.7",
"cheerio": "1.0.0-rc.12",
+ "kill-port": "^2.0.1",
"mocha": "^9.2.2",
- "wrangler": "^2.0.23"
+ "wrangler": "^3.5.0"
}
}
diff --git a/packages/integrations/cloudflare/test/basics.test.js b/packages/integrations/cloudflare/test/basics.test.js
index 9aa78f98e..c27b6be6c 100644
--- a/packages/integrations/cloudflare/test/basics.test.js
+++ b/packages/integrations/cloudflare/test/basics.test.js
@@ -14,7 +14,7 @@ describe('Basic app', () => {
});
await fixture.build();
- cli = runCLI('./fixtures/basics/', { silent: true, port: 8789 });
+ cli = await runCLI('./fixtures/basics/', { silent: true, port: 8789 });
await cli.ready;
});
@@ -23,7 +23,7 @@ describe('Basic app', () => {
});
it('can render', async () => {
- let res = await fetch(`http://localhost:8789/`);
+ let res = await fetch(`http://127.0.0.1:8789/`);
expect(res.status).to.equal(200);
let html = await res.text();
let $ = cheerio.load(html);
diff --git a/packages/integrations/cloudflare/test/cf.test.js b/packages/integrations/cloudflare/test/cf.test.js
index f8ab9c02f..e6c2ccd0b 100644
--- a/packages/integrations/cloudflare/test/cf.test.js
+++ b/packages/integrations/cloudflare/test/cf.test.js
@@ -17,7 +17,7 @@ describe('Cf metadata and caches', () => {
});
await fixture.build();
- cli = runCLI('./fixtures/cf/', { silent: false, port: 8788 });
+ cli = await runCLI('./fixtures/cf/', { silent: false, port: 8788 });
await cli.ready;
});
@@ -26,12 +26,12 @@ describe('Cf metadata and caches', () => {
});
it('Load cf and caches API', async () => {
- let res = await fetch(`http://localhost:8788/`);
+ let res = await fetch(`http://127.0.0.1:8788/`);
expect(res.status).to.equal(200);
let html = await res.text();
let $ = cheerio.load(html);
- // console.log($('#cf').text(), html);
- expect($('#cf').text()).to.contain('city');
+
+ expect($('#cf').text()).to.contain('city', `Expected "city" to exist in runtime, but got ${$('#cf').text()}`);
expect($('#hasCache').text()).to.equal('true');
});
});
diff --git a/packages/integrations/cloudflare/test/runtime.test.js b/packages/integrations/cloudflare/test/runtime.test.js
index 243c1dd67..17d813448 100644
--- a/packages/integrations/cloudflare/test/runtime.test.js
+++ b/packages/integrations/cloudflare/test/runtime.test.js
@@ -17,7 +17,7 @@ describe('Runtime Locals', () => {
});
await fixture.build();
- cli = runCLI('./fixtures/runtime/', { silent: true, port: 8793 });
+ cli = await runCLI('./fixtures/runtime/', { silent: true, port: 8793 });
await cli.ready;
});
@@ -26,7 +26,7 @@ describe('Runtime Locals', () => {
});
it('has CF and Caches', async () => {
- let res = await fetch(`http://localhost:8793/`);
+ let res = await fetch(`http://127.0.0.1:8793/`);
expect(res.status).to.equal(200);
let html = await res.text();
let $ = cheerio.load(html);
diff --git a/packages/integrations/cloudflare/test/test-utils.js b/packages/integrations/cloudflare/test/test-utils.js
index 90147a7f6..6a657a0fc 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,20 +22,30 @@ 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 = 10_000;
const ready = new Promise(async (resolve, reject) => {
const failed = setTimeout(
- () => reject(new Error(`Timed out starting the wrangler CLI`)),
+ () => {
+ p.kill();
+ reject(new Error(`Timed out starting the wrangler CLI`));
+ },
timeout
);
@@ -50,7 +61,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;
}
}
diff --git a/packages/integrations/cloudflare/test/with-solid-js.test.js b/packages/integrations/cloudflare/test/with-solid-js.test.js
index 90c1c0722..c091d04b3 100644
--- a/packages/integrations/cloudflare/test/with-solid-js.test.js
+++ b/packages/integrations/cloudflare/test/with-solid-js.test.js
@@ -14,7 +14,7 @@ describe('With SolidJS', () => {
});
await fixture.build();
- cli = runCLI('./fixtures/with-solid-js/', { silent: true, port: 8790 });
+ cli = await runCLI('./fixtures/with-solid-js/', { silent: true, port: 8790 });
await cli.ready;
});
@@ -23,7 +23,7 @@ describe('With SolidJS', () => {
});
it('renders the solid component', async () => {
- let res = await fetch(`http://localhost:8790/`);
+ let res = await fetch(`http://127.0.0.1:8790/`);
expect(res.status).to.equal(200);
let html = await res.text();
let $ = cheerio.load(html);
diff --git a/packages/integrations/cloudflare/test/wrangler.toml b/packages/integrations/cloudflare/test/wrangler.toml
index 6e2d864b0..2c1acb55a 100644
--- a/packages/integrations/cloudflare/test/wrangler.toml
+++ b/packages/integrations/cloudflare/test/wrangler.toml
@@ -1,4 +1,6 @@
# for tests only
+send_metrics = false
+
[vars]
SECRET_STUFF = "secret"