Skip to content
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

[wrangler] fix: switch default logging level of unstable_dev() to warn #5132

Merged
merged 1 commit into from
Mar 1, 2024
Merged
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
13 changes: 13 additions & 0 deletions .changeset/fluffy-yaks-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"wrangler": patch
---

fix: switch default logging level of `unstable_dev()` to `warn`

When running `unstable_dev()` in its default "test mode", the logging level was set to `none`. This meant any Worker startup errors or helpful warnings wouldn't be shown. This change switches the default to `warn`. To restore the previous behaviour, include `logLevel: "none"` in your options object:

```js
const worker = await unstable_dev("path/to/script.js", {
logLevel: "none",
});
```
7 changes: 7 additions & 0 deletions fixtures/local-mode-tests/src/nodejs-compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Buffer } from "node:buffer";

export default <ExportedHandler>{
async fetch() {
return new Response(Buffer.from("test").toString("base64"));
},
};
38 changes: 38 additions & 0 deletions fixtures/local-mode-tests/tests/logging.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import path from "node:path";
import util from "node:util";
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { unstable_dev } from "wrangler";

let output = "";
function spyOnConsoleMethod(name: keyof typeof console) {
vi.spyOn(console, name).mockImplementation((...args: unknown[]) => {
output += util.format(...args) + "\n";
});
}
beforeEach(() => {
spyOnConsoleMethod("debug");
spyOnConsoleMethod("log");
spyOnConsoleMethod("info");
spyOnConsoleMethod("error");
spyOnConsoleMethod("warn");
});
afterEach(() => {
vi.restoreAllMocks();
output = "";
});

it("logs startup errors", async () => {
try {
const worker = await unstable_dev(
path.resolve(__dirname, "..", "src", "nodejs-compat.ts"),
{
config: path.resolve(__dirname, "..", "wrangler.logging.toml"),
// Intentionally omitting `compatibilityFlags: ["nodejs_compat"]`
experimental: { disableExperimentalWarning: true },
}
);
await worker.stop();
expect.fail("Expected unstable_dev() to fail");
} catch {}
expect(output).toContain('No such module "node:buffer"');
});
2 changes: 2 additions & 0 deletions fixtures/local-mode-tests/wrangler.logging.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = "local-mode-tests"
compatibility_date = "2024-01-01"
2 changes: 1 addition & 1 deletion packages/wrangler/src/api/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export async function unstable_dev(
readyResolve = resolve;
});

const defaultLogLevel = testMode ? "none" : "log";
const defaultLogLevel = testMode ? "warn" : "log";
const local = options?.local ?? true;

const devOptions: StartDevOptions = {
Expand Down
Loading