Loading...
Loading...
Perses plugin testing: CUE schema unit tests with percli plugin test-schemas, React component tests, integration testing with local Perses server, and Grafana migration compatibility testing. Use for "test perses plugin", "perses plugin test", "perses schema test". Do NOT use for dashboard validation (use perses-lint).
npx skill4agent add notque/claude-code-toolkit perses-plugin-testpercli plugin test-schemasschemas/<type>/<name>/<name>.jsonpackage modelpackage modelpercli plugin test-schemaslocalhostclose({...})close()percli plugin test-schemas@perses-dev/plugin-systempercli plugin startpackage modelclose({...})schemas/<type>/<name>/<name>.jsonpercli plugin test-schemas@perses-dev/plugin-systemuseDataQueriesuseTimeRangenpm test -- --watchAll=falsedocker run --name perses-test -d -p 127.0.0.1:8080:8080 persesdev/persespercli plugin startmigrate/migrate.cuepercli migrate --input grafana-dashboard.json --output perses-dashboard.json| Error | Cause | Solution |
|---|---|---|
| CUE file missing | Add |
| Unclosed | Count opening/closing braces; ensure every |
| Wrong CUE import path (e.g., using Go-style paths instead of CUE module paths) | Check |
| JSON example contains fields not defined in the CUE schema | Either add the field to the CUE schema or remove it from the JSON example; |
| React test: "Cannot find module '@perses-dev/plugin-system'" | Missing mock setup for the plugin system dependency | Add |
| React test: "Invalid hook call" | Using wrong test renderer or missing React context providers | Wrap component in |
| Integration test: connection refused on port 8080 | Local Perses server not running or bound to a different port | Start server with |
| Integration test: 401 Unauthorized | Perses server has auth enabled but test is not authenticating | Run |
| Migration test: unexpected panel type | Grafana dashboard JSON contains panel types not handled by | Add a migration case for the new panel type in |
| Migration test: schema version mismatch | Grafana JSON structure changed between versions (e.g., v8 vs v10 panel format) | Check the Grafana version in the test fixture and ensure |
| Anti-Pattern | Why It Fails | Do Instead |
|---|---|---|
| Running component tests before schema tests pass | Components depend on valid schemas; testing components against broken schemas produces misleading failures | Always run |
| Testing against a shared or production Perses server | Tests may corrupt real data, hit rate limits, or fail due to network latency; results are non-reproducible | Always use a local Perses instance via Docker or binary — disposable and isolated |
| JSON examples that only test the happy path | Schemas with optional fields, unions, or conditional logic have branches that never get exercised | Create multiple JSON examples per schema: minimal (required fields only), full (all fields), and edge cases (empty arrays, null values) |
| Skipping migration tests because "the schema didn't change" | Upstream Grafana panel JSON evolves independently; a working migration can break without any local changes | Run migration tests against current Grafana sample fixtures on every test cycle |
| Mocking the entire plugin-system module with empty stubs | Tests pass but don't verify that hooks are called correctly or return expected shapes | Mock individual hooks with realistic return values (e.g., |
| Rationalization | Reality | Required Action |
|---|---|---|
| "Schema tests pass so the plugin works" | Schema tests only validate CUE syntax and JSON conformance — they say nothing about whether the React component renders | Run all four phases |
| "I tested with one JSON example and it passed" | One example may only exercise the default branch of a union type; other branches remain untested | Create JSON examples for every schema variant |
| "Integration tests are slow, I'll skip them this time" | Integration tests catch issues that unit tests cannot: plugin registration, data binding, render lifecycle | Always run integration tests against local Perses |
| "The migration worked for my Grafana dashboard" | Your dashboard may only use a subset of panel types; other users' dashboards will have panels you didn't test | Test migration with diverse Grafana fixtures covering all supported panel types |
package modelperclipercli plugin test-schemasperclitest-schemasmigrate/migrate.cue