-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[wrangler] test: fix E2E tests #4907
New issue
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
Changes from all commits
a4215e9
f532eb8
2283d81
c6e3dde
9de08d7
970d659
bc423c9
bef4ac4
47f1f0c
6fae44d
57480ea
d9a3654
f6e8616
00eaa3f
e8bb9b3
92c88f6
1164b08
81b9762
d2390dc
63ab5e5
0a22759
cc604b0
ce4a7f8
98e1bd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "wrangler": patch | ||
| --- | ||
|
|
||
| fix: mark R2 object and bucket not found errors as unreportable | ||
|
|
||
| Previously, running `wrangler r2 objects {get,put}` with an object or bucket that didn't exist would ask if you wanted to report that error to Cloudflare. There's nothing we can do to fix this, so this change prevents the prompt in this case. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "wrangler": patch | ||
| --- | ||
|
|
||
| fix: ensure `wrangler dev --log-level` flag applied to all logs | ||
|
|
||
| Previously, `wrangler dev` may have ignored the `--log-level` flag for some startup logs. This change ensures the `--log-level` flag is applied immediately. |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,15 +4,23 @@ import { existsSync } from "node:fs"; | |
| import * as nodeNet from "node:net"; | ||
| import path from "node:path"; | ||
| import { setTimeout } from "node:timers/promises"; | ||
| import getPort from "get-port"; | ||
| import shellac from "shellac"; | ||
| import { fetch } from "undici"; | ||
| import { Agent, fetch, setGlobalDispatcher } from "undici"; | ||
| import { afterEach, beforeEach, describe, expect, it } from "vitest"; | ||
| import { normalizeOutput } from "./helpers/normalize"; | ||
| import { retry } from "./helpers/retry"; | ||
| import { dedent, makeRoot, seed } from "./helpers/setup"; | ||
| import { WRANGLER } from "./helpers/wrangler-command"; | ||
|
|
||
| // Use `Agent` with lower timeouts so `fetch()`s inside `retry()`s don't block for a long time | ||
| setGlobalDispatcher( | ||
| new Agent({ | ||
| connectTimeout: 10_000, | ||
| headersTimeout: 10_000, | ||
| bodyTimeout: 10_000, | ||
| }) | ||
| ); | ||
|
|
||
| type MaybePromise<T = void> = T | Promise<T>; | ||
|
|
||
| const waitForPortToBeBound = async (port: number) => { | ||
|
|
@@ -31,11 +39,7 @@ const waitUntilOutputContains = async ( | |
| (stdout) => !stdout.includes(substring), | ||
| async () => { | ||
| await setTimeout(intervalMs); | ||
| return ( | ||
| normalizeOutput(session.stdout) + | ||
| "\n\n\n" + | ||
| normalizeOutput(session.stderr) | ||
| ); | ||
| return session.stdout + "\n\n\n" + session.stderr; | ||
| } | ||
| ); | ||
| }; | ||
|
|
@@ -46,6 +50,20 @@ interface SessionData { | |
| stderr: string; | ||
| } | ||
|
|
||
| function getPort() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use the |
||
| return new Promise<number>((resolve, reject) => { | ||
| const server = nodeNet.createServer((socket) => socket.destroy()); | ||
| server.listen(0, () => { | ||
| const address = server.address(); | ||
| assert(typeof address === "object" && address !== null); | ||
| server.close((err) => { | ||
| if (err) reject(err); | ||
| else resolve(address.port); | ||
| }); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| async function runDevSession( | ||
| workerPath: string, | ||
| flags: string, | ||
|
|
@@ -65,7 +83,11 @@ async function runDevSession( | |
|
|
||
| // Must use the `in` statement in the shellac script rather than `.in()` modifier on the `shellac` object | ||
| // otherwise the working directory does not get picked up. | ||
| let promiseResolve: (() => void) | undefined; | ||
| const promise = new Promise<void>((resolve) => (promiseResolve = resolve)); | ||
|
Comment on lines
+86
to
+87
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: could probably use createDeferred here |
||
| const bg = await shellac.env(process.env).bg` | ||
| await ${() => promise} | ||
|
|
||
| in ${workerPath} { | ||
| exits { | ||
| $ ${WRANGLER} dev ${flags} | ||
|
|
@@ -82,12 +104,18 @@ async function runDevSession( | |
| }; | ||
| bg.process.stdout.on("data", (chunk) => (sessionData.stdout += chunk)); | ||
| bg.process.stderr.on("data", (chunk) => (sessionData.stderr += chunk)); | ||
| // Only start `wrangler dev` once we've registered output listeners so we don't miss messages | ||
| promiseResolve?.(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking but... this is a bit gross and we should investigate fixing the need for this in shellac |
||
|
|
||
| await session(sessionData); | ||
|
|
||
| return bg.promise; | ||
| } finally { | ||
| if (pid) process.kill(pid); | ||
| try { | ||
| if (pid) process.kill(pid); | ||
| } catch { | ||
| // Ignore errors if we failed to kill the process (i.e. ESRCH if it's already terminated) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -489,14 +517,14 @@ describe("writes debug logs to hidden file", () => { | |
| async (session) => { | ||
| await waitForPortToBeBound(session.port); | ||
|
|
||
| await waitUntilOutputContains(session, "🐛 Writing debug logs to"); | ||
| await waitUntilOutputContains(session, "Writing logs to"); | ||
|
|
||
| await setTimeout(1000); // wait a bit to ensure the file is written to disk | ||
| } | ||
| ); | ||
|
|
||
| const filepath = finalA.stdout.match( | ||
| /🐛 Writing debug logs to "(.+\.log)"/ | ||
| /🪵 {2}Writing logs to "(.+\.log)"/ | ||
| )?.[1]; | ||
| assert(filepath); | ||
|
|
||
|
|
@@ -511,13 +539,13 @@ describe("writes debug logs to hidden file", () => { | |
| }); | ||
|
|
||
| const filepath = finalA.stdout.match( | ||
| /🐛 Writing debug logs to "(.+\.log)"/ | ||
| /🪵 {2}Writing logs to "(.+\.log)"/ | ||
| )?.[1]; | ||
|
|
||
| expect(filepath).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("rewrites address-in-use error logs", async () => { | ||
| it.skip("rewrites address-in-use error logs", async () => { | ||
| // 1. start worker A on a (any) port | ||
| await a.runDevSession("", async (sessionA) => { | ||
| const normalize = (text: string) => | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍