@ctrl/sentry-tests 0.0.0-stage → 0.1.1

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) 2026 Scott Cooper
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/NOTICE ADDED
@@ -0,0 +1,338 @@
1
+ @ctrl/dom
2
+ Copyright (c) 2026 Scott Cooper
3
+ Licensed under the MIT License (see LICENSE).
4
+
5
+ @ctrl/dom includes code ported from the third-party projects listed below. Every source file
6
+ with ported code names the upstream file it came from in a comment ("Port of ...", "Ported
7
+ from ..."), and those files have been modified from the originals. Each project's copyright
8
+ notice is listed with its entry; the license texts are at the end of this file.
9
+
10
+ ==================================================================================================
11
+ Included in the published packages
12
+ ==================================================================================================
13
+
14
+ @testing-library/dom 10.4.2 (MIT)
15
+ Copyright (c) 2017 Kent C. Dodds
16
+ https://github.com/testing-library/dom-testing-library
17
+ In @ctrl/dom/testing-library (source and public types) and parts of @ctrl/dom/aria
18
+
19
+ @testing-library/react 16.3.3 (MIT)
20
+ Copyright (c) 2017-Present Kent C. Dodds
21
+ https://github.com/testing-library/react-testing-library
22
+ In @ctrl/dom/react (source and public types)
23
+
24
+ @testing-library/user-event 14.6.8 (MIT)
25
+ Copyright (c) 2020 Giorgio Polvara
26
+ https://github.com/testing-library/user-event
27
+ In @ctrl/dom/user-event
28
+
29
+ @testing-library/jest-dom 7.0.1 (MIT)
30
+ Copyright (c) 2017 Kent C. Dodds
31
+ https://github.com/testing-library/jest-dom
32
+ In @ctrl/dom/jest-dom (source and public types)
33
+
34
+ dom-accessibility-api 0.5.16 / 0.6.3 (MIT)
35
+ Copyright (c) 2020 Sebastian Silbermann
36
+ https://github.com/eps1lon/dom-accessibility-api
37
+ In @ctrl/dom/aria (accessible name and description computation)
38
+
39
+ aria-query 5.3.0 / 5.3.2 (Apache-2.0)
40
+ Copyright 2020 A11yance
41
+ https://github.com/A11yance/aria-query
42
+ In @ctrl/dom/aria (role data) and @ctrl/dom/jest-dom (element roles)
43
+
44
+ @types/aria-query 5.0.4 (MIT)
45
+ Copyright (c) Microsoft Corporation
46
+ https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/aria-query
47
+ In @ctrl/dom/testing-library's public types (ARIA role names)
48
+
49
+ Playwright 1.56 (Apache-2.0)
50
+ Copyright (c) Microsoft Corporation
51
+ https://github.com/microsoft/playwright
52
+ In @ctrl/dom/testing-library (aria snapshot templates and matching, toMatchAriaSnapshot)
53
+ Playwright's NOTICE file:
54
+
55
+ Playwright
56
+ Copyright (c) Microsoft Corporation
57
+
58
+ This software contains code derived from the Puppeteer project (https://github.com/puppeteer/puppeteer),
59
+ available under the Apache 2.0 license (https://github.com/puppeteer/puppeteer/blob/master/LICENSE).
60
+
61
+ jsdom 30.1.3 (MIT)
62
+ Copyright (c) 2010 Elijah Insua
63
+ https://github.com/jsdom/jsdom
64
+ In @ctrl/dom (date, time and number microsyntaxes, from lib/jsdom/living/helpers/)
65
+
66
+ lz-string 1.5.0 (MIT)
67
+ Copyright (c) 2013 pieroxy
68
+ https://github.com/pieroxy/lz-string
69
+ In @ctrl/dom/testing-library (compressToEncodedURIComponent)
70
+
71
+ picocolors 1.1.1 (ISC)
72
+ Copyright (c) 2021-2024 Oleksii Raspopov, Kostiantyn Denysov, Anton Verinov
73
+ https://github.com/alexeyraspopov/picocolors
74
+ In @ctrl/dom/jest-dom (terminal color detection)
75
+
76
+ HTML Standard (CC BY 4.0, https://creativecommons.org/licenses/by/4.0/)
77
+ © WHATWG (Apple, Google, Mozilla, Microsoft)
78
+ https://html.spec.whatwg.org/
79
+ In @ctrl/dom: the named character references table, converted from
80
+ https://html.spec.whatwg.org/entities.json, and user-agent style sheet rules adapted from
81
+ https://html.spec.whatwg.org/#rendering
82
+
83
+ Source comments throughout quote the specifications they implement (WHATWG, W3C, CSSWG and
84
+ others), with a link to each section. Quoted text is © its authors; WHATWG specifications are
85
+ licensed under CC BY 4.0, W3C specifications under the W3C Software and Document License.
86
+
87
+ ==================================================================================================
88
+ Tests and test data (in the repository only, not in the published packages)
89
+ ==================================================================================================
90
+
91
+ web-platform-tests (BSD-3-Clause)
92
+ Copyright © web-platform-tests contributors
93
+ https://github.com/web-platform-tests/wpt
94
+ Ported dom, html, selectors, css and accname tests (packages/*/test/wpt)
95
+
96
+ html5lib-tests (MIT)
97
+ Copyright (c) 2006-2013 James Graham, Geoffrey Sneddon, and other contributors
98
+ https://github.com/html5lib/html5lib-tests
99
+ Tokenizer and tree construction suites (packages/dom/test/parser/fixtures/html5lib)
100
+
101
+ css-tokenizer-tests 1.4.0 (MIT, as its npm package @rmenke/css-tokenizer-tests declares)
102
+ Copyright (c) Romain Menke
103
+ https://github.com/romainmenke/css-tokenizer-tests
104
+ packages/dom/test/css/fixtures/css-tokenizer-tests.json
105
+
106
+ The test suites of @testing-library/dom, /react, /user-event and /jest-dom, dom-accessibility-api
107
+ and aria-query (copyrights and licenses as above) are ported under packages/*/test/upstream.
108
+
109
+ ==================================================================================================
110
+ License texts
111
+ ==================================================================================================
112
+
113
+ MIT License (the MIT entries above, each under its own copyright notice)
114
+ ------------------------------------------------------------------------
115
+
116
+ Permission is hereby granted, free of charge, to any person obtaining a copy
117
+ of this software and associated documentation files (the "Software"), to deal
118
+ in the Software without restriction, including without limitation the rights
119
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
120
+ copies of the Software, and to permit persons to whom the Software is
121
+ furnished to do so, subject to the following conditions:
122
+
123
+ The above copyright notice and this permission notice shall be included in all
124
+ copies or substantial portions of the Software.
125
+
126
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
127
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
128
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
129
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
130
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
131
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
132
+ SOFTWARE.
133
+
134
+ ISC License (picocolors)
135
+ ------------------------
136
+
137
+ Permission to use, copy, modify, and/or distribute this software for any
138
+ purpose with or without fee is hereby granted, provided that the above
139
+ copyright notice and this permission notice appear in all copies.
140
+
141
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
142
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
143
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
144
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
145
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
146
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
147
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
148
+
149
+ BSD 3-Clause License (web-platform-tests)
150
+ -----------------------------------------
151
+
152
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
153
+
154
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
155
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
156
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
157
+
158
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
159
+
160
+ Apache License 2.0 (aria-query, Playwright)
161
+ -------------------------------------------
162
+
163
+ Apache License
164
+ Version 2.0, January 2004
165
+ http://www.apache.org/licenses/
166
+
167
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
168
+
169
+ 1. Definitions.
170
+
171
+ "License" shall mean the terms and conditions for use, reproduction,
172
+ and distribution as defined by Sections 1 through 9 of this document.
173
+
174
+ "Licensor" shall mean the copyright owner or entity authorized by
175
+ the copyright owner that is granting the License.
176
+
177
+ "Legal Entity" shall mean the union of the acting entity and all
178
+ other entities that control, are controlled by, or are under common
179
+ control with that entity. For the purposes of this definition,
180
+ "control" means (i) the power, direct or indirect, to cause the
181
+ direction or management of such entity, whether by contract or
182
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
183
+ outstanding shares, or (iii) beneficial ownership of such entity.
184
+
185
+ "You" (or "Your") shall mean an individual or Legal Entity
186
+ exercising permissions granted by this License.
187
+
188
+ "Source" form shall mean the preferred form for making modifications,
189
+ including but not limited to software source code, documentation
190
+ source, and configuration files.
191
+
192
+ "Object" form shall mean any form resulting from mechanical
193
+ transformation or translation of a Source form, including but
194
+ not limited to compiled object code, generated documentation,
195
+ and conversions to other media types.
196
+
197
+ "Work" shall mean the work of authorship, whether in Source or
198
+ Object form, made available under the License, as indicated by a
199
+ copyright notice that is included in or attached to the work
200
+ (an example is provided in the Appendix below).
201
+
202
+ "Derivative Works" shall mean any work, whether in Source or Object
203
+ form, that is based on (or derived from) the Work and for which the
204
+ editorial revisions, annotations, elaborations, or other modifications
205
+ represent, as a whole, an original work of authorship. For the purposes
206
+ of this License, Derivative Works shall not include works that remain
207
+ separable from, or merely link (or bind by name) to the interfaces of,
208
+ the Work and Derivative Works thereof.
209
+
210
+ "Contribution" shall mean any work of authorship, including
211
+ the original version of the Work and any modifications or additions
212
+ to that Work or Derivative Works thereof, that is intentionally
213
+ submitted to Licensor for inclusion in the Work by the copyright owner
214
+ or by an individual or Legal Entity authorized to submit on behalf of
215
+ the copyright owner. For the purposes of this definition, "submitted"
216
+ means any form of electronic, verbal, or written communication sent
217
+ to the Licensor or its representatives, including but not limited to
218
+ communication on electronic mailing lists, source code control systems,
219
+ and issue tracking systems that are managed by, or on behalf of, the
220
+ Licensor for the purpose of discussing and improving the Work, but
221
+ excluding communication that is conspicuously marked or otherwise
222
+ designated in writing by the copyright owner as "Not a Contribution."
223
+
224
+ "Contributor" shall mean Licensor and any individual or Legal Entity
225
+ on behalf of whom a Contribution has been received by Licensor and
226
+ subsequently incorporated within the Work.
227
+
228
+ 2. Grant of Copyright License. Subject to the terms and conditions of
229
+ this License, each Contributor hereby grants to You a perpetual,
230
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
231
+ copyright license to reproduce, prepare Derivative Works of,
232
+ publicly display, publicly perform, sublicense, and distribute the
233
+ Work and such Derivative Works in Source or Object form.
234
+
235
+ 3. Grant of Patent License. Subject to the terms and conditions of
236
+ this License, each Contributor hereby grants to You a perpetual,
237
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
238
+ (except as stated in this section) patent license to make, have made,
239
+ use, offer to sell, sell, import, and otherwise transfer the Work,
240
+ where such license applies only to those patent claims licensable
241
+ by such Contributor that are necessarily infringed by their
242
+ Contribution(s) alone or by combination of their Contribution(s)
243
+ with the Work to which such Contribution(s) was submitted. If You
244
+ institute patent litigation against any entity (including a
245
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
246
+ or a Contribution incorporated within the Work constitutes direct
247
+ or contributory patent infringement, then any patent licenses
248
+ granted to You under this License for that Work shall terminate
249
+ as of the date such litigation is filed.
250
+
251
+ 4. Redistribution. You may reproduce and distribute copies of the
252
+ Work or Derivative Works thereof in any medium, with or without
253
+ modifications, and in Source or Object form, provided that You
254
+ meet the following conditions:
255
+
256
+ (a) You must give any other recipients of the Work or
257
+ Derivative Works a copy of this License; and
258
+
259
+ (b) You must cause any modified files to carry prominent notices
260
+ stating that You changed the files; and
261
+
262
+ (c) You must retain, in the Source form of any Derivative Works
263
+ that You distribute, all copyright, patent, trademark, and
264
+ attribution notices from the Source form of the Work,
265
+ excluding those notices that do not pertain to any part of
266
+ the Derivative Works; and
267
+
268
+ (d) If the Work includes a "NOTICE" text file as part of its
269
+ distribution, then any Derivative Works that You distribute must
270
+ include a readable copy of the attribution notices contained
271
+ within such NOTICE file, excluding those notices that do not
272
+ pertain to any part of the Derivative Works, in at least one
273
+ of the following places: within a NOTICE text file distributed
274
+ as part of the Derivative Works; within the Source form or
275
+ documentation, if provided along with the Derivative Works; or,
276
+ within a display generated by the Derivative Works, if and
277
+ wherever such third-party notices normally appear. The contents
278
+ of the NOTICE file are for informational purposes only and
279
+ do not modify the License. You may add Your own attribution
280
+ notices within Derivative Works that You distribute, alongside
281
+ or as an addendum to the NOTICE text from the Work, provided
282
+ that such additional attribution notices cannot be construed
283
+ as modifying the License.
284
+
285
+ You may add Your own copyright statement to Your modifications and
286
+ may provide additional or different license terms and conditions
287
+ for use, reproduction, or distribution of Your modifications, or
288
+ for any such Derivative Works as a whole, provided Your use,
289
+ reproduction, and distribution of the Work otherwise complies with
290
+ the conditions stated in this License.
291
+
292
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
293
+ any Contribution intentionally submitted for inclusion in the Work
294
+ by You to the Licensor shall be under the terms and conditions of
295
+ this License, without any additional terms or conditions.
296
+ Notwithstanding the above, nothing herein shall supersede or modify
297
+ the terms of any separate license agreement you may have executed
298
+ with Licensor regarding such Contributions.
299
+
300
+ 6. Trademarks. This License does not grant permission to use the trade
301
+ names, trademarks, service marks, or product names of the Licensor,
302
+ except as required for reasonable and customary use in describing the
303
+ origin of the Work and reproducing the content of the NOTICE file.
304
+
305
+ 7. Disclaimer of Warranty. Unless required by applicable law or
306
+ agreed to in writing, Licensor provides the Work (and each
307
+ Contributor provides its Contributions) on an "AS IS" BASIS,
308
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
309
+ implied, including, without limitation, any warranties or conditions
310
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
311
+ PARTICULAR PURPOSE. You are solely responsible for determining the
312
+ appropriateness of using or redistributing the Work and assume any
313
+ risks associated with Your exercise of permissions under this License.
314
+
315
+ 8. Limitation of Liability. In no event and under no legal theory,
316
+ whether in tort (including negligence), contract, or otherwise,
317
+ unless required by applicable law (such as deliberate and grossly
318
+ negligent acts) or agreed to in writing, shall any Contributor be
319
+ liable to You for damages, including any direct, indirect, special,
320
+ incidental, or consequential damages of any character arising as a
321
+ result of this License or out of the use or inability to use the
322
+ Work (including but not limited to damages for loss of goodwill,
323
+ work stoppage, computer failure or malfunction, or any and all
324
+ other commercial damages or losses), even if such Contributor
325
+ has been advised of the possibility of such damages.
326
+
327
+ 9. Accepting Warranty or Additional Liability. While redistributing
328
+ the Work or Derivative Works thereof, You may choose to offer,
329
+ and charge a fee for, acceptance of support, warranty, indemnity,
330
+ or other liability obligations and/or rights consistent with this
331
+ License. However, in accepting such obligations, You may act only
332
+ on Your own behalf and on Your sole responsibility, not on behalf
333
+ of any other Contributor, and only if You agree to indemnify,
334
+ defend, and hold each Contributor harmless for any liability
335
+ incurred by, or claims asserted against, such Contributor by reason
336
+ of your accepting any such warranty or additional liability.
337
+
338
+ END OF TERMS AND CONDITIONS
package/README.md CHANGED
@@ -1,3 +1,272 @@
1
- # Temporary Holding Version
1
+ # @ctrl/sentry-tests
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Your test runs in Sentry, for Vitest and Jest:
4
+
5
+ - **Each failing test becomes an issue**, grouped by file and test name, so the same test failing
6
+ again lands in the same issue (and a fixed test that breaks again is a regression). It carries
7
+ the failing line, what the test did as breadcrumbs, and the page as it was when the test failed.
8
+ - **Each flaky test becomes an issue**: a test that failed and then passed on a retry, titled
9
+ `FlakyTest`, with the failed attempt's error.
10
+ - **Each test file becomes a trace**, with a span for every describe block, test, hook and test
11
+ function, so slow setup, slow hooks and slow tests show up where they are.
12
+
13
+ It works with any test environment (jsdom, happy-dom, node). With
14
+ [@ctrl/dom](https://github.com/scttcper/dom), traces also hold every Testing Library query,
15
+ `waitFor`, user-event action and React render, and failures get an accessibility snapshot of the
16
+ page. It sends to a Sentry project or to [Spotlight](https://spotlightjs.com), Sentry's local UI.
17
+ No Sentry SDK and no dependencies: it writes Sentry's envelopes itself and sends them from the
18
+ test runner's main process while the run continues.
19
+
20
+ ## What it sends
21
+
22
+ A test file's trace:
23
+
24
+ ```
25
+ cart.test.tsx test.file 412 ms
26
+ ├─ collect cart.test.tsx test.collect 180 ms
27
+ └─ Cart test.suite 230 ms
28
+ ├─ Cart > adds an item test.case 31 ms
29
+ │ ├─ beforeEach test.hook 2 ms
30
+ │ ├─ adds an item test.fn 27 ms
31
+ │ │ ├─ render(<Cart />) react.render 9 ms ┐
32
+ │ │ ├─ user.click(button "Add") user-event.click 6 ms │ with @ctrl/dom
33
+ │ │ └─ findByText("1 item") testing-library.query 8 ms ┘
34
+ │ └─ afterEach test.hook 1 ms
35
+ └─ Cart > checks out test.case ✗
36
+ ```
37
+
38
+ A failing test's issue is titled by its error, for example
39
+ `TestingLibraryElementError: Unable to find role="option" and name "Option Three"`, with:
40
+
41
+ - **the failing line**: the test's own frame, with its source;
42
+ - **breadcrumbs**, what the test did, in order:
43
+ ```
44
+ beforeEach (2.1 ms)
45
+ render(<CompactSelect />) (20 ms)
46
+ getByRole("button", { name: "Option One" }) (0.8 ms, 1 match)
47
+ user.click(button "Option One") (24 ms)
48
+ findByRole("option", { name: "Option Three" }) (11 ms, 40 checks, 1994 ms skipped)
49
+ ```
50
+ plus, under Vitest, the test's console output;
51
+ - **the page when it failed**, captured before the afterEach hooks (and Testing Library's cleanup)
52
+ emptied it: `page.html` from any DOM, and with @ctrl/dom `accessibility-snapshot.txt`:
53
+ ```
54
+ - button "Option One" [expanded]:
55
+ - listbox "Option One":
56
+ - option "Option One" [active] [selected]
57
+ - option "Option Two"
58
+ ```
59
+ - **tags** to search and alert on: `test.file`, `test.name`, `runner`, `flaky`, `retries` (and
60
+ `test.project` in a multi-project setup);
61
+ - **a link to the test's span** in the file's trace.
62
+
63
+ A file that fails to load (an import or syntax error) is an issue too.
64
+
65
+ ## Setup
66
+
67
+ ### 1. A project for your tests
68
+
69
+ Create a Sentry project for test runs, separate from your app's, so test failures don't mix with
70
+ production issues (the platform doesn't matter; Node.js is closest). Its DSN is under
71
+ Settings → Projects → (the project) → Client Keys (DSN).
72
+
73
+ ### 2. Vitest
74
+
75
+ ```sh
76
+ npm install --save-dev @ctrl/sentry-tests
77
+ ```
78
+
79
+ ```ts
80
+ // vitest.config.ts
81
+ import { defineConfig } from "vitest/config";
82
+ import { sentryTests } from "@ctrl/sentry-tests/vitest";
83
+
84
+ export default defineConfig({
85
+ plugins: [sentryTests()],
86
+ // Flaky-test issues come from retries.
87
+ test: { retry: process.env.CI ? 1 : 0 },
88
+ });
89
+ ```
90
+
91
+ The plugin adds a reporter, and makes the project's test runner one that records each file's spans
92
+ (Vitest's own runner, extended). Without a DSN or Spotlight it adds nothing, so local runs and
93
+ forks are unaffected.
94
+
95
+ - **With @ctrl/dom**: `plugins: [ctrlDom(), sentryTests()]`.
96
+ - **Projects** (`test.projects`): a project only gets the runner from plugins it has, so give each
97
+ project the plugin, or use `extends: true`.
98
+ - **Your own runner** (`test.runner`): build it on ours and add the reporter instead of the plugin
99
+ (which refuses to replace your runner).
100
+ ```ts
101
+ // my-runner.ts
102
+ import { withSentry } from "@ctrl/sentry-tests/vitest-runner";
103
+ export default withSentry(MyRunner); // MyRunner extends Vitest's TestRunner
104
+ ```
105
+ ```ts
106
+ // vitest.config.ts
107
+ test: { runner: "./my-runner.ts", reporters: ["default", "@ctrl/sentry-tests/vitest"] }
108
+ ```
109
+
110
+ ### 2. Jest
111
+
112
+ ```js
113
+ // jest.config.js
114
+ module.exports = {
115
+ reporters: ["default", "@ctrl/sentry-tests/jest"],
116
+ // Records describe blocks, tests, hooks and test functions as spans, with any environment.
117
+ testRunner: "@ctrl/sentry-tests/jest-runner",
118
+ };
119
+ ```
120
+
121
+ The test runner is Jest's own (jest-circus), listening to its events; without the reporter it
122
+ does nothing. Without the test runner the reporter still sends the issues, with no traces, and its
123
+ summary line says so. For flaky-test issues, retry with `jest.retryTimes(1)` in a setup file. Options go
124
+ in the reporter's entry: `["@ctrl/sentry-tests/jest", { tracesSampleRate: 0.1 }]`.
125
+
126
+ ### 3. The DSN
127
+
128
+ In CI:
129
+
130
+ ```yaml
131
+ # .github/workflows/test.yml
132
+ - run: npm test
133
+ env:
134
+ SENTRY_DSN: ${{ secrets.SENTRY_TESTS_DSN }}
135
+ ```
136
+
137
+ The release defaults to `GITHUB_SHA`, so issues say which commit broke a test. The run ends with
138
+ one line saying what was sent where:
139
+
140
+ ```
141
+ @ctrl/sentry-tests: 12 traces, 1 failed test, 2 flaky tests → o123.ingest.sentry.io
142
+ ```
143
+
144
+ **Locally**, start Spotlight (`npx @spotlightjs/spotlight`, then open http://localhost:8969) and run
145
+ your tests with `SENTRY_SPOTLIGHT=1`.
146
+
147
+ ## Options
148
+
149
+ `sentryTests({ … })`, or the Jest reporter's options. Each falls back to an environment variable.
150
+
151
+ | Option | Default | |
152
+ | --- | --- | --- |
153
+ | `dsn` | `SENTRY_DSN` | project to send to |
154
+ | `spotlight` | `SENTRY_SPOTLIGHT` | `true` for Spotlight's default sidecar (`http://localhost:8969/stream`), or its URL |
155
+ | `environment` | `SENTRY_ENVIRONMENT`, else `ci` under CI, else `local` | |
156
+ | `release` | `SENTRY_RELEASE`, else `GITHUB_SHA`, else the checkout's commit | regressions are tracked per release |
157
+ | `traces` | `true` | one trace per test file |
158
+ | `tracesSampleRate` | `SENTRY_TRACES_SAMPLE_RATE`, else `1` | fraction of files sent as traces; failures and flaky tests are always sent |
159
+ | `failures` | `true` | an issue per failing test |
160
+ | `flaky` | `true` | an issue per flaky test |
161
+ | `attachments` | `true` | attach the page (and whatever subscribers add) to failure events |
162
+ | `tags` | | extra tags on every event |
163
+
164
+ ## Spans
165
+
166
+ | `op` | Description | `data` |
167
+ | --- | --- | --- |
168
+ | `test.file` (transaction) | the file, relative to the root | `environment_setup` measurement (Vitest) |
169
+ | `test.collect` | importing the file, with its setup files | |
170
+ | `test.suite` | a describe block's full name | `code.lineno` (Vitest) |
171
+ | `test.case` | the test's full name (Jest: one per attempt) | `test.retries`, `test.flaky`, `code.lineno` (Vitest) |
172
+ | `test.hook` | `beforeEach`, `afterEach`, `beforeAll`, `afterAll`; Vitest also `beforeEach cleanup` (functions a hook returned) | `hooks` (how many ran), `test.retry` |
173
+ | `test.fn` | the test function | `test.retry` |
174
+
175
+ A run of hooks of one kind is one span: a test's `beforeEach` hooks, its describe blocks' and its
176
+ setup files' together, and likewise for `afterEach`. With @ctrl/dom, under them:
177
+
178
+ | `op` | Description, as the test wrote it | `data` |
179
+ | --- | --- | --- |
180
+ | `react.render`, `react.rerender` | `render(<Signup />)` | |
181
+ | `testing-library.query` | `getByRole("button", { name: "Save" })`, `findByText("Saved")` | `matches`, and for `findBy*` `checks` |
182
+ | `testing-library.wait_for` | `waitFor(() => expect(screen.getByText("Saved")).toBeVisible())` | `checks` |
183
+ | `testing-library.fire_event` | `fireEvent.click(button "Save")` | |
184
+ | `user-event.<action>` | `user.type(textbox "Email", "ada@example.com")` | |
185
+
186
+ Any of those during which @ctrl/dom's virtual clock skipped idle time has `clock.skipped_ms`. A
187
+ test keeps at most 300 spans of its own (the rest are counted in `spans.dropped`). A transaction
188
+ holds at most 1000, so a file with more is split by whole tests into further transactions in the
189
+ same trace (`<file> (part 2 of 4)`), and no test loses its spans.
190
+
191
+ ## Your own spans and attachments
192
+
193
+ Both go through `node:diagnostics_channel`, so nothing needs to import this package.
194
+
195
+ A span under whatever the test is running, on the `sentry-tests:span` tracing channel:
196
+
197
+ ```ts
198
+ import { tracingChannel } from "node:diagnostics_channel";
199
+
200
+ const spans = tracingChannel("sentry-tests:span");
201
+ export const seed = (rows: Row[]) =>
202
+ spans.tracePromise(() => db.insert(rows), { op: "db.seed", description: `seed ${rows.length} rows`, data: { rows: rows.length }, async: true });
203
+ ```
204
+
205
+ Attachments and contexts for a failed test, on the `sentry-tests:failure` channel, published before
206
+ the test's afterEach hooks run:
207
+
208
+ ```ts
209
+ // a setup file
210
+ import { channel } from "node:diagnostics_channel";
211
+ import { store } from "../src/store";
212
+
213
+ channel("sentry-tests:failure").subscribe((failure) => {
214
+ failure.attachments.push({ filename: "store.json", contentType: "application/json", data: JSON.stringify(store.getState()) });
215
+ failure.contexts.feature_flags = { ...flags };
216
+ // failure.waitUntil(promise) holds the test (up to 5 s) for async work, a screenshot say.
217
+ });
218
+ ```
219
+
220
+ The message's fields are typed as `FailureMessage`, exported from `@ctrl/sentry-tests`. A
221
+ subscriber must not throw.
222
+
223
+ ## Cost
224
+
225
+ Nothing is collected unless a DSN or Spotlight is set. With reporting on, Sentry's own component
226
+ tests (15 files, 589 tests, Jest) ran in the same wall time as without it, within run-to-run
227
+ noise: the worker records spans into arrays, and the reporter sends while the run continues. Each
228
+ test file is a transaction, which counts against span quota: `tracesSampleRate` keeps a fraction
229
+ of them.
230
+
231
+ ## Compared with @sentry/jest-environment
232
+
233
+ [@sentry/jest-environment](https://github.com/getsentry/jest-sentry-environment) records Jest
234
+ test files as transactions through the Sentry SDK, as a test environment wrapping jsdom or node.
235
+ This package:
236
+
237
+ - works with Vitest and Jest, with any environment, because it hooks the test runner rather than
238
+ replacing the environment;
239
+ - reports failing and flaky tests as issues, with the page attached, not only performance data;
240
+ - sends from the main process (workers only collect), without the Sentry SDK or any dependency;
241
+ - takes spans and attachments from anything in the test process over diagnostics channels.
242
+
243
+ ## Limits
244
+
245
+ - Tests running concurrently in one file (`test.concurrent`) under Jest share the span stack:
246
+ their spans can land under each other. Vitest nests them correctly.
247
+ - Vitest's browser mode runs its own runner in the browser: there the reporter sends issues
248
+ without traces or page captures.
249
+ - `page.html` is the page as rendered, so it holds whatever the test rendered. Set
250
+ `attachments: false` if that shouldn't leave CI.
251
+ - Jest reports console output per file, not per test, so Jest failures have no console
252
+ breadcrumbs.
253
+
254
+ ## How it works
255
+
256
+ In the test worker, the runner (Vitest's `TestRunner` with its `trace` hook wrapped; for Jest,
257
+ jest-circus's events) opens a span for each describe block, test, hook and test function. The
258
+ current span lives in `AsyncLocalStorage`, so spans published on the tracing channels while a test
259
+ function awaits land under it. Times come from `perf_hooks`, which fake timers leave alone. When a
260
+ test fails, the runner captures the page and publishes `sentry-tests:failure` before the afterEach
261
+ hooks run. Vitest hands each file's spans to the main process on the file task's meta; Jest's
262
+ runner writes them to a temporary directory the reporter set up. The reporter builds the envelopes
263
+ and sends them, a few at a time, as each file finishes.
264
+
265
+ ## Development
266
+
267
+ `node packages/sentry-tests/scripts/relay-check.ts` runs what the reporter builds through Relay,
268
+ Sentry's ingestion service (Docker, `getsentry/relay`), and fails if Relay rejects an envelope or
269
+ had to drop or fix a field. With `--run "<command>"` it runs a real suite with `SENTRY_DSN`
270
+ pointing at Relay instead.
271
+
272
+ MIT licensed. Part of [@ctrl/dom](https://github.com/scttcper/dom)'s repository.
@@ -0,0 +1,6 @@
1
+ // src/channels.ts
2
+ /** Tracing channels whose spans are recorded. */
3
+ const SPAN_CHANNELS = ["sentry-tests:span", "ctrl-dom:span"];
4
+ const FAILURE_CHANNEL = "sentry-tests:failure";
5
+
6
+ export { SPAN_CHANNELS as n, FAILURE_CHANNEL as t };