We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unstable_dev
Wrangler
2.8.1
Mac
Due to the code here: https://github.com/cloudflare/wrangler2/blob/89d78c0ac444885298ac052b0b3de23b69fb029b/packages/wrangler/src/api/dev.ts#L302-L328
The URL that's passed into fetch for unstable_dev does not handle query params. This obviously causes any test using these to fail.
fetch
Repro:
import { writeFile } from 'fs/promises'; import { expect, test } from 'vitest'; import { unstable_dev } from 'wrangler'; test('unstable_dev fetch repro', async () => { const script = ` export default { fetch(req) { const url = new URL(req.url); const name = url.searchParams.get('name'); return new Response('Hello, ' + name); } } `; await writeFile('script.js', script, { encoding: 'utf8' }); const worker = await unstable_dev('script.js'); const res = await worker.fetch('http://worker?name=Walshy'); expect(res.status).toBe(200); const text = await res.text(); expect(text).toBe('Hello, Walshy'); await worker.stop(); });
Error:
FAIL test/repro.test.ts > unstable_dev fetch repro AssertionError: expected 'Hello, null' to be 'Hello, Walshy' // Object.is equality ❯ test/repro.test.ts:25:15 23| const text = await res.text(); 24| 25| expect(text).toBe('Hello, Walshy'); | ^ 26| 27| await worker.stop(); - Expected "Hello, Walshy" + Received "Hello, null"
A fix I'd suggest is instead just relying on the URL object, something like:
const url = new URL(input); url.protocol = `${protocol}:`; url.hostname = readyAddress; url.port = readyPort; input = url.toString();
Instead of manually constructing the URL string.
The text was updated successfully, but these errors were encountered:
Related/additionally, it doesn't unpack a Request at all if it's passed in, so even changing the path has no effect if you use the template:
Request
workers-sdk/templates/worker-typescript/src/index.test.ts
Lines 17 to 18 in 6fd0624
i.e. If you change that to new Request('http://falcon/foo', { method: 'GET' }); your app receives http://ip:port/ as the request.url
new Request('http://falcon/foo', { method: 'GET' });
http://ip:port/
request.url
Sorry, something went wrong.
.fetch
Successfully merging a pull request may close this issue.
Which Cloudflare product(s) does this pertain to?
Wrangler
What version of
Wrangler
are you using?2.8.1
What operating system are you using?
Mac
Describe the Bug
Due to the code here:
https://github.com/cloudflare/wrangler2/blob/89d78c0ac444885298ac052b0b3de23b69fb029b/packages/wrangler/src/api/dev.ts#L302-L328
The URL that's passed into
fetch
forunstable_dev
does not handle query params. This obviously causes any test using these to fail.Repro:
Error:
A fix I'd suggest is instead just relying on the URL object, something like:
Instead of manually constructing the URL string.
The text was updated successfully, but these errors were encountered: