@hedia/test 1.2.1 → 1.2.2
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/README.md +11 -1
- package/package.json +12 -6
- package/src/reporter.js +80 -75
package/README.md
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Custom Test Reporter
|
|
2
|
+
|
|
3
|
+
Format and send test output to the `test-service`.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
node --test --experimental-test-coverage --test-reporter @hedia/test/reporter
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Tip: Save the following command as a script in `package.json`
|
package/package.json
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hedia/test",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.2.2",
|
|
4
|
+
"description": "Custom Test Reporter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./reporter": "./src/reporter.js"
|
|
8
|
-
},
|
|
9
|
-
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
+
"prettier:check": "prettier --check .",
|
|
12
|
+
"prettier:write": "prettier --write ."
|
|
10
13
|
},
|
|
11
14
|
"repository": {
|
|
12
15
|
"type": "git",
|
|
13
16
|
"url": "git+https://github.com/hedia-team/test.git"
|
|
14
17
|
},
|
|
15
|
-
"author": "",
|
|
18
|
+
"author": "Mathieu Veber <mathieu@hedia.com>",
|
|
16
19
|
"license": "UNLICENSED",
|
|
17
20
|
"bugs": {
|
|
18
21
|
"url": "https://github.com/hedia-team/test/issues"
|
|
19
22
|
},
|
|
20
|
-
"homepage": "https://github.com/hedia-team/test#readme"
|
|
23
|
+
"homepage": "https://github.com/hedia-team/test#readme",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"prettier": "^3.0.3"
|
|
26
|
+
}
|
|
21
27
|
}
|
package/src/reporter.js
CHANGED
|
@@ -1,88 +1,93 @@
|
|
|
1
1
|
import { readFileSync } from "fs";
|
|
2
2
|
|
|
3
3
|
export default async function* testReporter(source) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
try {
|
|
5
|
+
let title = "";
|
|
6
|
+
const tests = [];
|
|
7
|
+
let nestedTitles = [];
|
|
8
|
+
let nestingLevel = -1;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
10
|
+
for await (const event of source) {
|
|
11
|
+
switch (event.type) {
|
|
12
|
+
case "test:start":
|
|
13
|
+
if (nestingLevel < event.data.nesting) {
|
|
14
|
+
nestedTitles.push(event.data.name);
|
|
15
|
+
nestingLevel += 1;
|
|
16
|
+
}
|
|
17
|
+
if (nestingLevel === event.data.nesting) {
|
|
18
|
+
nestedTitles[nestedTitles.length - 1] = event.data.name;
|
|
19
|
+
}
|
|
20
|
+
break;
|
|
21
|
+
case "test:pass":
|
|
22
|
+
if (nestingLevel > event.data.nesting) {
|
|
23
|
+
nestedTitles = nestedTitles.slice(0, -1);
|
|
24
|
+
nestingLevel -= 1;
|
|
25
|
+
}
|
|
26
|
+
if (event.data?.details?.type === "suite") {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
yield `test ${nestedTitles.join(" - ")}: pass (${
|
|
31
|
+
event.data.details.duration_ms
|
|
32
|
+
}ms)\n`;
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
tests.push({
|
|
35
|
+
name: nestedTitles.join(" - "),
|
|
36
|
+
number: tests.length + 1,
|
|
37
|
+
duration: event.data.details.duration_ms,
|
|
38
|
+
status: "pass",
|
|
39
|
+
});
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
break;
|
|
42
|
+
case "test:fail":
|
|
43
|
+
if (nestingLevel > event.data.nesting) {
|
|
44
|
+
nestedTitles = nestedTitles.slice(0, -1);
|
|
45
|
+
nestingLevel -= 1;
|
|
46
|
+
}
|
|
47
|
+
if (event.data?.details?.type === "suite") {
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
yield `test ${nestedTitles.join(" - ")}: fail (${
|
|
52
|
+
event.data.details.duration_ms
|
|
53
|
+
}ms)\n`;
|
|
54
|
+
tests.push({
|
|
55
|
+
name: nestedTitles.join(" - "),
|
|
56
|
+
number: tests.length + 1,
|
|
57
|
+
duration: event.data.details.duration_ms,
|
|
58
|
+
status: "fail",
|
|
59
|
+
});
|
|
56
60
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
break;
|
|
62
|
+
case "test:coverage":
|
|
63
|
+
const location =
|
|
64
|
+
event.data.summary.workingDirectory + "/package.json";
|
|
65
|
+
const { name, version } = JSON.parse(readFileSync(location, "utf8"));
|
|
66
|
+
title = `${name}@${version}`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
64
69
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
70
|
+
const input = "https://test.hedia.dev/api/v1/reports";
|
|
71
|
+
const init = {
|
|
72
|
+
method: "POST",
|
|
73
|
+
headers: {
|
|
74
|
+
"Content-Type": "application/json",
|
|
75
|
+
},
|
|
76
|
+
body: JSON.stringify(
|
|
77
|
+
{
|
|
78
|
+
title,
|
|
79
|
+
tests,
|
|
80
|
+
},
|
|
81
|
+
null,
|
|
82
|
+
4,
|
|
83
|
+
),
|
|
84
|
+
};
|
|
80
85
|
|
|
81
|
-
|
|
86
|
+
const response = await fetch(input, init);
|
|
82
87
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
console.log(response.ok ? "OK" : "NOT OK");
|
|
89
|
+
yield true;
|
|
90
|
+
} catch (err) {
|
|
91
|
+
console.error(err.message);
|
|
92
|
+
}
|
|
88
93
|
}
|