Skip to content

ci(tests): upload Vitest and Playwright JUnit reports to Trunk Flaky Tests#2941

Open
gantoine wants to merge 5 commits into
mainfrom
trunk-flaky-tests-setup
Open

ci(tests): upload Vitest and Playwright JUnit reports to Trunk Flaky Tests#2941
gantoine wants to merge 5 commits into
mainfrom
trunk-flaky-tests-setup

Conversation

@gantoine

@gantoine gantoine commented Jun 25, 2026

Copy link
Copy Markdown
Member

What

Sets up Trunk Flaky Tests test uploads for the posthog-inc org. CI provider is GitHub Actions; covers both test frameworks in the repo — Vitest (unit/integration) and Playwright (E2E).

Vitest

Config (all 8 configs)

apps/code, apps/mobile, packages/{ui,agent,git,shared,workspace-server,electron-trpc}:

  • Add the junit reporter (outputFile: ./junit.xml, addFileAttribute: true — Trunk needs the file attribute to map results to source) alongside the existing default reporter, so console output is preserved.
  • Add explicit retry: 0 so flaky detection sees raw pass/fail results. (0 is already Vitest's default; this makes it explicit.)

CI (unit-test job in .github/workflows/test.yml)

New Upload test results to Trunk step after pnpm test:

  • junit-paths: "apps/*/junit.xml,packages/*/junit.xml" — scoped to package roots. A bare **/junit.xml glob descends into node_modules (pnpm symlinks workspace packages) and uploads each report dozens of times; the scoped glob matches exactly the 8 reports.

Playwright

Config (apps/code/tests/e2e/playwright.config.ts)

  • Add the junit reporter (outputFile: junit.xml, resolved next to the config → apps/code/tests/e2e/junit.xml) to both the CI and local reporter sets.
  • retries: 0 (was isCI ? 2 : 0) so flaky detection sees raw pass/fail results.

CI (integration-test job)

New Upload test results to Trunk step after the E2E run:

  • junit-paths: "apps/code/tests/e2e/junit.xml".

Shared CI details

Both upload steps:

  • Use trunk-io/analytics-uploader pinned to v2.1.2 (SHA), per the repo's action-pinning convention.
  • if: ${{ !cancelled() }} so failed/flaky results are still reported; continue-on-error: true so an upload hiccup can't fail the job.
  • org-slug: posthog-inc; TRUNK_API_TOKEN wired as both the token input and a step env var.

.gitignore ignores the generated junit.xml reports.

Local validation (trunk-analytics-cli validate)

  • Vitest: 8 valid files, 0 warnings, 0 errors (validated against the scoped globs the CI step uses).
  • Playwright: 0 errors, 1 non-blocking warning — "report has test cases with missing file or filepath". This is inherent to Playwright's built-in JUnit reporter (no option to emit a per-testcase file attribute, confirmed in playwright@1.58.1 source) and matches Trunk's documented Playwright config. Clearing it would require a custom reporter; happy to add one if we want absolute 0 warnings (low value today — there's no CODEOWNERS file for Trunk to map against).

Follow-ups (not in this PR)

  • Add the TRUNK_API_TOKEN secret to the repo's GitHub Actions secrets (from Trunk org settings). Confirm posthog-inc is the exact Trunk org URL slug. ✅

🤖 Generated with Claude Code

Configure Trunk Flaky Tests test uploads for the posthog-inc org.

- Add the junit reporter (outputFile ./junit.xml, addFileAttribute: true)
  alongside the default reporter in all 8 Vitest configs, and set an
  explicit retry: 0 so flaky detection sees raw pass/fail results.
- Add an "Upload test results to Trunk" step to the unit-test job in
  test.yml using trunk-io/analytics-uploader (pinned), scoped to
  apps/*/junit.xml,packages/*/junit.xml to avoid node_modules dupes.
- Gitignore the generated junit.xml reports.

Validated locally with trunk-analytics-cli validate: 8 valid files,
0 warnings, 0 errors.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit d88bfb6.

@greptile-apps

greptile-apps Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "ci(tests): upload JUnit reports to Trunk..." | Re-trigger Greptile

Comment thread apps/code/vitest.config.ts Outdated
Comment thread .github/workflows/test.yml Outdated
Extend the Trunk Flaky Tests setup to the Playwright E2E suite.

- Add the junit reporter (outputFile junit.xml, resolved next to the
  config => apps/code/tests/e2e/junit.xml) to playwright.config.ts, in
  both the CI and local reporter sets, and set retries: 0 (was
  isCI ? 2 : 0) so flaky detection sees raw pass/fail results.
- Add an "Upload test results to Trunk" step to the integration-test
  job in test.yml, after the E2E run, using the pinned
  trunk-io/analytics-uploader with junit-paths apps/code/tests/e2e/junit.xml.

Validated locally with trunk-analytics-cli validate: 0 errors. (One
non-blocking warning remains -- "missing file or filepath" -- which is
inherent to Playwright's built-in JUnit reporter, which has no option to
emit a per-testcase file attribute; it matches Trunk's documented
Playwright config.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gantoine gantoine changed the title ci(tests): upload JUnit reports to Trunk Flaky Tests ci(tests): upload Vitest and Playwright JUnit reports to Trunk Flaky Tests Jun 25, 2026
gantoine and others added 3 commits June 25, 2026 14:40
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The retry: 0 setting and junit reporter array were pasted verbatim into
all 8 vitest.config.ts files, so any change (outputFile path, a new Trunk
reporter option) had to be made in lockstep across every file.

Extract them to a root-level vitest.config.base.ts as `trunkTestOptions`
and spread it into each config's `test` block. The constant is explicitly
typed so the reporter tuple stays assignable across the Vitest 2.x and
4.x versions used in the workspace.

Verified at runtime in a v4 package (shared), a v2 package (git), and the
vite-augmented config (electron-trpc): junit.xml is still emitted and
trunk-analytics-cli validate reports 0 warnings, 0 errors for all three.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The trunk-io/analytics-uploader action maps the token: input to the CLI
--token flag, so the separately-set env var was redundant and exposed the
secret in the step environment unnecessarily. Keep only the token: input.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gantoine gantoine requested review from a team and joshsny and removed request for joshsny June 26, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant