Skip to content

Commit 88514c8

Browse files
authored
Better messaging in dev console (#7986)
* docs: add better console messaging for remote development * e2e fix * one more * fix snapshot * Ensure logging only once, and remove unnecssary message * fix whitespace
1 parent cee82fa commit 88514c8

File tree

6 files changed

+153
-69
lines changed

6 files changed

+153
-69
lines changed

.changeset/light-taxis-move.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
docs: clarifies that local resources are "simulated locally" or "connected to remote resource", and adds console messages to help explain local dev

packages/wrangler/e2e/__snapshots__/pages-dev.test.ts.snap

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,30 @@ exports[`Pages 'wrangler pages dev' > should merge (with override) \`wrangler.to
77
Remote Durable Objects that are affected:
88
- {"name":"DO_BINDING_1_TOML","class_name":"DO_1_TOML","script_name":"DO_SCRIPT_1_TOML"}
99
- {"name":"DO_BINDING_2_TOML","class_name":"DO_2_TOML","script_name":"DO_SCRIPT_2_TOML"}
10+
Your Worker and resources are simulated locally via Miniflare. For more information, see: https://developers.cloudflare.com/workers/testing/local-development.
1011
Your worker has access to the following bindings:
1112
- Durable Objects:
12-
- DO_BINDING_1_TOML: NEW_DO_1 (defined in NEW_DO_SCRIPT_1 [not connected]) (local)
13-
- DO_BINDING_2_TOML: DO_2_TOML (defined in DO_SCRIPT_2_TOML [not connected]) (local)
14-
- DO_BINDING_3_ARGS: DO_3_ARGS (defined in DO_SCRIPT_3_ARGS [not connected]) (local)
13+
- DO_BINDING_1_TOML: NEW_DO_1 (defined in NEW_DO_SCRIPT_1 [not connected])
14+
- DO_BINDING_2_TOML: DO_2_TOML (defined in DO_SCRIPT_2_TOML [not connected])
15+
- DO_BINDING_3_ARGS: DO_3_ARGS (defined in DO_SCRIPT_3_ARGS [not connected])
1516
- KV Namespaces:
16-
- KV_BINDING_1_TOML: NEW_KV_ID_1 (local)
17-
- KV_BINDING_2_TOML: KV_ID_2_TOML (local)
18-
- KV_BINDING_3_ARGS: KV_ID_3_ARGS (local)
17+
- KV_BINDING_1_TOML: NEW_KV_ID_1 [simulated locally]
18+
- KV_BINDING_2_TOML: KV_ID_2_TOML [simulated locally]
19+
- KV_BINDING_3_ARGS: KV_ID_3_ARGS [simulated locally]
1920
- D1 Databases:
20-
- D1_BINDING_1_TOML: local-D1_BINDING_1_TOML=NEW_D1_NAME_1 (NEW_D1_NAME_1) (local)
21-
- D1_BINDING_2_TOML: D1_NAME_2_TOML (D1_ID_2_TOML) (local)
22-
- D1_BINDING_3_ARGS: local-D1_BINDING_3_ARGS=D1_NAME_3_ARGS (D1_NAME_3_ARGS) (local)
21+
- D1_BINDING_1_TOML: local-D1_BINDING_1_TOML=NEW_D1_NAME_1 (NEW_D1_NAME_1) [simulated locally]
22+
- D1_BINDING_2_TOML: D1_NAME_2_TOML (D1_ID_2_TOML) [simulated locally]
23+
- D1_BINDING_3_ARGS: local-D1_BINDING_3_ARGS=D1_NAME_3_ARGS (D1_NAME_3_ARGS) [simulated locally]
2324
- R2 Buckets:
24-
- R2_BINDING_1_TOML: NEW_R2_BUCKET_1 (local)
25-
- R2_BINDING_2_TOML: R2_BUCKET_2_TOML (local)
26-
- R2_BINDING_3_TOML: R2_BUCKET_3_ARGS (local)
25+
- R2_BINDING_1_TOML: NEW_R2_BUCKET_1 [simulated locally]
26+
- R2_BINDING_2_TOML: R2_BUCKET_2_TOML [simulated locally]
27+
- R2_BINDING_3_TOML: R2_BUCKET_3_ARGS [simulated locally]
2728
- Services:
2829
- SERVICE_BINDING_1_TOML: NEW_SERVICE_NAME_1 [not connected]
2930
- SERVICE_BINDING_2_TOML: SERVICE_NAME_2_TOML [not connected]
3031
- SERVICE_BINDING_3_TOML: SERVICE_NAME_3_ARGS [not connected]
3132
- AI:
32-
- Name: AI_BINDING_2_TOML
33+
- Name: AI_BINDING_2_TOML [connected to remote resource]
3334
- Vars:
3435
- VAR1: "(hidden)"
3536
- VAR2: "VAR_2_TOML"

packages/wrangler/e2e/pages-dev.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ describe.sequential.each([{ cmd: "wrangler pages dev" }])(
121121
expect(normalizeOutput(worker.currentOutput)).toContain(
122122
dedent`Your worker has access to the following bindings:
123123
- Durable Objects:
124-
- TEST_DO: TestDurableObject (defined in a [not connected]) (local)
124+
- TEST_DO: TestDurableObject (defined in a [not connected])
125125
- KV Namespaces:
126-
- TEST_KV: TEST_KV (local)
126+
- TEST_KV: TEST_KV [simulated locally]
127127
- D1 Databases:
128-
- TEST_D1: local-TEST_D1 (TEST_D1) (local)
128+
- TEST_D1: local-TEST_D1 (TEST_D1) [simulated locally]
129129
- R2 Buckets:
130-
- TEST_R2: TEST_R2 (local)
130+
- TEST_R2: TEST_R2 [simulated locally]
131131
- Services:
132132
- TEST_SERVICE: test-worker [not connected]
133133
`
@@ -327,7 +327,7 @@ describe.sequential.each([{ cmd: "wrangler pages dev" }])(
327327
expect(normalizeOutput(worker.currentOutput)).toContain(
328328
dedent`Your worker has access to the following bindings:
329329
- KV Namespaces:
330-
- KV_BINDING_TOML: KV_ID_TOML (local)
330+
- KV_BINDING_TOML: KV_ID_TOML [simulated locally]
331331
- Vars:
332332
- PAGES: "⚡️ Pages ⚡️"
333333
`

packages/wrangler/src/__tests__/dev.test.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import registerDevHotKeys from "../dev/hotkeys";
1111
import { getWorkerAccountAndContext } from "../dev/remote";
1212
import { FatalError } from "../errors";
1313
import { CI } from "../is-ci";
14+
import { logger } from "../logger";
1415
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
1516
import { mockConsoleMethods } from "./helpers/mock-console";
1617
import { useMockIsTTY } from "./helpers/mock-istty";
@@ -129,6 +130,7 @@ describe.sequential("wrangler dev", () => {
129130
...mswSuccessOauthHandlers,
130131
...mswSuccessUserHandlers
131132
);
133+
logger.clearHistory();
132134
});
133135

134136
runInTempDir();
@@ -1208,12 +1210,14 @@ describe.sequential("wrangler dev", () => {
12081210
process.platform === "win32" ? "127.0.0.1" : "localhost"
12091211
);
12101212
expect(std.out).toMatchInlineSnapshot(`
1211-
"Your worker has access to the following bindings:
1213+
"Your Worker and resources are simulated locally via Miniflare. For more information, see: https://developers.cloudflare.com/workers/testing/local-development.
1214+
1215+
Your worker has access to the following bindings:
12121216
- Durable Objects:
1213-
- NAME_1: CLASS_1 (local)
1214-
- NAME_2: CLASS_2 (defined in SCRIPT_A [not connected]) (local)
1215-
- NAME_3: CLASS_3 (local)
1216-
- NAME_4: CLASS_4 (defined in SCRIPT_B [not connected]) (local)
1217+
- NAME_1: CLASS_1
1218+
- NAME_2: CLASS_2 (defined in SCRIPT_A [not connected])
1219+
- NAME_3: CLASS_3
1220+
- NAME_4: CLASS_4 (defined in SCRIPT_B [not connected])
12171221
"
12181222
`);
12191223
expect(std.warn).toMatchInlineSnapshot(`
@@ -1299,6 +1303,8 @@ describe.sequential("wrangler dev", () => {
12991303
});
13001304
expect(std.out).toMatchInlineSnapshot(`
13011305
"Using vars defined in .dev.vars
1306+
Your Worker and resources are simulated locally via Miniflare. For more information, see: https://developers.cloudflare.com/workers/testing/local-development.
1307+
13021308
Your worker has access to the following bindings:
13031309
- Vars:
13041310
- VAR_1: \\"(hidden)\\"
@@ -1333,6 +1339,8 @@ describe.sequential("wrangler dev", () => {
13331339
expect(varBindings).toEqual({ CUSTOM_VAR: "custom" });
13341340
expect(std.out).toMatchInlineSnapshot(`
13351341
"Using vars defined in .dev.vars.custom
1342+
Your Worker and resources are simulated locally via Miniflare. For more information, see: https://developers.cloudflare.com/workers/testing/local-development.
1343+
13361344
Your worker has access to the following bindings:
13371345
- Vars:
13381346
- CUSTOM_VAR: \\"(hidden)\\"
@@ -1853,7 +1861,9 @@ describe.sequential("wrangler dev", () => {
18531861
fs.writeFileSync("index.js", `export default {};`);
18541862
await runWranglerUntilConfig("dev index.js");
18551863
expect(std.out).toMatchInlineSnapshot(`
1856-
"Your worker has access to the following bindings:
1864+
"Your Worker and resources are simulated locally via Miniflare. For more information, see: https://developers.cloudflare.com/workers/testing/local-development.
1865+
1866+
Your worker has access to the following bindings:
18571867
- Services:
18581868
- WorkerA: A [not connected]
18591869
- WorkerB: B [not connected]
@@ -1874,7 +1884,9 @@ describe.sequential("wrangler dev", () => {
18741884
fs.writeFileSync("index.js", `export default {};`);
18751885
await runWranglerUntilConfig("dev index.js");
18761886
expect(std.out).toMatchInlineSnapshot(`
1877-
"Your worker has access to the following bindings:
1887+
"Your Worker and resources are simulated locally via Miniflare. For more information, see: https://developers.cloudflare.com/workers/testing/local-development.
1888+
1889+
Your worker has access to the following bindings:
18781890
- Services:
18791891
- WorkerA: A [not connected]
18801892
- WorkerB: B [not connected]
@@ -1901,6 +1913,8 @@ describe.sequential("wrangler dev", () => {
19011913
await runWranglerUntilConfig("dev index.js");
19021914
expect(std.out).toMatchInlineSnapshot(`
19031915
"Using vars defined in .dev.vars
1916+
Your Worker and resources are simulated locally via Miniflare. For more information, see: https://developers.cloudflare.com/workers/testing/local-development.
1917+
19041918
Your worker has access to the following bindings:
19051919
- Vars:
19061920
- variable: 123

packages/wrangler/src/logger.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export class Logger {
5555
constructor() {}
5656

5757
private overrideLoggerLevel?: LoggerLevel;
58+
private onceHistory = new Set<string>();
5859

5960
get loggerLevel() {
6061
return this.overrideLoggerLevel ?? getLoggerLevel();
@@ -107,7 +108,6 @@ export class Logger {
107108
Logger.#afterLogHook?.();
108109
}
109110

110-
static onceHistory = new Set();
111111
get once() {
112112
return {
113113
info: (...args: unknown[]) => this.doLogOnce("info", args),
@@ -116,14 +116,16 @@ export class Logger {
116116
error: (...args: unknown[]) => this.doLogOnce("error", args),
117117
};
118118
}
119-
doLogOnce(messageLevel: Exclude<LoggerLevel, "none">, args: unknown[]) {
120-
// using this.constructor.onceHistory, instead of hard-coding Logger.onceHistory, allows for subclassing
121-
const { onceHistory } = this.constructor as typeof Logger;
122119

120+
clearHistory() {
121+
this.onceHistory.clear();
122+
}
123+
124+
doLogOnce(messageLevel: Exclude<LoggerLevel, "none">, args: unknown[]) {
123125
const cacheKey = `${messageLevel}: ${args.join(" ")}`;
124126

125-
if (!onceHistory.has(cacheKey)) {
126-
onceHistory.add(cacheKey);
127+
if (!this.onceHistory.has(cacheKey)) {
128+
this.onceHistory.add(cacheKey);
127129
this.doLog(messageLevel, args);
128130
}
129131
}

0 commit comments

Comments
 (0)