summaryrefslogtreecommitdiff
path: root/packages/integrations/cloudflare/test
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2023-08-17 08:54:28 -0400
committerGravatar Matthew Phillips <matthew@skypack.dev> 2023-08-17 08:54:28 -0400
commitcbb77af978bd0dcee08ad2dcadadb032abc44dc1 (patch)
tree94b7f35fd4214bbcdb1d36393583c5332bc5ff24 /packages/integrations/cloudflare/test
parent2484dc4080e5cd84b9a53648a1de426d7c907be2 (diff)
parentd6b4943764989c0e89df2d6875cd19691566dfb3 (diff)
downloadastro-cbb77af978bd0dcee08ad2dcadadb032abc44dc1.tar.gz
astro-cbb77af978bd0dcee08ad2dcadadb032abc44dc1.tar.zst
astro-cbb77af978bd0dcee08ad2dcadadb032abc44dc1.zip
Merge branch 'main' into next
Diffstat (limited to 'packages/integrations/cloudflare/test')
-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/fixtures/cf/src/pages/index.astro2
-rw-r--r--packages/integrations/cloudflare/test/fixtures/runtime/src/pages/index.astro2
-rw-r--r--packages/integrations/cloudflare/test/runtime.test.js6
-rw-r--r--packages/integrations/cloudflare/test/test-utils.js36
-rw-r--r--packages/integrations/cloudflare/test/with-solid-js.test.js4
-rw-r--r--packages/integrations/cloudflare/test/wrangler.toml2
8 files changed, 42 insertions, 22 deletions
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..ec0e52c97 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($('#hasRuntime').text()).to.equal('true');
expect($('#hasCache').text()).to.equal('true');
});
});
diff --git a/packages/integrations/cloudflare/test/fixtures/cf/src/pages/index.astro b/packages/integrations/cloudflare/test/fixtures/cf/src/pages/index.astro
index c9e67bb05..6ba48e803 100644
--- a/packages/integrations/cloudflare/test/fixtures/cf/src/pages/index.astro
+++ b/packages/integrations/cloudflare/test/fixtures/cf/src/pages/index.astro
@@ -8,7 +8,7 @@ const runtime = getRuntime(Astro.request);
</head>
<body>
<h1>Testing</h1>
- <div id="cf">{JSON.stringify(runtime.cf)}</div>
+ <div id="hasRuntime">{!!runtime.cf?.colo}</div>
<div id="hasCache">{!!runtime.caches}</div>
</body>
</html>
diff --git a/packages/integrations/cloudflare/test/fixtures/runtime/src/pages/index.astro b/packages/integrations/cloudflare/test/fixtures/runtime/src/pages/index.astro
index 320e8e162..aa73ab8ea 100644
--- a/packages/integrations/cloudflare/test/fixtures/runtime/src/pages/index.astro
+++ b/packages/integrations/cloudflare/test/fixtures/runtime/src/pages/index.astro
@@ -8,8 +8,8 @@ const env = runtime.env;
</head>
<body>
<h1>Testing</h1>
- <div id="cf">{JSON.stringify(runtime.cf)}</div>
<div id="env">{JSON.stringify(env)}</div>
+ <div id="hasRuntime">{!!runtime.cf?.colo}</div>
<div id="hasCache">{!!runtime.caches}</div>
</body>
</html>
diff --git a/packages/integrations/cloudflare/test/runtime.test.js b/packages/integrations/cloudflare/test/runtime.test.js
index 243c1dd67..be14718e8 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,13 +26,13 @@ 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);
- expect($('#cf').text()).to.contain('city');
expect($('#env').text()).to.contain('SECRET_STUFF');
expect($('#env').text()).to.contain('secret');
+ expect($('#hasRuntime').text()).to.contain('true');
expect($('#hasCache').text()).to.equal('true');
});
});
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;
}
}
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"