Test your logs
Call logger.info(‘probe’), await capture.settled(), and assert that the entry has screen=SettingsTeam.
The /testing entry point holds two helpers for your own tests. Only test files import it, so your app ships none of it, and neither helper needs a DOM.
A test that reads what ships
Section titled “A test that reads what ships”import { createMemoryRouter } from 'react-router'import { initLogger } from '@dasasian/firebase-structured-logger/client'import { enableReactRouterNavigation } from '@dasasian/firebase-structured-logger/client/navigation/react-router'import { captureEntries, resetSession } from '@dasasian/firebase-structured-logger/testing'import { routes } from './routes'
const capture = captureEntries()const logger = initLogger({ appId: 'test', releaseId: 'test', logFunction: capture.logFunction })
beforeEach(() => { resetSession() capture.clear()})
test('team settings is its own screen', async () => { const router = createMemoryRouter(routes, { initialEntries: ['/settings/team'] }) enableReactRouterNavigation(router) logger.info('probe') await capture.settled()
const entry = capture.entries.findLast((e) => e.message === 'probe') expect(entry?.labels.screen).toBe('SettingsTeam') expect(entry?.jsonPayload?.breadcrumbs?.filter((b) => b.type === 'nav')).toHaveLength(1)})Entries are only sent at WARNING and above in production. Tests run with the dev default, DEBUG, so info passes the floor. If your test environment sets NODE_ENV=production, pass minSeverity to initLogger.
captureEntries
Section titled “captureEntries”captureEntries() returns { logFunction, entries, clear(), settled() }. Pass logFunction to initLogger. Each entry in entries is exactly what your log function would receive, after label cleaning, size limits and the rate limiter, so the test checks what ships.
Each call gets its own entries. settled() is not per capture: the logger has one watcher, so every capture’s settled() waits for every send started since the first captureEntries() call.
Wait for settled
Section titled “Wait for settled”A log call returns nothing, and an entry with attachments reaches logFunction only after its files are read. await capture.settled() before you read entries. It waits for every send already started, repeat summaries and trace warnings included, and resolves when each has reached logFunction or failed.
Find your entry by message
Section titled “Find your entry by message”Do not read by position. The logger sends entries of its own, such as repeat summaries and trace warnings. An entry the rate limiter dropped is missing, so findLast returns undefined and the test fails. It does not read the previous entry by mistake.
resetSession
Section titled “resetSession”resetSession() empties the breadcrumb trail, clears the current page, restores a full rate-limit budget, and empties both the duplicate counts and the pending repeat-summary queue. Call it before each test. The trail holds 50 crumbs and the budget 50 entries, and both carry over between tests otherwise.
It leaves configuration alone. enableNavigation() or a router adapter stays wired, and the reader that enableViews() registered stays registered, as a real new tab would keep them.
A test of views (data-fsl-view) needs a DOM environment such as jsdom. See Tabs and dialogs and Breadcrumbs for what the entries should contain.
Made by Dasasian