Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.2 KB
Raw Blame
import { type SeriesLabel, distinctSeriesLabels } from './metricsSeries'

describe('distinctSeriesLabels', () => {
    it.each<{ name: string; labels: Record<string, string>[]; distinct: SeriesLabel[][] }>([
        {
            name: 'drops labels with the same value on every series',
            labels: [
                { app: 'checkout', route: '/cart' },
                { app: 'checkout', route: '/pay' },
            ],
            distinct: [[['route', '/cart']], [['route', '/pay']]],
        },
        {
            name: 'keeps a label that one series does not have',
            labels: [{ app: 'checkout', route: '/cart' }, { route: '/pay' }],
            distinct: [
                [
                    ['app', 'checkout'],
                    ['route', '/cart'],
                ],
                [['route', '/pay']],
            ],
        },
        {
            name: 'keeps every label of a single series',
            labels: [{ app: 'checkout' }],
            distinct: [[['app', 'checkout']]],
        },
    ])('$name', ({ labels, distinct }) => {
        expect(distinctSeriesLabels(labels.map((seriesLabels) => ({ labels: seriesLabels })))).toEqual(distinct)
    })
})