-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wrangler] Expose URL from url & node:url in node_compat mode (#5480)
* Add e2e tests & support node:url * Add changeset * Address comments
- Loading branch information
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
fix: Ensure url & node:url export URL (aliased to globalThis.URL) in node_compat mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,6 +183,39 @@ describe("basic dev tests", () => { | |
`, | ||
})); | ||
}); | ||
it("can import URL from 'url' in node_compat mode", async () => { | ||
await worker.seed((workerName) => ({ | ||
"wrangler.toml": dedent` | ||
name = "${workerName}" | ||
main = "src/index.ts" | ||
compatibility_date = "2023-01-01" | ||
node_compat = true | ||
`, | ||
"src/index.ts": dedent` | ||
const { URL } = require('url'); | ||
const { URL: nURL } = require('node:url'); | ||
export default { | ||
fetch(request) { | ||
const url = new URL('postgresql://user:[email protected]:12345/dbname?sslmode=disable') | ||
const nUrl = new nURL('postgresql://user:[email protected]:12345/dbname?sslmode=disable') | ||
return new Response(url + nUrl) | ||
} | ||
}`, | ||
})); | ||
await worker.runDevSession("", async (session) => { | ||
const { text } = await retry( | ||
(s) => s.status !== 200, | ||
async () => { | ||
const r = await fetch(`http://127.0.0.1:${session.port}`); | ||
return { text: await r.text(), status: r.status }; | ||
} | ||
); | ||
expect(text).toMatchInlineSnapshot( | ||
`"postgresql://user:[email protected]:12345/dbname?sslmode=disablepostgresql://user:[email protected]:12345/dbname?sslmode=disable"` | ||
); | ||
}); | ||
}); | ||
|
||
it("can modify worker during dev session (local)", async () => { | ||
await worker.runDevSession("", async (session) => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters