@ctrl/sentry-tests 0.0.0-stage → 0.1.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 +21 -0
- package/NOTICE +338 -0
- package/README.md +271 -2
- package/dist/_chunks/channels-CLjUmyuI.js +6 -0
- package/dist/_chunks/collector-DiJaNK5H.js +271 -0
- package/dist/_chunks/delivery-DSYzskz8.js +61 -0
- package/dist/_chunks/jest-collector-B4DJnUVQ.js +135 -0
- package/dist/_chunks/report-CgKIcCfQ.js +545 -0
- package/dist/index.js +4 -0
- package/dist/jest-runner.js +27 -0
- package/dist/jest.js +104 -0
- package/dist/types/channels.d.ts +36 -0
- package/dist/types/collector.d.ts +80 -0
- package/dist/types/delivery.d.ts +10 -0
- package/dist/types/envelope.d.ts +68 -0
- package/dist/types/html.d.ts +2 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/jest-collector.d.ts +43 -0
- package/dist/types/jest-runner.d.ts +11 -0
- package/dist/types/jest.d.ts +42 -0
- package/dist/types/options.d.ts +46 -0
- package/dist/types/report.d.ts +60 -0
- package/dist/types/vitest-runner.d.ts +13 -0
- package/dist/types/vitest.d.ts +21 -0
- package/dist/vitest-runner.js +167 -0
- package/dist/vitest.js +119 -0
- package/package.json +76 -3
package/dist/vitest.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { i as sendEnvelope, n as buildReport, r as resolveOptions, t as FILE_FAILURE } from "./_chunks/report-CgKIcCfQ.js";
|
|
2
|
+
import { t as Delivery } from "./_chunks/delivery-DSYzskz8.js";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
// src/vitest.ts
|
|
6
|
+
const RUNNER = fileURLToPath(new URL(import.meta.url.endsWith(".ts") ? "./vitest-runner.ts" : "./vitest-runner.js", import.meta.url));
|
|
7
|
+
/** Vitest instances the reporter was added to (configureVitest runs once per project). */
|
|
8
|
+
const registered = /* @__PURE__ */ new WeakSet();
|
|
9
|
+
/** The Vitest plugin: spans from the runner, events from the reporter, when there is somewhere to send them. */
|
|
10
|
+
function sentryTests(options = {}) {
|
|
11
|
+
const resolved = resolveOptions(options);
|
|
12
|
+
return {
|
|
13
|
+
name: "@ctrl/sentry-tests",
|
|
14
|
+
config(config) {
|
|
15
|
+
if (resolved === null) return;
|
|
16
|
+
const own = config.test?.runner;
|
|
17
|
+
if (own !== void 0) throw new Error(`@ctrl/sentry-tests: the project has its own test runner (${own}). Build it with withSentry() from "@ctrl/sentry-tests/vitest-runner" and drop sentryTests() from the plugins, adding the reporter instead: reporters: ["default", "@ctrl/sentry-tests/vitest"].`);
|
|
18
|
+
return { test: { runner: RUNNER } };
|
|
19
|
+
},
|
|
20
|
+
configureVitest({ vitest }) {
|
|
21
|
+
if (resolved === null || registered.has(vitest)) return;
|
|
22
|
+
registered.add(vitest);
|
|
23
|
+
vitest.config.reporters.push(new SentryReporter(options));
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The reporter, which the plugin adds. With a runner built on withSentry(), add it yourself:
|
|
29
|
+
* `reporters: ["default", "@ctrl/sentry-tests/vitest"]`.
|
|
30
|
+
*/
|
|
31
|
+
var SentryReporter = class {
|
|
32
|
+
options;
|
|
33
|
+
#root = process.cwd();
|
|
34
|
+
#vitest = null;
|
|
35
|
+
#delivery;
|
|
36
|
+
/** Each test's console output, by task id, until its file is reported. */
|
|
37
|
+
#console = /* @__PURE__ */ new Map();
|
|
38
|
+
constructor(options = {}) {
|
|
39
|
+
this.options = resolveOptions(options);
|
|
40
|
+
this.#delivery = this.options === null ? null : new Delivery(this.options, sendEnvelope);
|
|
41
|
+
}
|
|
42
|
+
onInit(vitest) {
|
|
43
|
+
this.#vitest = vitest;
|
|
44
|
+
this.#root = vitest.config.root;
|
|
45
|
+
}
|
|
46
|
+
onUserConsoleLog(log) {
|
|
47
|
+
if (this.options === null || log.taskId === void 0) return;
|
|
48
|
+
const entries = this.#console.get(log.taskId) ?? [];
|
|
49
|
+
entries.push({
|
|
50
|
+
timestamp: log.time / 1e3,
|
|
51
|
+
stream: log.type,
|
|
52
|
+
message: log.content.trimEnd()
|
|
53
|
+
});
|
|
54
|
+
this.#console.set(log.taskId, entries);
|
|
55
|
+
}
|
|
56
|
+
onTestModuleEnd(module) {
|
|
57
|
+
if (this.options === null || this.#delivery === null) return;
|
|
58
|
+
const tests = [...module.children.allTests()].map((test) => {
|
|
59
|
+
const report = toTestCaseReport(test);
|
|
60
|
+
const output = this.#console.get(test.id);
|
|
61
|
+
if (output !== void 0) {
|
|
62
|
+
report.console = output;
|
|
63
|
+
this.#console.delete(test.id);
|
|
64
|
+
}
|
|
65
|
+
return report;
|
|
66
|
+
});
|
|
67
|
+
const project = module.project.name;
|
|
68
|
+
this.#delivery.add(buildReport({
|
|
69
|
+
runner: "vitest",
|
|
70
|
+
root: this.#root,
|
|
71
|
+
file: module.moduleId,
|
|
72
|
+
...project ? { project } : {},
|
|
73
|
+
tests,
|
|
74
|
+
collected: module.meta().sentryTests ?? null,
|
|
75
|
+
environmentSetupMs: module.diagnostic().environmentSetupDuration,
|
|
76
|
+
outsideTests: [...module.errors().map((e) => ({
|
|
77
|
+
name: FILE_FAILURE,
|
|
78
|
+
error: toErrorInfo(e)
|
|
79
|
+
})), ...[...module.children.allSuites()].flatMap((suite) => suite.errors().map((e) => ({
|
|
80
|
+
name: suite.fullName,
|
|
81
|
+
error: toErrorInfo(e)
|
|
82
|
+
})))]
|
|
83
|
+
}, this.options));
|
|
84
|
+
}
|
|
85
|
+
async onTestRunEnd() {
|
|
86
|
+
if (this.#delivery === null) return;
|
|
87
|
+
const summary = await this.#delivery.flush();
|
|
88
|
+
if (summary !== null) (this.#vitest?.logger ?? console).log(summary);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
function toTestCaseReport(test) {
|
|
92
|
+
const result = test.result();
|
|
93
|
+
const diagnostic = test.diagnostic();
|
|
94
|
+
return {
|
|
95
|
+
key: test.id,
|
|
96
|
+
name: test.fullName,
|
|
97
|
+
state: result.state === "passed" ? "pass" : result.state === "failed" ? "fail" : "skip",
|
|
98
|
+
duration: diagnostic?.duration ?? 0,
|
|
99
|
+
retries: diagnostic?.retryCount ?? 0,
|
|
100
|
+
flaky: diagnostic?.flaky ?? false,
|
|
101
|
+
errors: (result.errors ?? []).map(toErrorInfo)
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** Vitest's serialized errors carry source-mapped frames (`stacks`). */
|
|
105
|
+
function toErrorInfo(e) {
|
|
106
|
+
return {
|
|
107
|
+
name: e.name,
|
|
108
|
+
message: e.message,
|
|
109
|
+
stack: e.stack,
|
|
110
|
+
...e.stacks ? { frames: e.stacks.map((s) => ({
|
|
111
|
+
method: s.method,
|
|
112
|
+
file: s.file,
|
|
113
|
+
line: s.line,
|
|
114
|
+
column: s.column
|
|
115
|
+
})) } : {}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { SentryReporter, SentryReporter as default, sentryTests };
|
package/package.json
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ctrl/sentry-tests",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Test runs in Sentry for Vitest and Jest: each test file as a trace with spans for describe blocks, tests, hooks and test functions, failing tests as issues with the page attached, flaky tests as issues. No Sentry SDK.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sentry",
|
|
7
|
+
"vitest",
|
|
8
|
+
"jest",
|
|
9
|
+
"tracing",
|
|
10
|
+
"flaky-tests",
|
|
11
|
+
"test-observability",
|
|
12
|
+
"spotlight"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"homepage": "https://github.com/scttcper/dom/tree/main/packages/sentry-tests#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/scttcper/dom/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/scttcper/dom.git",
|
|
22
|
+
"directory": "packages/sentry-tests"
|
|
23
|
+
},
|
|
24
|
+
"author": "Scott Cooper <scttcper@gmail.com>",
|
|
25
|
+
"type": "module",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"README.md",
|
|
29
|
+
"NOTICE",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=26"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"jest": ">=30.0.0",
|
|
37
|
+
"jest-circus": ">=30.0.0",
|
|
38
|
+
"vitest": ">=5.0.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"jest": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"jest-circus": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"vitest": {
|
|
48
|
+
"optional": true
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"main": "./dist/index.js",
|
|
52
|
+
"types": "./dist/types/index.d.ts",
|
|
53
|
+
"exports": {
|
|
54
|
+
".": {
|
|
55
|
+
"types": "./dist/types/index.d.ts",
|
|
56
|
+
"default": "./dist/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./vitest": {
|
|
59
|
+
"types": "./dist/types/vitest.d.ts",
|
|
60
|
+
"default": "./dist/vitest.js"
|
|
61
|
+
},
|
|
62
|
+
"./vitest-runner": {
|
|
63
|
+
"types": "./dist/types/vitest-runner.d.ts",
|
|
64
|
+
"default": "./dist/vitest-runner.js"
|
|
65
|
+
},
|
|
66
|
+
"./jest": {
|
|
67
|
+
"types": "./dist/types/jest.d.ts",
|
|
68
|
+
"default": "./dist/jest.js"
|
|
69
|
+
},
|
|
70
|
+
"./jest-runner": {
|
|
71
|
+
"types": "./dist/types/jest-runner.d.ts",
|
|
72
|
+
"default": "./dist/jest-runner.js"
|
|
73
|
+
},
|
|
74
|
+
"./package.json": "./package.json"
|
|
75
|
+
},
|
|
76
|
+
"publishConfig": {
|
|
77
|
+
"access": "public"
|
|
78
|
+
}
|
|
6
79
|
}
|