70bf21e064
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import dedent from "ts-dedent";
|
|
import { test, vitestConfig } from "./helpers";
|
|
|
|
test("routes workerd structured logs to the correct output stream", async ({
|
|
expect,
|
|
seed,
|
|
vitestRun,
|
|
}) => {
|
|
await seed({
|
|
"vitest.config.mts": vitestConfig(),
|
|
"index.test.ts": dedent`
|
|
import { it, expect } from "vitest";
|
|
it("emits structured logs at various levels", () => {
|
|
// __console is the original workerd console, saved before Vitest
|
|
// patches globalThis.console. Output from __console goes through
|
|
// workerd stdout -> structured log parsing -> handleStructuredLogs,
|
|
// which routes error/warn to process.stderr and everything else
|
|
// to process.stdout.
|
|
__console.log("__STDOUT_LOG__");
|
|
__console.warn("__STDERR_WARN__");
|
|
__console.error("__STDERR_ERROR__");
|
|
expect(true).toBe(true);
|
|
});
|
|
`,
|
|
});
|
|
const result = await vitestRun();
|
|
expect(await result.exitCode).toBe(0);
|
|
|
|
// handleStructuredLogs routes log-level output to stdout
|
|
expect(result.stdout).toContain("__STDOUT_LOG__");
|
|
|
|
// handleStructuredLogs routes warn/error-level output to stderr
|
|
expect(result.stderr).toContain("__STDERR_WARN__");
|
|
expect(result.stderr).toContain("__STDERR_ERROR__");
|
|
});
|