factorio-test-cli 2.0.0 → 3.0.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/README.md +57 -0
- package/cli-error.js +6 -0
- package/cli.js +18 -7
- package/config.test.js +94 -0
- package/factorio-discovery.js +53 -0
- package/factorio-discovery.test.js +24 -0
- package/factorio-output-parser.js +41 -0
- package/factorio-output-parser.test.js +38 -0
- package/factorio-process.js +165 -0
- package/factorio-process.test.js +15 -0
- package/file-watcher.js +36 -0
- package/file-watcher.test.js +29 -0
- package/headless-save.zip +0 -0
- package/mod-setup.js +246 -0
- package/mod-setup.test.js +30 -0
- package/output-formatter.js +94 -0
- package/output-formatter.test.js +93 -0
- package/package.json +19 -7
- package/process-utils.js +27 -0
- package/progress-renderer.js +70 -0
- package/progress-renderer.test.js +88 -0
- package/results-writer.js +30 -0
- package/results-writer.test.js +89 -0
- package/run.js +176 -253
- package/schema.test.js +67 -0
- package/test-run-collector.js +92 -0
- package/test-run-collector.test.js +101 -0
- package/vitest.config.js +7 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
+
import { TestRunCollector } from "./test-run-collector.js";
|
|
3
|
+
describe("TestRunCollector", () => {
|
|
4
|
+
let collector;
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
collector = new TestRunCollector();
|
|
7
|
+
});
|
|
8
|
+
it("handles testStarted followed by testPassed", () => {
|
|
9
|
+
collector.handleEvent({ type: "testStarted", test: { path: "root > test1" } });
|
|
10
|
+
collector.handleEvent({ type: "testPassed", test: { path: "root > test1" } });
|
|
11
|
+
const data = collector.getData();
|
|
12
|
+
expect(data.tests).toHaveLength(1);
|
|
13
|
+
expect(data.tests[0].path).toBe("root > test1");
|
|
14
|
+
expect(data.tests[0].result).toBe("passed");
|
|
15
|
+
expect(data.tests[0].errors).toEqual([]);
|
|
16
|
+
expect(data.tests[0].logs).toEqual([]);
|
|
17
|
+
expect(typeof data.tests[0].durationMs).toBe("number");
|
|
18
|
+
});
|
|
19
|
+
it("handles testStarted followed by testFailed with errors", () => {
|
|
20
|
+
collector.handleEvent({ type: "testStarted", test: { path: "test" } });
|
|
21
|
+
collector.handleEvent({
|
|
22
|
+
type: "testFailed",
|
|
23
|
+
test: { path: "test" },
|
|
24
|
+
errors: ["assertion failed", "stack trace"],
|
|
25
|
+
});
|
|
26
|
+
const data = collector.getData();
|
|
27
|
+
expect(data.tests).toHaveLength(1);
|
|
28
|
+
expect(data.tests[0].result).toBe("failed");
|
|
29
|
+
expect(data.tests[0].errors).toEqual(["assertion failed", "stack trace"]);
|
|
30
|
+
});
|
|
31
|
+
it("captures logs between testStarted and result", () => {
|
|
32
|
+
collector.handleEvent({ type: "testStarted", test: { path: "test" } });
|
|
33
|
+
collector.captureLog("log line 1");
|
|
34
|
+
collector.captureLog("log line 2");
|
|
35
|
+
collector.handleEvent({ type: "testPassed", test: { path: "test" } });
|
|
36
|
+
const data = collector.getData();
|
|
37
|
+
expect(data.tests[0].logs).toEqual(["log line 1", "log line 2"]);
|
|
38
|
+
});
|
|
39
|
+
it("does not capture logs when no test is running", () => {
|
|
40
|
+
collector.captureLog("orphan log");
|
|
41
|
+
collector.handleEvent({ type: "testSkipped", test: { path: "test" } });
|
|
42
|
+
const data = collector.getData();
|
|
43
|
+
expect(data.tests[0].logs).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
it("handles testSkipped without prior testStarted", () => {
|
|
46
|
+
collector.handleEvent({ type: "testSkipped", test: { path: "skipped test" } });
|
|
47
|
+
const data = collector.getData();
|
|
48
|
+
expect(data.tests).toHaveLength(1);
|
|
49
|
+
expect(data.tests[0]).toEqual({
|
|
50
|
+
path: "skipped test",
|
|
51
|
+
source: undefined,
|
|
52
|
+
result: "skipped",
|
|
53
|
+
errors: [],
|
|
54
|
+
logs: [],
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
it("handles testTodo without prior testStarted", () => {
|
|
58
|
+
collector.handleEvent({ type: "testTodo", test: { path: "todo test" } });
|
|
59
|
+
const data = collector.getData();
|
|
60
|
+
expect(data.tests).toHaveLength(1);
|
|
61
|
+
expect(data.tests[0].result).toBe("todo");
|
|
62
|
+
});
|
|
63
|
+
it("associates logs with correct test when multiple tests run", () => {
|
|
64
|
+
collector.handleEvent({ type: "testStarted", test: { path: "test1" } });
|
|
65
|
+
collector.captureLog("test1 log");
|
|
66
|
+
collector.handleEvent({ type: "testPassed", test: { path: "test1" } });
|
|
67
|
+
collector.handleEvent({ type: "testStarted", test: { path: "test2" } });
|
|
68
|
+
collector.captureLog("test2 log");
|
|
69
|
+
collector.handleEvent({ type: "testPassed", test: { path: "test2" } });
|
|
70
|
+
const data = collector.getData();
|
|
71
|
+
expect(data.tests[0].logs).toEqual(["test1 log"]);
|
|
72
|
+
expect(data.tests[1].logs).toEqual(["test2 log"]);
|
|
73
|
+
});
|
|
74
|
+
it("stores testRunFinished summary", () => {
|
|
75
|
+
collector.handleEvent({
|
|
76
|
+
type: "testRunFinished",
|
|
77
|
+
results: {
|
|
78
|
+
ran: 5,
|
|
79
|
+
passed: 3,
|
|
80
|
+
failed: 1,
|
|
81
|
+
skipped: 1,
|
|
82
|
+
todo: 0,
|
|
83
|
+
cancelled: 0,
|
|
84
|
+
describeBlockErrors: 0,
|
|
85
|
+
status: "failed",
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
const data = collector.getData();
|
|
89
|
+
expect(data.summary?.status).toBe("failed");
|
|
90
|
+
expect(data.summary?.ran).toBe(5);
|
|
91
|
+
});
|
|
92
|
+
it("preserves source location when provided", () => {
|
|
93
|
+
collector.handleEvent({
|
|
94
|
+
type: "testStarted",
|
|
95
|
+
test: { path: "test", source: { file: "test.ts", line: 42 } },
|
|
96
|
+
});
|
|
97
|
+
collector.handleEvent({ type: "testPassed", test: { path: "test" } });
|
|
98
|
+
const data = collector.getData();
|
|
99
|
+
expect(data.tests[0].source).toEqual({ file: "test.ts", line: 42 });
|
|
100
|
+
});
|
|
101
|
+
});
|