Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tasty-moose-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Fixed duplicate warning messages appearing during wrangler dev when configuration changes or state transitions occur
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,53 @@ describe("ConfigController", () => {
},
});
});

it("should only log warnings once even with multiple config updates", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use a remote dev test here—they're flaky. Instead, test Analytics engine bindings with a service worker format worker

const std = mockConsoleMethods();

await seed({
"src/index.js": dedent/* javascript */ `
addEventListener('fetch', event => {
event.respondWith(new Response('hello world'))
})
`,
"wrangler.toml": dedent/* toml */ `
name = "my-worker"
main = "src/index.js"
compatibility_date = "2024-06-01"

[[analytics_engine_datasets]]
binding = "ANALYTICS"
dataset = "analytics_dataset"
`,
});

const event1 = waitForConfigUpdate(controller);
await controller.set({
config: "./wrangler.toml",
});
await event1;

const event2 = waitForConfigUpdate(controller);
await controller.patch({
dev: { liveReload: true },
});
await event2;

const event3 = waitForConfigUpdate(controller);
await controller.patch({
dev: { server: { port: 8787 } },
});
await event3;

const warningCount = std.warn
.split("\n")
.filter((line) =>
line.includes(
"Analytics Engine is not supported locally when using the service-worker format"
)
).length;

expect(warningCount).toBe(1);
});
});
9 changes: 9 additions & 0 deletions packages/wrangler/src/__tests__/dev.test.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add this?

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getWorkerAccountAndContext } from "../dev/remote";
import { COMPLIANCE_REGION_CONFIG_UNKNOWN } from "../environment-variables/misc-variables";
import { FatalError } from "../errors";
import { CI } from "../is-ci";
import { logger } from "../logger";
import { sniffUserAgent } from "../package-manager";
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
import { mockConsoleMethods } from "./helpers/mock-console";
Expand Down Expand Up @@ -2110,6 +2111,14 @@ describe.sequential("wrangler dev", () => {
});

describe("containers", () => {
beforeEach(() => {
// Clear logger.once history between tests to ensure test isolation.
// Without this, warnings logged via logger.once.warn() in one test
// would be suppressed in subsequent tests since they track logged
// messages globally across the test process.
logger.clearHistory();
});

const containerConfig = {
main: "index.js",
compatibility_date: "2024-01-01",
Expand Down
16 changes: 10 additions & 6 deletions packages/wrangler/src/api/startDevWorker/ConfigController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ async function resolveConfig(
!resolved.dev.remote &&
resolved.build.format === "service-worker"
) {
logger.warn(
logger.once.warn(
"Analytics Engine is not supported locally when using the service-worker format. Please migrate to the module worker format: https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/"
);
}
Expand All @@ -405,7 +405,7 @@ async function resolveConfig(

const services = extractBindingsOfType("service", resolved.bindings);
if (services && services.length > 0 && resolved.dev?.remote) {
logger.warn(
logger.once.warn(
`This worker is bound to live services: ${services
.map(
(service) =>
Expand All @@ -418,7 +418,7 @@ async function resolveConfig(
}

if (!resolved.dev?.origin?.secure && resolved.dev?.remote) {
logger.warn(
logger.once.warn(
"Setting upstream-protocol to http is not currently supported for remote mode.\n" +
"If this is required in your project, please add your use case to the following issue:\n" +
"https://github.com/cloudflare/workers-sdk/issues/583."
Expand All @@ -442,7 +442,9 @@ async function resolveConfig(
(queues?.length ||
resolved.triggers?.some((t) => t.type === "queue-consumer"))
) {
logger.warn("Queues are not yet supported in wrangler dev remote mode.");
logger.once.warn(
"Queues are not yet supported in wrangler dev remote mode."
);
}

if (resolved.dev.remote) {
Expand All @@ -453,7 +455,7 @@ async function resolveConfig(
resolved.containers &&
resolved.containers.length > 0
) {
logger.warn(
logger.once.warn(
"Containers are only supported in local mode, to suppress this warning set `dev.enable_containers` to `false` or pass `--enable-containers=false` to the `wrangler dev` command"
);
}
Expand All @@ -466,7 +468,9 @@ async function resolveConfig(
resolved.dev.remote &&
Array.from(classNamesWhichUseSQLite.values()).some((v) => v)
) {
logger.warn("SQLite in Durable Objects is only supported in local mode.");
logger.once.warn(
"SQLite in Durable Objects is only supported in local mode."
);
}
}

Expand Down
Loading