feat: now supports async functions for logging data
- `logger.debug('message', async () => ({ asyncReturn: await asyncFn() }))` is now supported
- NOTE: this may result in logging occurring out of band for these calls if other events fire befor they settle
Update CI labels to direct jobs to correct servers
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { createConsoleSink } from "../src/index";
|
||||
import type { LogEvent } from "../src/index";
|
||||
|
||||
function event(overrides: Partial<LogEvent> = {}): LogEvent {
|
||||
return {
|
||||
level: "debug",
|
||||
namespace: "API",
|
||||
arguments: ["hello"],
|
||||
timestamp: new Date(),
|
||||
environment: "development",
|
||||
sendToSentryLogs: false,
|
||||
sendToSentryIssue: false,
|
||||
sendToConsole: true,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("createConsoleSink", () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("appends [async] to the namespace label when event.async is set", () => {
|
||||
const debug = vi.spyOn(console, "debug").mockImplementation(() => undefined);
|
||||
createConsoleSink().emit(event({ async: true }));
|
||||
expect(debug).toHaveBeenCalled();
|
||||
const first = debug.mock.calls[0]?.[0];
|
||||
expect(String(first)).toContain("[API][async]");
|
||||
});
|
||||
|
||||
it("omits [async] for synchronous events", () => {
|
||||
const debug = vi.spyOn(console, "debug").mockImplementation(() => undefined);
|
||||
createConsoleSink().emit(event());
|
||||
expect(debug).toHaveBeenCalled();
|
||||
const first = debug.mock.calls[0]?.[0];
|
||||
expect(String(first)).toContain("[API]");
|
||||
expect(String(first)).not.toContain("[async]");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user