Update wrangler (#8081)

* chore: update wrangler

* chore(cloudflare): update tests to support wrangler@3

* chore(cloudflare): update debug message

* chore: force ci
This commit is contained in:
Nate Moore 2023-08-15 12:10:51 -05:00 committed by GitHub
parent 087270c61f
commit 74df833708
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 431 additions and 534 deletions

View file

@ -52,7 +52,8 @@
"astro-scripts": "workspace:*", "astro-scripts": "workspace:*",
"chai": "^4.3.7", "chai": "^4.3.7",
"cheerio": "1.0.0-rc.12", "cheerio": "1.0.0-rc.12",
"kill-port": "^2.0.1",
"mocha": "^9.2.2", "mocha": "^9.2.2",
"wrangler": "^2.0.23" "wrangler": "^3.5.0"
} }
} }

View file

@ -14,7 +14,7 @@ describe('Basic app', () => {
}); });
await fixture.build(); await fixture.build();
cli = runCLI('./fixtures/basics/', { silent: true, port: 8789 }); cli = await runCLI('./fixtures/basics/', { silent: true, port: 8789 });
await cli.ready; await cli.ready;
}); });
@ -23,7 +23,7 @@ describe('Basic app', () => {
}); });
it('can render', async () => { 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); expect(res.status).to.equal(200);
let html = await res.text(); let html = await res.text();
let $ = cheerio.load(html); let $ = cheerio.load(html);

View file

@ -17,7 +17,7 @@ describe('Cf metadata and caches', () => {
}); });
await fixture.build(); await fixture.build();
cli = runCLI('./fixtures/cf/', { silent: false, port: 8788 }); cli = await runCLI('./fixtures/cf/', { silent: false, port: 8788 });
await cli.ready; await cli.ready;
}); });
@ -26,12 +26,12 @@ describe('Cf metadata and caches', () => {
}); });
it('Load cf and caches API', async () => { 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); expect(res.status).to.equal(200);
let html = await res.text(); let html = await res.text();
let $ = cheerio.load(html); 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'); expect($('#hasCache').text()).to.equal('true');
}); });
}); });

View file

@ -17,7 +17,7 @@ describe('Runtime Locals', () => {
}); });
await fixture.build(); await fixture.build();
cli = runCLI('./fixtures/runtime/', { silent: true, port: 8793 }); cli = await runCLI('./fixtures/runtime/', { silent: true, port: 8793 });
await cli.ready; await cli.ready;
}); });
@ -26,7 +26,7 @@ describe('Runtime Locals', () => {
}); });
it('has CF and Caches', async () => { 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); expect(res.status).to.equal(200);
let html = await res.text(); let html = await res.text();
let $ = cheerio.load(html); let $ = cheerio.load(html);

View file

@ -1,5 +1,6 @@
import { spawn } from 'node:child_process'; import { spawn } from 'node:child_process';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
import kill from 'kill-port';
import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js'; import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js';
export { fixLineEndings } 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 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.stderr.setEncoding('utf-8');
p.stdout.setEncoding('utf-8'); p.stdout.setEncoding('utf-8');
const timeout = 10000; const timeout = 10_000;
const ready = new Promise(async (resolve, reject) => { const ready = new Promise(async (resolve, reject) => {
const failed = setTimeout( const failed = setTimeout(
() => reject(new Error(`Timed out starting the wrangler CLI`)), () => {
p.kill();
reject(new Error(`Timed out starting the wrangler CLI`));
},
timeout timeout
); );
@ -50,7 +61,7 @@ export function runCLI(basePath, { silent, port = 8787 }) {
if (!silent) { if (!silent) {
console.log(msg); console.log(msg);
} }
if (msg.includes(`Listening on`)) { if (msg.includes(`[mf:inf] Ready on`)) {
break; break;
} }
} }

View file

@ -14,7 +14,7 @@ describe('With SolidJS', () => {
}); });
await fixture.build(); 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; await cli.ready;
}); });
@ -23,7 +23,7 @@ describe('With SolidJS', () => {
}); });
it('renders the solid component', async () => { 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); expect(res.status).to.equal(200);
let html = await res.text(); let html = await res.text();
let $ = cheerio.load(html); let $ = cheerio.load(html);

View file

@ -1,4 +1,6 @@
# for tests only # for tests only
send_metrics = false
[vars] [vars]
SECRET_STUFF = "secret" SECRET_STUFF = "secret"

File diff suppressed because it is too large Load diff