@woovi/jest-test-reporter 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/dist/index.d.ts +15 -0
- package/dist/index.js +54 -0
- package/package.json +35 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AggregatedResult, TestContext } from '@jest/test-result';
|
|
2
|
+
import type { Reporter } from '@jest/reporters';
|
|
3
|
+
import type { Config } from '@jest/types';
|
|
4
|
+
interface ReporterOptions {
|
|
5
|
+
url?: string;
|
|
6
|
+
repo?: string;
|
|
7
|
+
package?: string;
|
|
8
|
+
token?: string;
|
|
9
|
+
}
|
|
10
|
+
declare class WooviTestReporter implements Pick<Reporter, 'onRunComplete'> {
|
|
11
|
+
private options;
|
|
12
|
+
constructor(_globalConfig: Config.GlobalConfig, options: ReporterOptions);
|
|
13
|
+
onRunComplete(_testContexts: Set<TestContext>, results: AggregatedResult): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export default WooviTestReporter;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
class WooviTestReporter {
|
|
2
|
+
options;
|
|
3
|
+
constructor(_globalConfig, options){
|
|
4
|
+
this.options = options;
|
|
5
|
+
}
|
|
6
|
+
async onRunComplete(_testContexts, results) {
|
|
7
|
+
const url = this.options.url || process.env.TEST_AGGREGATOR_URL;
|
|
8
|
+
const repo = this.options.repo || process.env.REPO || process.env.GITHUB_REPOSITORY || '';
|
|
9
|
+
const pkg = this.options.package || process.env.PACKAGE || '';
|
|
10
|
+
const token = this.options.token || process.env.TEST_AGGREGATOR_TOKEN || '';
|
|
11
|
+
const commit = process.env.COMMIT_SHA || process.env.GITHUB_SHA || '';
|
|
12
|
+
const branch = process.env.BRANCH || process.env.GITHUB_REF_NAME || '';
|
|
13
|
+
if (!url) return void console.warn('[woovi-test-reporter] No url configured, skipping upload');
|
|
14
|
+
const tests = results.testResults.flatMap((suite)=>suite.testResults.map((test)=>({
|
|
15
|
+
name: test.fullName || test.title,
|
|
16
|
+
status: 'passed' === test.status ? 'passed' : 'failed' === test.status ? 'failed' : 'skipped',
|
|
17
|
+
duration: test.duration || 0,
|
|
18
|
+
suite: suite.testFilePath,
|
|
19
|
+
message: test.failureMessages?.join('\n') || void 0
|
|
20
|
+
})));
|
|
21
|
+
const report = {
|
|
22
|
+
results: {
|
|
23
|
+
tool: {
|
|
24
|
+
name: 'jest'
|
|
25
|
+
},
|
|
26
|
+
tests
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
try {
|
|
30
|
+
const res = await fetch(url + '/api/reports', {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
headers: {
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
Authorization: `Bearer ${token}`
|
|
35
|
+
},
|
|
36
|
+
body: JSON.stringify({
|
|
37
|
+
repo,
|
|
38
|
+
package: pkg,
|
|
39
|
+
branch,
|
|
40
|
+
commit,
|
|
41
|
+
report
|
|
42
|
+
})
|
|
43
|
+
});
|
|
44
|
+
if (res.ok) {
|
|
45
|
+
const data = await res.json();
|
|
46
|
+
console.log(`[woovi-test-reporter] Uploaded: ${data.summary?.total} tests`);
|
|
47
|
+
} else console.warn(`[woovi-test-reporter] Upload failed: ${res.status} ${await res.text()}`);
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.warn("[woovi-test-reporter] Upload error:", err);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const src = WooviTestReporter;
|
|
54
|
+
export { src as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@woovi/jest-test-reporter",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Jest reporter that uploads test results to Woovi Test Aggregator",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@jest/reporters": ">=29.0.0",
|
|
23
|
+
"@jest/test-result": ">=29.0.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@jest/reporters": "^29.0.0",
|
|
27
|
+
"@jest/test-result": "^29.0.0",
|
|
28
|
+
"@jest/types": "^29.0.0",
|
|
29
|
+
"@rslib/core": "^0.6.0",
|
|
30
|
+
"typescript": "^5.7.0"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "rslib build"
|
|
34
|
+
}
|
|
35
|
+
}
|