grafana/grafana
Testing
Grafana has three independent test suites: backend Go tests, frontend Jest tests, and Playwright end-to-end tests. CI runs all three.
Backend tests (Go)
| Command | What it runs |
|---|---|
go test ./pkg/services/myservice/ |
Single package |
go test -run TestName ./pkg/... |
Single test by name |
make test-go-unit |
All Go unit tests |
make test-go-integration |
Integration tests (some need a database) |
make test-go-integration-postgres |
Integration tests using Postgres (start with make devenv sources=postgres_tests) |
make test-go-integration-mysql |
Same for MySQL |
CI shards the backend test run with SHARD/SHARDS environment variables; locally you don't need them.
Patterns
- Unit tests live next to source files:
foo.go↔foo_test.go. - Mocks are usually generated under
mocks/subdirectories or hand-written*_fake.gofiles. The repo uses bothmockeryandwire-style fakes — match what neighbors do. - Test helpers for HTTP / web tests live in
pkg/api/common_test.go— thesetupHTTPServerhelpers are the most common starting point for a new API test. - Database tests use
pkg/services/sqlstore/sqlstore_test.gohelpers and the testing matrix frompkg/tests/for end-to-end DB cases. - Slow compile:
pkg/api/has a heavy import graph; first compile of its tests takes ~2 min. Use-run TestNameaggressively.
Build tags
Many tests gate on // +build integration or oss/enterprise build tags. The integration-test Make targets pass the right tags; running raw go test ./... will skip them.
Frontend tests (Jest)
| Command | What it runs |
|---|---|
yarn test path/to/file |
Watch mode (default!) |
yarn jest --no-watch path/to/file |
One-shot |
yarn test -t "pattern" |
Filter by test name regex |
yarn test -u |
Update snapshots |
yarn test:ci |
Full CI run (sharded) |
yarn test:coverage |
Coverage report |
⚠️ Plain
yarn testdefaults to--watch. In CI/AI/automation contexts always useyarn jest --no-watchoryarn test --watchAll=false.
Patterns
- Co-located tests:
Component.tsx↔Component.test.tsx. - React Testing Library is the default — render with
render(...), query withscreen.getByRole, prefer accessible queries over test ids. - MSW is used for HTTP mocking. Per-test setup typically wires up
server.use(...)handlers. - Storybook has its own test setup under
packages/grafana-ui/. Runyarn storybookfor the design-system playground.
End-to-end tests (Playwright)
| Command | What it runs |
|---|---|
yarn e2e:playwright |
The default e2e suite (excludes cloud-plugin tests) |
yarn e2e:pw path/to/test.spec.ts |
One file |
yarn e2e:playwright:debug |
With Playwright UI / inspector |
yarn e2e:playwright:storybook |
Storybook visual tests |
yarn e2e:plugin:build && yarn e2e:plugin:build:dev |
Build the bundled test plugins |
E2E specs live in e2e-playwright/. Earlier Cypress specs have been migrated; a few may still exist but Playwright is the supported framework.
Test plugins
e2e-playwright/test-plugins/ contains Yarn workspace plugins that act as fixtures (e.g. a fake datasource, a fake panel). They are built before e2e runs:
yarn e2e:plugin:build:devLinters and type checks (also run in CI)
make lint-go # golangci-lint
yarn lint # ESLint + stylelint
yarn lint:fix # ESLint auto-fix
yarn prettier:write # Prettier auto-format
yarn typecheck # tsc --noEmitCustom analysis
- Custom ESLint rules live in
packages/grafana-eslint-rules/(workspace@grafana/eslint-plugin). Examples:theme-token-usage,no-untranslated-strings. - Go has a
ruleguard.rules.gofile atpkg/ruleguard.rules.goused bygolangci-lint's ruleguard linter. madgerunsyarn lint:circularto detect circular TS imports.
Local QA screenshots
These screenshots came from local QA runs and are kept here as supporting test evidence rather than overview material.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.