: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(replay): revive the replay-shared jest suite and run it in CI (#68650)
Robbie0ff1394de6dd
diff --git a/.github/workflows/ci-frontend.yml b/.github/workflows/ci-frontend.ymlindex cb20b126da86..c9446b8aa8e2 100644--- a/.github/workflows/ci-frontend.yml+++ b/.github/workflows/ci-frontend.yml@@ -48,6 +48,9 @@ jobs:${{ (steps.filter.outputs.frontend_code || 'true') == 'true'&& (steps.exclude.outputs.outside_node_product_workspaces || 'true') == 'true'&& steps.baseline_push.outputs.result != 'true' }}+ replay_shared: >-+ ${{ (steps.filter.outputs.replay_shared || 'true') == 'true'+ && steps.baseline_push.outputs.result != 'true' }}steps:# For pull requests it's not necessary to check out the code, but we# also want this to run on master, so we need to check out@@ -122,6 +125,16 @@ jobs:- tsconfig.*.json- webpack.config.js- stylelint*+ # The @posthog/replay-shared package's own jest suite (the+ # jest-replay-shared job). posthog-js bumps land via the catalog ++ # lockfile and have broken it before (rrweb subpath entries switching+ # to ESM); its zstd tests need the node:zlib support pinned by .nvmrc.+ replay_shared:+ - 'common/replay-shared/**'+ - pnpm-workspace.yaml+ - pnpm-lock.yaml+ - .nvmrc+ - .github/workflows/ci-frontend.yml- name: Detect Visual Review baseline-only pushid: baseline_push@@ -692,9 +705,36 @@ jobs:if-no-files-found: ignoreretention-days: 1+ jest-replay-shared:+ runs-on: ubuntu-latest+ timeout-minutes: 10+ needs: changes+ if: needs.changes.outputs.replay_shared == 'true'+ name: Jest test (replay-shared)+ steps:+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2++ # Full workspace install: the suite's jsdom test environment resolves+ # through the workspace root, not the package's own dependencies, so a+ # filtered install can't run it.+ - name: Install pnpm dependencies+ uses: ./.github/actions/pnpm-install++ - name: Test with Jest+ run: pnpm --filter=@posthog/replay-shared test+calculate-running-time:name: Calculate running time- needs: [jest, frontend-typescript-checks, frontend-format, frontend-bundle-size, frontend_tests, changes]+ needs:+ [+ jest,+ jest-replay-shared,+ frontend-typescript-checks,+ frontend-format,+ frontend-bundle-size,+ frontend_tests,+ changes,+ ]runs-on: ubuntu-latesttimeout-minutes: 5if: # Run on pull requests to PostHog/posthog + on PostHog/posthog outside of PRs - but never on forks or Dependabot (no secrets access)@@ -736,7 +776,7 @@ jobs:runner: 'github'frontend_tests:- needs: [jest, frontend-format, frontend-bundle-size, frontend-typescript-checks]+ needs: [jest, jest-replay-shared, frontend-format, frontend-bundle-size, frontend-typescript-checks]name: Frontend Tests Passruns-on: ubuntu-latesttimeout-minutes: 5@@ -750,6 +790,11 @@ jobs:exit 1fiecho "Frontend jest tests passed."+ if [[ "${{ needs.jest-replay-shared.result }}" != "success" && "${{ needs.jest-replay-shared.result }}" != "skipped" ]]; then+ echo "Replay shared jest tests failed."+ exit 1+ fi+ echo "Replay shared jest tests passed."if [[ "${{ needs.frontend-format.result }}" != "success" && "${{ needs.frontend-format.result }}" != "skipped" ]]; thenecho "Frontend linting failed."exit 1diff --git a/common/replay-shared/jest.config.js b/common/replay-shared/jest.config.jsindex fe978f9b58cb..4f747e8d8f3e 100644--- a/common/replay-shared/jest.config.js+++ b/common/replay-shared/jest.config.js@@ -1,7 +1,9 @@module.exports = {transform: {- '^.+\\.ts$': ['@swc/jest'],+ '^.+\\.[cm]?[jt]s$': ['@swc/jest'],},+ // posthog-js's rrweb subpath entries are shipped as ESM; let them through to the transform.+ transformIgnorePatterns: ['node_modules/(?!.*posthog-js/dist/rrweb)'],testEnvironment: 'node',clearMocks: true,testMatch: ['<rootDir>/src/**/*.test.ts'],diff --git a/common/replay-shared/src/rrweb-plugins/rrweb-plugins.test.ts b/common/replay-shared/src/rrweb-plugins/rrweb-plugins.test.tsindex a525391ceb29..4b35df68a492 100644--- a/common/replay-shared/src/rrweb-plugins/rrweb-plugins.test.ts+++ b/common/replay-shared/src/rrweb-plugins/rrweb-plugins.test.ts@@ -60,6 +60,10 @@ jest.mock('hls.js', () => ({ __esModule: true, default: mockHlsClass }))describe('HLSPlayerPlugin', () => {let plugin: ReturnType<typeof createHLSPlayerPlugin>+ // `onBuild` fires `import('hls.js').then(...)` without awaiting it; drain the microtask+ // queue so the handler has run before asserting.+ const delay = (ms = 0): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms))+beforeEach(() => {jest.clearAllMocks()mockHlsClass.isSupported.mockReturnValue(true)@@ -83,6 +87,7 @@ describe('HLSPlayerPlugin', () => {video.setAttribute('hls-src', 'https://example.com/stream.m3u8')await plugin.onBuild?.(video, { id: 1, replayer: null as any })+ await delay()expect(mockHlsClass).toHaveBeenCalled()expect(mockHlsInstance.loadSource).toHaveBeenCalledWith('https://example.com/stream.m3u8')@@ -97,6 +102,7 @@ describe('HLSPlayerPlugin', () => {video.canPlayType = jest.fn(() => 'maybe') as anyawait plugin.onBuild?.(video, { id: 1, replayer: null as any })+ await delay()expect(mockHlsInstance.loadSource).not.toHaveBeenCalled()expect(video.src).toContain('https://example.com/stream.m3u8')