vitest-sentry-reporter 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 C-A de Salaberry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,143 @@
1
+ # vitest-sentry-reporter
2
+
3
+ [![codecov](https://codecov.io/gh/cadesalaberry/vitest-sentry-reporter/graph/badge.svg)](https://codecov.io/gh/cadesalaberry/vitest-sentry-reporter)
4
+
5
+ Uses Sentry to collect software defects and orchestrate its correction.
6
+
7
+ ## Why report failing Vitest tests to Sentry
8
+
9
+ - **Faster feedback**: Centralizes failures from CI and local runs for immediate visibility.
10
+ - **Actionable context**: Captures stack traces, release, commit SHA, env, and custom tags.
11
+ - **Ownership & triage**: Deduplicates, routes to the right team, and suppresses known flakes.
12
+ - **Trend & flake insights**: Surfaces regressions and flaky patterns to improve reliability.
13
+ - **Shift-left quality**: Treats test failures as first-class defects, not console noise.
14
+ - **Production parity**: Mirrors proven prod observability practices in pre-merge pipelines.
15
+ - **Continuous improvement**: Dashboards and alerts drive SLIs/SLOs for test health.
16
+
17
+ Good teams observe production. Great teams also observe their tests.
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ bun add -D vitest-sentry-reporter @sentry/node
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ Add the reporter to your `vitest.config.ts`.
28
+
29
+ ```ts
30
+ // vitest.config.ts
31
+ import { defineConfig } from 'vitest/config';
32
+ import VitestSentryReporter from 'vitest-sentry-reporter';
33
+
34
+ export default defineConfig({
35
+ test: {
36
+ reporters: [
37
+ new VitestSentryReporter({
38
+ // If omitted, uses process.env.SENTRY_DSN
39
+ // dsn: process.env.SENTRY_DSN,
40
+
41
+ // Enable/disable explicitly. Defaults to enabled if DSN exists.
42
+ // enabled: true,
43
+
44
+ // Optional metadata; will fall back to env and CI info if omitted
45
+ environment: process.env.SENTRY_ENVIRONMENT || 'ci',
46
+ release: process.env.SENTRY_RELEASE, // defaults to commit SHA on popular CIs
47
+ serverName: 'local-dev',
48
+ tags: {
49
+ project: 'my-repo', // useful when used across multiple repos
50
+ team: 'qa',
51
+ },
52
+
53
+ // Sentry SDK options
54
+ sentryOptions: {
55
+ // debug: true,
56
+ },
57
+
58
+ // Filter which failures are reported
59
+ shouldReport: (ctx) => !ctx.flaky,
60
+
61
+ // Add or override tags dynamically per failure
62
+ getTags: (ctx) => ({
63
+ spec: ctx.filePath,
64
+ retry: String(ctx.retry ?? 0),
65
+ }),
66
+
67
+ // Stable grouping across repos
68
+ getFingerprint: (ctx) => [
69
+ 'vitest-failure',
70
+ ctx.filePath ?? 'unknown-file',
71
+ ctx.testName,
72
+ ],
73
+
74
+ // Associate a user to help spot who hit the failure locally
75
+ getUser: () => ({ username: process.env.USER }),
76
+
77
+ // Mutate the final Sentry event before it is sent
78
+ beforeSend: (event, _hint, ctx) => {
79
+ event.level = 'error';
80
+ event.tags = { ...(event.tags || {}), quicklook: 'true' };
81
+ event.extra = { ...(event.extra || {}),
82
+ suite_path: ctx.suitePath,
83
+ duration_ms: ctx.durationMs,
84
+ };
85
+ return event;
86
+ },
87
+
88
+ // Safety valve in large suites
89
+ maxEventsPerRun: 200,
90
+
91
+ // If true, logs what would be sent without sending to Sentry
92
+ // dryRun: true,
93
+ })
94
+ ],
95
+ },
96
+ });
97
+ ```
98
+
99
+ Compatible with Vitest 3 and 4.
100
+
101
+ ### What gets reported
102
+
103
+ - **Error**: The thrown error from the failed test (or synthesized from message).
104
+ - **Tags**: `test_file`, `test_name`, `test_full_title`, `flaky`, `retry`, `node_version`, `os_platform`, `os_release`, `ci`, `repository`, `branch`, `commit_sha`, plus any custom tags.
105
+ - **Extras**: `duration_ms`, `logs`, `suite_path`, `vitest_version`, minimal CI env snapshot.
106
+ - **Contexts**: `test` context with file/name/fullTitle/duration/retry/flaky.
107
+ - **Fingerprint**: Defaults to `['vitest-failure', file, testName]`; override with `getFingerprint`.
108
+
109
+ ### Environment variables and CI auto-detection
110
+
111
+ - `SENTRY_DSN` (required unless `dsn` is provided)
112
+ - `SENTRY_ENVIRONMENT`, `SENTRY_RELEASE` are respected when not explicitly set.
113
+ - CI metadata auto-detected for GitHub Actions, CircleCI, Buildkite, GitLab, Jenkins.
114
+
115
+ ### Multi-repo usage
116
+
117
+ Use the `tags.project` field and/or `getTags` to inject a stable project identifier. You can also add a `repository` tag if you aggregate across multiple repos.
118
+
119
+ ### License
120
+
121
+ MIT
122
+
123
+ ## Architectural Decision Records (ADR)
124
+
125
+ We record architectural decisions using MADR (Markdown Architectural Decision Records).
126
+
127
+ - **Directory**: `docs/decisions`
128
+ - **Template**: `docs/decisions/adr-template.md`
129
+ - **Format**: MADR. See the docs at [adr.github.io/madr](https://adr.github.io/madr/) and the repository at [github.com/adr/madr](https://github.com/adr/madr).
130
+
131
+ ### Create a new ADR
132
+
133
+ 1. Pick the next number (zero-padded), e.g., `0001`.
134
+ 2. Copy the template and edit:
135
+
136
+ ```
137
+ cp docs/decisions/adr-template.md docs/decisions/0001-short-title.md
138
+ ```
139
+
140
+ 3. Fill in the sections and set an appropriate status (`proposed`, `accepted`, `rejected`, `superseded`).
141
+
142
+ The initial ADR adopting MADR lives at `docs/decisions/0000-use-markdown-architectural-decision-records.md`.
143
+
@@ -0,0 +1,2 @@
1
+ import type { CIProvider } from './types.js';
2
+ export declare const BuildkiteProvider: CIProvider;
@@ -0,0 +1,2 @@
1
+ import type { CIProvider } from './types.js';
2
+ export declare const CircleCIProvider: CIProvider;
@@ -0,0 +1,2 @@
1
+ import type { CIProvider } from './types.js';
2
+ export declare const GenericCIProvider: CIProvider;
@@ -0,0 +1,2 @@
1
+ import type { CIProvider } from './types.js';
2
+ export declare const GitHubActionsProvider: CIProvider;
@@ -0,0 +1,2 @@
1
+ import type { CIProvider } from './types.js';
2
+ export declare const GitLabCIProvider: CIProvider;
@@ -0,0 +1,10 @@
1
+ import type { CIProvider } from './types.js';
2
+ import { GitHubActionsProvider } from './github.js';
3
+ import { CircleCIProvider } from './circleci.js';
4
+ import { BuildkiteProvider } from './buildkite.js';
5
+ import { GitLabCIProvider } from './gitlab.js';
6
+ import { JenkinsProvider } from './jenkins.js';
7
+ import { GenericCIProvider } from './generic.js';
8
+ export declare function detectProvider(env: NodeJS.ProcessEnv): CIProvider | undefined;
9
+ export { type CIProvider } from './types.js';
10
+ export { GitHubActionsProvider, CircleCIProvider, BuildkiteProvider, GitLabCIProvider, JenkinsProvider, GenericCIProvider, };
@@ -0,0 +1,2 @@
1
+ import type { CIProvider } from './types.js';
2
+ export declare const JenkinsProvider: CIProvider;
@@ -0,0 +1,13 @@
1
+ export interface CIProvider {
2
+ readonly name: string;
3
+ isActive(env: NodeJS.ProcessEnv): boolean;
4
+ repository(env: NodeJS.ProcessEnv): string | undefined;
5
+ branch(env: NodeJS.ProcessEnv): string | undefined;
6
+ commitSha(env: NodeJS.ProcessEnv): string | undefined;
7
+ runUrl(env: NodeJS.ProcessEnv): string | undefined;
8
+ workflowId(env: NodeJS.ProcessEnv): string | undefined;
9
+ /**
10
+ * Minimal, provider-specific environment snapshot useful for debugging links and context.
11
+ */
12
+ envSnapshot(env: NodeJS.ProcessEnv): Record<string, string | undefined>;
13
+ }
@@ -0,0 +1,5 @@
1
+ import type { Envelope } from '@sentry/core';
2
+ export declare function makeDryRunTransport(): {
3
+ send(envelope: Envelope): Promise<{}>;
4
+ flush(_timeout?: number): Promise<boolean>;
5
+ };
@@ -0,0 +1 @@
1
+ export { default } from './reporter.js';