factorio-test-cli 3.0.1 → 3.0.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/output-formatter.js +2 -0
- package/output-formatter.test.js +45 -1
- package/package.json +1 -1
- package/progress-renderer.js +11 -6
- package/progress-renderer.test.js +23 -0
package/output-formatter.js
CHANGED
|
@@ -63,6 +63,8 @@ export class OutputPrinter {
|
|
|
63
63
|
printTestResult(test) {
|
|
64
64
|
if (this.options.quiet || this.options.useProgressBar)
|
|
65
65
|
return;
|
|
66
|
+
if ((test.result === "skipped" || test.result === "todo") && !this.options.verbose)
|
|
67
|
+
return;
|
|
66
68
|
this.formatter.formatTestResult(test);
|
|
67
69
|
}
|
|
68
70
|
printFailures(tests) {
|
package/output-formatter.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { OutputFormatter } from "./output-formatter.js";
|
|
2
|
+
import { OutputFormatter, OutputPrinter } from "./output-formatter.js";
|
|
3
3
|
describe("OutputFormatter", () => {
|
|
4
4
|
let consoleSpy;
|
|
5
5
|
let output;
|
|
@@ -91,3 +91,47 @@ describe("OutputFormatter", () => {
|
|
|
91
91
|
expect(output[0]).toContain("todo test");
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
|
+
describe("OutputPrinter", () => {
|
|
95
|
+
let consoleSpy;
|
|
96
|
+
let output;
|
|
97
|
+
beforeEach(() => {
|
|
98
|
+
output = [];
|
|
99
|
+
consoleSpy = vi.spyOn(console, "log").mockImplementation((...args) => {
|
|
100
|
+
output.push(args.join(" "));
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
afterEach(() => {
|
|
104
|
+
consoleSpy.mockRestore();
|
|
105
|
+
});
|
|
106
|
+
const skippedTest = { path: "skipped", result: "skipped", errors: [], logs: [] };
|
|
107
|
+
const todoTest = { path: "todo", result: "todo", errors: [], logs: [] };
|
|
108
|
+
const passedTest = { path: "passed", result: "passed", errors: [], logs: [] };
|
|
109
|
+
const failedTest = { path: "failed", result: "failed", errors: ["err"], logs: [] };
|
|
110
|
+
it("hides skipped tests without verbose", () => {
|
|
111
|
+
const printer = new OutputPrinter({});
|
|
112
|
+
printer.printTestResult(skippedTest);
|
|
113
|
+
expect(output).toHaveLength(0);
|
|
114
|
+
});
|
|
115
|
+
it("hides todo tests without verbose", () => {
|
|
116
|
+
const printer = new OutputPrinter({});
|
|
117
|
+
printer.printTestResult(todoTest);
|
|
118
|
+
expect(output).toHaveLength(0);
|
|
119
|
+
});
|
|
120
|
+
it("shows skipped tests with verbose", () => {
|
|
121
|
+
const printer = new OutputPrinter({ verbose: true });
|
|
122
|
+
printer.printTestResult(skippedTest);
|
|
123
|
+
expect(output.some((line) => line.includes("SKIP"))).toBe(true);
|
|
124
|
+
});
|
|
125
|
+
it("shows todo tests with verbose", () => {
|
|
126
|
+
const printer = new OutputPrinter({ verbose: true });
|
|
127
|
+
printer.printTestResult(todoTest);
|
|
128
|
+
expect(output.some((line) => line.includes("TODO"))).toBe(true);
|
|
129
|
+
});
|
|
130
|
+
it("shows passed and failed tests without verbose", () => {
|
|
131
|
+
const printer = new OutputPrinter({});
|
|
132
|
+
printer.printTestResult(passedTest);
|
|
133
|
+
printer.printTestResult(failedTest);
|
|
134
|
+
expect(output.some((line) => line.includes("PASS"))).toBe(true);
|
|
135
|
+
expect(output.some((line) => line.includes("FAIL"))).toBe(true);
|
|
136
|
+
});
|
|
137
|
+
});
|
package/package.json
CHANGED
package/progress-renderer.js
CHANGED
|
@@ -24,15 +24,20 @@ export class ProgressRenderer {
|
|
|
24
24
|
}
|
|
25
25
|
handleTestFinished(test) {
|
|
26
26
|
this.currentTest = undefined;
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
if (test.result === "passed") {
|
|
28
|
+
this.ran++;
|
|
29
29
|
this.passed++;
|
|
30
|
-
|
|
30
|
+
}
|
|
31
|
+
else if (test.result === "failed") {
|
|
32
|
+
this.ran++;
|
|
31
33
|
this.failed++;
|
|
32
|
-
|
|
34
|
+
}
|
|
35
|
+
else if (test.result === "skipped") {
|
|
33
36
|
this.skipped++;
|
|
34
|
-
|
|
37
|
+
}
|
|
38
|
+
else if (test.result === "todo") {
|
|
35
39
|
this.todo++;
|
|
40
|
+
}
|
|
36
41
|
}
|
|
37
42
|
withPermanentOutput(callback) {
|
|
38
43
|
if (!this.isTTY || !this.active) {
|
|
@@ -53,7 +58,7 @@ export class ProgressRenderer {
|
|
|
53
58
|
this.active = true;
|
|
54
59
|
const percent = this.total > 0 ? Math.floor((this.ran / this.total) * 100) : 0;
|
|
55
60
|
const barWidth = 20;
|
|
56
|
-
const filled = Math.floor((percent / 100) * barWidth);
|
|
61
|
+
const filled = Math.min(barWidth, Math.floor((percent / 100) * barWidth));
|
|
57
62
|
const bar = "█".repeat(filled) + "░".repeat(barWidth - filled);
|
|
58
63
|
const counts = [
|
|
59
64
|
chalk.green(`✓${this.passed}`),
|
|
@@ -70,6 +70,29 @@ describe("ProgressRenderer", () => {
|
|
|
70
70
|
const output = vi.mocked(logUpdate).mock.calls[0][0];
|
|
71
71
|
expect(output).toContain("Running: describe > my test");
|
|
72
72
|
});
|
|
73
|
+
it("handles ran exceeding total without error", () => {
|
|
74
|
+
const renderer = new ProgressRenderer(true);
|
|
75
|
+
renderer.handleEvent({ type: "testRunStarted", total: 2 });
|
|
76
|
+
for (let i = 0; i < 5; i++) {
|
|
77
|
+
renderer.handleTestFinished({ path: `test${i}`, result: "passed", errors: [], logs: [] });
|
|
78
|
+
}
|
|
79
|
+
expect(() => {
|
|
80
|
+
renderer.handleEvent({ type: "testStarted", test: { path: "extra test" } });
|
|
81
|
+
}).not.toThrow();
|
|
82
|
+
});
|
|
83
|
+
it("does not count skipped or todo tests in ran", () => {
|
|
84
|
+
const renderer = new ProgressRenderer(true);
|
|
85
|
+
renderer.handleEvent({ type: "testRunStarted", total: 2 });
|
|
86
|
+
renderer.handleTestFinished({ path: "test1", result: "passed", errors: [], logs: [] });
|
|
87
|
+
renderer.handleTestFinished({ path: "skipped", result: "skipped", errors: [], logs: [] });
|
|
88
|
+
renderer.handleTestFinished({ path: "todo", result: "todo", errors: [], logs: [] });
|
|
89
|
+
renderer.handleTestFinished({ path: "test2", result: "failed", errors: [], logs: [] });
|
|
90
|
+
vi.mocked(logUpdate).mockClear();
|
|
91
|
+
renderer.handleEvent({ type: "testStarted", test: { path: "next" } });
|
|
92
|
+
const output = vi.mocked(logUpdate).mock.calls[0][0];
|
|
93
|
+
expect(output).toContain("2/2");
|
|
94
|
+
expect(output).toContain("100%");
|
|
95
|
+
});
|
|
73
96
|
});
|
|
74
97
|
describe("finish", () => {
|
|
75
98
|
it("clears on finish when active", () => {
|