Skip to content

Commit c088e05

Browse files
test: add process.stderr and process.stdout tests to the worker-logs fixture
1 parent d8f30b8 commit c088e05

File tree

5 files changed

+48
-9
lines changed

5 files changed

+48
-9
lines changed

fixtures/worker-logs/src/module.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export default {
2020
console.debug("<<<<<this is a debug message>>>>>");
2121
console.info("<<<<<this is an info message>>>>>");
2222

23+
process.stderr.write("<<<<<this is a stderr message>>>>>\n");
24+
process.stdout.write("<<<<<this is a stdout message>>>>>\n");
25+
2326
return response;
2427
},
2528
};

fixtures/worker-logs/tests/index.test.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ describe("'wrangler dev' correctly displays logs", () => {
7070
"X [ERROR] <<<<<this is an error>>>>>
7171
▲ [WARNING] <<<<<this is a warning>>>>>
7272
<<<<<this is a log>>>>>
73+
<<<<<this is a stderr message>>>>>
74+
<<<<<this is a stdout message>>>>>
7375
<<<<<this is an info message>>>>>"
7476
`);
7577
});
@@ -80,6 +82,8 @@ describe("'wrangler dev' correctly displays logs", () => {
8082
"X [ERROR] <<<<<this is an error>>>>>
8183
▲ [WARNING] <<<<<this is a warning>>>>>
8284
<<<<<this is a log>>>>>
85+
<<<<<this is a stderr message>>>>>
86+
<<<<<this is a stdout message>>>>>
8387
<<<<<this is an info message>>>>>"
8488
`);
8589
});
@@ -111,15 +115,24 @@ describe("'wrangler dev' correctly displays logs", () => {
111115
});
112116

113117
test("with --log-level=debug", async ({ expect }) => {
114-
const output = await getWranglerDevOutput(
115-
"module",
116-
["--log-level=debug"],
117-
undefined,
118-
// For some reason in debug mode two requests are
119-
// needed to trigger the log here...
120-
2
118+
const output = await getWranglerDevOutput("module", [
119+
"--log-level=debug",
120+
]);
121+
expect(
122+
Array.from(output.matchAll(/^.*<<<<<.*$/gm)).flat()
123+
).toMatchInlineSnapshot(
124+
`
125+
[
126+
"X [ERROR] <<<<<this is an error>>>>>",
127+
"▲ [WARNING] <<<<<this is a warning>>>>>",
128+
"<<<<<this is a debug message>>>>>",
129+
"<<<<<this is a log>>>>>",
130+
"<<<<<this is a stderr message>>>>>",
131+
"<<<<<this is a stdout message>>>>>",
132+
"<<<<<this is an info message>>>>>",
133+
]
134+
`
121135
);
122-
expect(output).toContain("<<<<<this is a debug message>>>>>");
123136
});
124137

125138
test('with WRANGLER_LOG="debug"', async ({ expect }) => {

fixtures/worker-logs/turbo.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$schema": "http://turbo.build/schema.json",
3+
"extends": ["//"],
4+
"tasks": {
5+
"test:ci": {
6+
"env": [
7+
"VITEST",
8+
"NODE_DEBUG",
9+
"MINIFLARE_WORKERD_PATH",
10+
"WRANGLER",
11+
"WRANGLER_IMPORT",
12+
"MINIFLARE_IMPORT",
13+
"CLOUDFLARE_ACCOUNT_ID",
14+
"CLOUDFLARE_API_TOKEN",
15+
"TEST_CLOUDFLARE_ACCOUNT_ID",
16+
"TEST_CLOUDFLARE_API_TOKEN",
17+
"WRANGLER_E2E_TEST_FILE"
18+
]
19+
}
20+
}
21+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "worker-logs",
3-
"compatibility_date": "2022-03-31",
3+
"compatibility_date": "2025-09-01",
44
"main": "src/module.js",
5+
"compatibility_flags": ["nodejs_compat", "enable_nodejs_process_v2"],
56
}

fixtures/worker-logs/wrangler.service.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
"name": "worker-logs",
33
"compatibility_date": "2022-03-31",
44
"main": "src/service.js",
5+
"compatibility_flags": ["nodejs_compat", "enable_nodejs_process_v2"],
56
}

0 commit comments

Comments
 (0)