@kinora/reporter 0.0.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 +21 -0
- package/dist/index.d.mts +27 -0
- package/dist/index.mjs +151 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present Joris Gallot <https://github.com/joris-gallot>
|
|
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/dist/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CiMeta, GitMeta } from "@kinora/core";
|
|
2
|
+
import { FullConfig, FullResult, Reporter, Suite } from "@playwright/test/reporter";
|
|
3
|
+
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
interface KinoraReporterOptions {
|
|
6
|
+
/** kinora server base URL. Defaults to env KINORA_URL. */
|
|
7
|
+
url?: string;
|
|
8
|
+
/** Project API token. Defaults to env KINORA_TOKEN (keep it out of the config file). */
|
|
9
|
+
token?: string;
|
|
10
|
+
/** Target project. `name` defaults to `slug`. */
|
|
11
|
+
project: {
|
|
12
|
+
slug: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
};
|
|
15
|
+
git?: GitMeta;
|
|
16
|
+
ci?: CiMeta;
|
|
17
|
+
}
|
|
18
|
+
declare class KinoraReporter implements Reporter {
|
|
19
|
+
private readonly options;
|
|
20
|
+
private suite;
|
|
21
|
+
private config;
|
|
22
|
+
constructor(options: KinoraReporterOptions);
|
|
23
|
+
onBegin(config: FullConfig, suite: Suite): void;
|
|
24
|
+
onEnd(result: FullResult): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { KinoraReporterOptions, KinoraReporter as default };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import { createIngestClient, isTraceAttachment, makeTestKey } from "@kinora/core";
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
function identity(test) {
|
|
6
|
+
let file = "";
|
|
7
|
+
let projectName = "";
|
|
8
|
+
const describes = [];
|
|
9
|
+
let suite = test.parent;
|
|
10
|
+
while (suite) {
|
|
11
|
+
if (suite.type === "file") file = suite.title;
|
|
12
|
+
else if (suite.type === "project") projectName = suite.title;
|
|
13
|
+
else if (suite.type === "describe" && suite.title) describes.unshift(suite.title);
|
|
14
|
+
suite = suite.parent;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
file,
|
|
18
|
+
titlePath: [
|
|
19
|
+
file,
|
|
20
|
+
...describes,
|
|
21
|
+
test.title
|
|
22
|
+
],
|
|
23
|
+
projectName
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function toNormTest(test) {
|
|
27
|
+
const { file, titlePath, projectName } = identity(test);
|
|
28
|
+
const last = test.results.at(-1);
|
|
29
|
+
return {
|
|
30
|
+
testKey: makeTestKey(file, titlePath, projectName),
|
|
31
|
+
title: test.title,
|
|
32
|
+
titlePath,
|
|
33
|
+
file,
|
|
34
|
+
line: test.location.line,
|
|
35
|
+
column: test.location.column,
|
|
36
|
+
projectName,
|
|
37
|
+
status: test.outcome(),
|
|
38
|
+
ok: test.ok(),
|
|
39
|
+
duration: test.results.reduce((sum, r) => sum + r.duration, 0),
|
|
40
|
+
retries: Math.max(0, test.results.length - 1),
|
|
41
|
+
tags: test.tags,
|
|
42
|
+
annotations: test.annotations.map((a) => ({
|
|
43
|
+
type: a.type,
|
|
44
|
+
description: a.description
|
|
45
|
+
})),
|
|
46
|
+
errors: (last?.errors ?? []).flatMap((e) => e.message ? [{
|
|
47
|
+
message: e.message,
|
|
48
|
+
stack: e.stack,
|
|
49
|
+
location: e.location
|
|
50
|
+
}] : []),
|
|
51
|
+
attachments: (last?.attachments ?? []).map((a) => ({
|
|
52
|
+
name: a.name,
|
|
53
|
+
contentType: a.contentType,
|
|
54
|
+
path: a.path,
|
|
55
|
+
hasBody: a.body != null
|
|
56
|
+
}))
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function countsOf(tests) {
|
|
60
|
+
const counts = {
|
|
61
|
+
total: tests.length,
|
|
62
|
+
expected: 0,
|
|
63
|
+
unexpected: 0,
|
|
64
|
+
flaky: 0,
|
|
65
|
+
skipped: 0
|
|
66
|
+
};
|
|
67
|
+
for (const t of tests) counts[t.status]++;
|
|
68
|
+
return counts;
|
|
69
|
+
}
|
|
70
|
+
function detectGit() {
|
|
71
|
+
const sha = process.env.GITHUB_SHA;
|
|
72
|
+
const branch = process.env.GITHUB_REF_NAME;
|
|
73
|
+
if (!sha && !branch) return void 0;
|
|
74
|
+
return {
|
|
75
|
+
sha,
|
|
76
|
+
branch
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function detectCi() {
|
|
80
|
+
if (!process.env.GITHUB_ACTIONS) return void 0;
|
|
81
|
+
const { GITHUB_SERVER_URL, GITHUB_REPOSITORY, GITHUB_RUN_ID, GITHUB_RUN_NUMBER } = process.env;
|
|
82
|
+
return {
|
|
83
|
+
provider: "github",
|
|
84
|
+
runUrl: GITHUB_SERVER_URL && GITHUB_REPOSITORY && GITHUB_RUN_ID ? `${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}` : void 0,
|
|
85
|
+
runNumber: GITHUB_RUN_NUMBER
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
var KinoraReporter = class {
|
|
89
|
+
options;
|
|
90
|
+
suite;
|
|
91
|
+
config;
|
|
92
|
+
constructor(options) {
|
|
93
|
+
this.options = options;
|
|
94
|
+
}
|
|
95
|
+
onBegin(config, suite) {
|
|
96
|
+
this.config = config;
|
|
97
|
+
this.suite = suite;
|
|
98
|
+
}
|
|
99
|
+
async onEnd(result) {
|
|
100
|
+
const url = this.options.url ?? process.env.KINORA_URL;
|
|
101
|
+
const token = this.options.token ?? process.env.KINORA_TOKEN;
|
|
102
|
+
if (!url || !token) {
|
|
103
|
+
console.warn("[kinora] skipping upload: missing url/token (set KINORA_URL + KINORA_TOKEN)");
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const tests = (this.suite?.allTests() ?? []).map(toNormTest);
|
|
107
|
+
const payload = {
|
|
108
|
+
project: {
|
|
109
|
+
slug: this.options.project.slug,
|
|
110
|
+
name: this.options.project.name ?? this.options.project.slug
|
|
111
|
+
},
|
|
112
|
+
run: {
|
|
113
|
+
startedAt: result.startTime.toISOString(),
|
|
114
|
+
duration: result.duration,
|
|
115
|
+
counts: countsOf(tests),
|
|
116
|
+
playwrightVersion: this.config?.version,
|
|
117
|
+
git: this.options.git ?? detectGit(),
|
|
118
|
+
ci: this.options.ci ?? detectCi()
|
|
119
|
+
},
|
|
120
|
+
tests
|
|
121
|
+
};
|
|
122
|
+
try {
|
|
123
|
+
const client = createIngestClient({
|
|
124
|
+
baseUrl: url,
|
|
125
|
+
token
|
|
126
|
+
});
|
|
127
|
+
const res = await client.uploadRun(payload);
|
|
128
|
+
let traces = 0;
|
|
129
|
+
for (const t of tests) for (const a of t.attachments) {
|
|
130
|
+
if (!a.path || !isTraceAttachment(a)) continue;
|
|
131
|
+
try {
|
|
132
|
+
await client.uploadArtifact({
|
|
133
|
+
runId: res.runId,
|
|
134
|
+
testKey: t.testKey,
|
|
135
|
+
name: a.name,
|
|
136
|
+
contentType: a.contentType,
|
|
137
|
+
body: await readFile(a.path)
|
|
138
|
+
});
|
|
139
|
+
traces++;
|
|
140
|
+
} catch (err) {
|
|
141
|
+
console.warn(`[kinora] trace upload failed for ${t.testKey}:`, err instanceof Error ? err.message : err);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
console.log(`[kinora] uploaded ${res.tests} tests + ${traces} traces (run ${res.runId})`);
|
|
145
|
+
} catch (err) {
|
|
146
|
+
console.error(`[kinora] upload failed:`, err instanceof Error ? err.message : err);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
//#endregion
|
|
151
|
+
export { KinoraReporter as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kinora/reporter",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "Playwright reporter that uploads test results to a kinora server",
|
|
6
|
+
"author": "Joris Gallot",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/joris-gallot/kinora#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/joris-gallot/kinora.git",
|
|
12
|
+
"directory": "packages/reporter"
|
|
13
|
+
},
|
|
14
|
+
"bugs": "https://github.com/joris-gallot/kinora/issues",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"playwright",
|
|
17
|
+
"reporter",
|
|
18
|
+
"test-report",
|
|
19
|
+
"ci",
|
|
20
|
+
"kinora"
|
|
21
|
+
],
|
|
22
|
+
"exports": {
|
|
23
|
+
".": "./dist/index.mjs"
|
|
24
|
+
},
|
|
25
|
+
"main": "./dist/index.mjs",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=20"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsdown",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"prepublishOnly": "tsdown"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@playwright/test": ">=1.40.0"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@kinora/core": "workspace:*"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@playwright/test": "^1.60.0",
|
|
48
|
+
"@types/node": "^24.12.3",
|
|
49
|
+
"tsdown": "^0.22.2",
|
|
50
|
+
"typescript": "~6.0.2"
|
|
51
|
+
}
|
|
52
|
+
}
|