aboutsummaryrefslogtreecommitdiff
path: root/packages/integrations/cloudflare/test
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/cloudflare/test')
-rw-r--r--packages/integrations/cloudflare/test/basics.test.js29
-rw-r--r--packages/integrations/cloudflare/test/cf.test.js30
-rw-r--r--packages/integrations/cloudflare/test/test-utils.js4
-rw-r--r--packages/integrations/cloudflare/test/with-solid-js.test.js27
4 files changed, 49 insertions, 41 deletions
diff --git a/packages/integrations/cloudflare/test/basics.test.js b/packages/integrations/cloudflare/test/basics.test.js
index d382a9084..b97079b8f 100644
--- a/packages/integrations/cloudflare/test/basics.test.js
+++ b/packages/integrations/cloudflare/test/basics.test.js
@@ -5,28 +5,29 @@ import * as cheerio from 'cheerio';
describe.skip('Basic app', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
+ /** @type {import('./test-utils').WranglerCLI} */
+ let cli;
before(async () => {
fixture = await loadFixture({
root: './fixtures/basics/',
});
await fixture.build();
- });
- it('can render', async () => {
- const { ready, stop } = runCLI('./fixtures/basics/', { silent: true, port: 8789 });
+ cli = runCLI('./fixtures/basics/', { silent: true, port: 8789 });
+ await cli.ready;
+ });
- try {
- await ready;
+ after(async () => {
+ await cli.stop();
+ });
- let res = await fetch(`http://localhost:8789/`);
- expect(res.status).to.equal(200);
- let html = await res.text();
- let $ = cheerio.load(html);
- expect($('h1').text()).to.equal('Testing');
- expect($('#env').text()).to.equal('secret');
- } finally {
- await stop();
- }
+ it('can render', async () => {
+ let res = await fetch(`http://localhost:8789/`);
+ expect(res.status).to.equal(200);
+ let html = await res.text();
+ let $ = cheerio.load(html);
+ expect($('h1').text()).to.equal('Testing');
+ expect($('#env').text()).to.equal('secret');
});
});
diff --git a/packages/integrations/cloudflare/test/cf.test.js b/packages/integrations/cloudflare/test/cf.test.js
index cf310f34d..559df5c76 100644
--- a/packages/integrations/cloudflare/test/cf.test.js
+++ b/packages/integrations/cloudflare/test/cf.test.js
@@ -6,6 +6,8 @@ import cloudflare from '../dist/index.js';
describe('Cf metadata and caches', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
+ /** @type {import('./test-utils').WranglerCLI} */
+ let cli;
before(async () => {
fixture = await loadFixture({
@@ -14,22 +16,22 @@ describe('Cf metadata and caches', () => {
adapter: cloudflare(),
});
await fixture.build();
+
+ cli = runCLI('./fixtures/cf/', { silent: true, port: 8788 });
+ await cli.ready;
});
- it('Load cf and caches API', async () => {
- const { ready, stop } = runCLI('./fixtures/cf/', { silent: true, port: 8788 });
+ after(async () => {
+ await cli.stop();
+ });
- try {
- await ready;
- let res = await fetch(`http://localhost: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($('#hasCache').text()).to.equal('true');
- } finally {
- await stop();
- }
+ it('Load cf and caches API', async () => {
+ let res = await fetch(`http://localhost: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($('#hasCache').text()).to.equal('true');
});
});
diff --git a/packages/integrations/cloudflare/test/test-utils.js b/packages/integrations/cloudflare/test/test-utils.js
index e0fc90a64..bff7fb2a4 100644
--- a/packages/integrations/cloudflare/test/test-utils.js
+++ b/packages/integrations/cloudflare/test/test-utils.js
@@ -5,6 +5,7 @@ import { fileURLToPath } from 'url';
export { fixLineEndings } from '../../../astro/test/test-utils.js';
/**
+ * @typedef {{ ready: Promise<void>, stop: Promise<void> }} WranglerCLI
* @typedef {import('../../../astro/test/test-utils').Fixture} Fixture
*/
@@ -19,6 +20,9 @@ const wranglerPath = fileURLToPath(
new URL('../node_modules/wrangler/bin/wrangler.js', import.meta.url)
);
+/**
+ * @returns {WranglerCLI}
+ */
export function runCLI(basePath, { silent, port = 8787 }) {
const script = fileURLToPath(new URL(`${basePath}/dist/_worker.js`, import.meta.url));
const p = spawn('node', [wranglerPath, 'dev', '-l', script, '--port', port]);
diff --git a/packages/integrations/cloudflare/test/with-solid-js.test.js b/packages/integrations/cloudflare/test/with-solid-js.test.js
index 270c387b5..90c1c0722 100644
--- a/packages/integrations/cloudflare/test/with-solid-js.test.js
+++ b/packages/integrations/cloudflare/test/with-solid-js.test.js
@@ -5,27 +5,28 @@ import * as cheerio from 'cheerio';
describe('With SolidJS', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
+ /** @type {import('./test-utils').WranglerCLI} */
+ let cli;
before(async () => {
fixture = await loadFixture({
root: './fixtures/with-solid-js/',
});
await fixture.build();
- });
- it('renders the solid component', async () => {
- const { ready, stop } = runCLI('./fixtures/with-solid-js/', { silent: true, port: 8790 });
+ cli = runCLI('./fixtures/with-solid-js/', { silent: true, port: 8790 });
+ await cli.ready;
+ });
- try {
- await ready;
+ after(async () => {
+ await cli.stop();
+ });
- let res = await fetch(`http://localhost:8790/`);
- expect(res.status).to.equal(200);
- let html = await res.text();
- let $ = cheerio.load(html);
- expect($('.solid').text()).to.equal('Solid Content');
- } finally {
- await stop();
- }
+ it('renders the solid component', async () => {
+ let res = await fetch(`http://localhost:8790/`);
+ expect(res.status).to.equal(200);
+ let html = await res.text();
+ let $ = cheerio.load(html);
+ expect($('.solid').text()).to.equal('Solid Content');
});
});