-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
bug: deno test --doc
incorrectly evaluates snippets
#25718
Comments
Here's why this issue happens - this code snippet import { getLogger } from "@std/log";
const logger = getLogger("my-awesome-module");
export function sum(a: number, b: number) {
logger.debug(`running ${a} + ${b}`); // no message will be logged, because getLogger() was called before log.setup()
return a + b;
} is first virtually converted into import { getLogger } from "@std/log";
Deno.test("<test-name>", async () => {
const logger = getLogger("my-awesome-module");
export function sum(a: number, b: number) {
logger.debug(`running ${a} + ${b}`); // no message will be logged, because getLogger() was called before log.setup()
return a + b;
}
}); but right after this, the code converter (precisely speaking, swc) detects that import { getLogger } from "@std/log";
Deno.test("<test-name>", async () => {
const logger = getLogger("my-awesome-module");
});
export function sum(a: number, b: number) {
logger.debug(`running ${a} + ${b}`); // no message will be logged, because getLogger() was called before log.setup()
return a + b;
} Therefore I'll try to consider what would be the best fix for this. |
I suggest printing a warning for a snippet containing exported symbols. I don't think snippets would typically contain them. In the meantime, I'll remove the |
That sounds like a sensible solution, though I had started with the difference approach which can be seen #2570. The idea is to remove |
To reproduce:
git clone https://github.com/denoland/std.git
deno test --doc log/mod.ts
using latest canary and get the following:These same snippets run fine:
Version: Deno 2.0.0-rc.3+c3bc692
The text was updated successfully, but these errors were encountered: