# test.build/core/converters/browser.converter.test.ts

> 41 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-build-core-converters-browser-converter-test-ts
Source text: https://banes-lab.com/source/testing/test.build/core/converters/browser.converter.test.ts.txt

Listed in [test.build/core/converters](https://banes-lab.com/api/source/testing/test.build/core/converters.md), after [test.build/core/converters/baseline.converter.test.ts](https://banes-lab.com/source/testing/test.build/core/converters/baseline.converter.test.ts.md) and before [test.build/core/converters/build.converter.test.ts](https://banes-lab.com/source/testing/test.build/core/converters/build.converter.test.ts.md).

## Contained in

- [test.build/core/converters](https://banes-lab.com/anatomy/testing/folder-testing-test-build-core-converters.md)

## Source

```typescript
import {
    consoleRecord,
    eventRecord,
    exceptionRecord,
} from "@banes-lab/build-scripts/core/converters/browser.converter.ts";
import { describe, expect, it } from "vitest";
import type { ConsoleRecord } from "@banes-lab/build-scripts/types/browser.types.ts";

describe("consoleRecord", () => {
    it("joins the arguments and locates the first call frame", () => {
        const record: ConsoleRecord = consoleRecord({
            args: [{ value: "hello" }, { value: 2 }],
            stackTrace: { callFrames: [{ lineNumber: 4, url: "https://site.test/app.js" }] },
            type: "warning",
        });
        expect(record).toStrictEqual({ level: "warning", source: "https://site.test/app.js:5", text: "hello 2" });
    });

    it("defaults to the log level with no source when nothing is known", () => {
        expect(consoleRecord(null)).toStrictEqual({ level: "log", source: "", text: "" });
    });
});

describe("eventRecord", () => {
    it("records a console call and a thrown exception and ignores any other event", () => {
        const logged = eventRecord({
            method: "Runtime.consoleAPICalled",
            params: { args: [{ value: "hi" }], type: "log" },
        });
        expect(logged?.text).toBe("hi");
        const thrown = eventRecord({
            method: "Runtime.exceptionThrown",
            params: { exceptionDetails: { exception: { description: "Boom" }, lineNumber: 0, url: "a.js" } },
        });
        expect(thrown).toStrictEqual({ level: "exception", source: "a.js:1", text: "Boom" });
        expect(eventRecord({ method: "Page.loadEventFired", params: {} })).toBeNull();
    });
});

describe("exceptionRecord", () => {
    it("takes the first line of the thrown description", () => {
        const record = exceptionRecord({ exception: { description: "Boom\n  at x" }, lineNumber: 1, url: "a.js" });
        expect(record).toStrictEqual({ level: "exception", source: "a.js:2", text: "Boom" });
    });
});
```
