Skip to content

Commit 139b5ec

Browse files
authored
Prevent infinite console.log()/console.info() loops with Wrangler E2E tests (#8163)
* Prevent infinite console.log/console.info loops with Vitest v3 * Fix ESLint * Rearrange remote/local
1 parent ed91624 commit 139b5ec

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

packages/wrangler/e2e/startWorker.test.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,16 @@ describe.each(OPTIONS)("DevEnv (remote: $remote)", ({ remote }) => {
201201
// through a worker (InspectorProxyWorker) which hits the limit (without the fix, compatibilityFlags:["increase_websocket_message_size"])
202202
// By logging a large string we can verify that the inspector messages are being proxied successfully.
203203
it("InspectorProxyWorker can proxy messages > 1MB", async (t) => {
204-
t.onTestFinished(() => worker?.dispose());
205-
206-
const originalConsoleLog = console.log;
207-
const mockConsoleLogImpl = (message: unknown, ...args: unknown[]) => {
208-
if (typeof message === "string" && /z+/.test(message)) {
209-
return; // don't log chunks of the large string
210-
}
211-
212-
originalConsoleLog(message, ...args);
213-
};
214-
vi.spyOn(console, "info").mockImplementation(mockConsoleLogImpl);
215-
vi.spyOn(console, "log").mockImplementation(mockConsoleLogImpl);
204+
const consoleInfoSpy = vi
205+
.spyOn(console, "info")
206+
.mockImplementation(() => {});
207+
const consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {});
208+
209+
t.onTestFinished(() => {
210+
consoleInfoSpy.mockRestore();
211+
consoleLogSpy.mockRestore();
212+
return worker?.dispose();
213+
});
216214

217215
const LARGE_STRING = "This is a large string" + "z".repeat(2 ** 20);
218216

@@ -250,9 +248,7 @@ describe.each(OPTIONS)("DevEnv (remote: $remote)", ({ remote }) => {
250248
expect(consoleApiMessages).toContainMatchingObject({
251249
method: "Runtime.consoleAPICalled",
252250
params: expect.objectContaining({
253-
args: [
254-
{ type: "string", value: expect.stringContaining("zzzzzzzzz") },
255-
],
251+
args: [{ type: "string", value: LARGE_STRING }],
256252
}),
257253
});
258254
},

0 commit comments

Comments
 (0)