@hedia/test 1.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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/index.js +88 -0
  3. package/package.json +19 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # test
package/index.js ADDED
@@ -0,0 +1,88 @@
1
+ import { writeFileSync } from "fs";
2
+ export default async function* testReporter(source) {
3
+ try {
4
+ const events = [];
5
+ const tests = [];
6
+ let nestedTitles = [];
7
+ let nestingLevel = -1;
8
+
9
+ for await (const event of source) {
10
+ events.push(event);
11
+
12
+ switch (event.type) {
13
+ case "test:start":
14
+ if (nestingLevel < event.data.nesting) {
15
+ nestedTitles.push(event.data.name);
16
+ nestingLevel += 1;
17
+ }
18
+ if (nestingLevel === event.data.nesting) {
19
+ nestedTitles[nestedTitles.length - 1] = event.data.name;
20
+ }
21
+ break;
22
+ case "test:pass":
23
+ if (nestingLevel > event.data.nesting) {
24
+ nestedTitles = nestedTitles.slice(0, -1);
25
+ nestingLevel -= 1;
26
+ }
27
+ if (event.data?.details?.type === "suite") {
28
+ break;
29
+ }
30
+
31
+ yield `test ${nestedTitles.join(" - ")}: pass (${event.data.details.duration_ms}ms)\n`;
32
+
33
+ tests.push({
34
+ name: nestedTitles.join(" - "),
35
+ number: tests.length + 1,
36
+ duration: event.data.details.duration_ms,
37
+ status: "pass",
38
+ });
39
+
40
+ break;
41
+ case "test:fail":
42
+ if (nestingLevel > event.data.nesting) {
43
+ nestedTitles = nestedTitles.slice(0, -1);
44
+ nestingLevel -= 1;
45
+ }
46
+ if (event.data?.details?.type === "suite") {
47
+ break;
48
+ }
49
+
50
+ yield `test ${nestedTitles.join(" - ")}: fail (${event.data.details.duration_ms}ms)\n`;
51
+ tests.push({
52
+ name: nestedTitles.join(" - "),
53
+ number: tests.length + 1,
54
+ duration: event.data.details.duration_ms,
55
+ status: "fail",
56
+ });
57
+
58
+ break;
59
+ }
60
+ }
61
+
62
+ // const input = "http://localhost:8469/api/v1/reports";
63
+ const input = "https://test.hedia.dev/api/v1/reports";
64
+ const init = {
65
+ method: "POST",
66
+ headers: {
67
+ "Content-Type": "application/json",
68
+ },
69
+ body: JSON.stringify(
70
+ {
71
+ title: new Date().toISOString(),
72
+ tests,
73
+ },
74
+ null,
75
+ 4,
76
+ ),
77
+ };
78
+
79
+ const response = await fetch(input, init);
80
+
81
+ console.log(response.ok ? "OK" : "NOT OK");
82
+ yield true;
83
+
84
+ writeFileSync("./test-report.json", JSON.stringify(events, null, 4), "utf-8");
85
+ } catch (err) {
86
+ console.error(err.message);
87
+ }
88
+ }
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@hedia/test",
3
+ "version": "1.0.1",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/hedia-team/test.git"
12
+ },
13
+ "author": "",
14
+ "license": "UNLICENSED",
15
+ "bugs": {
16
+ "url": "https://github.com/hedia-team/test/issues"
17
+ },
18
+ "homepage": "https://github.com/hedia-team/test#readme"
19
+ }