pi-lens 2.0.7 → 2.0.8

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 (34) hide show
  1. package/clients/ast-grep-client.test.ts +146 -116
  2. package/clients/ast-grep-client.ts +645 -551
  3. package/clients/biome-client.test.ts +154 -137
  4. package/clients/biome-client.ts +397 -337
  5. package/clients/complexity-client.test.ts +188 -200
  6. package/clients/complexity-client.ts +815 -667
  7. package/clients/dependency-checker.test.ts +55 -55
  8. package/clients/dependency-checker.ts +358 -333
  9. package/clients/go-client.test.ts +121 -111
  10. package/clients/go-client.ts +218 -216
  11. package/clients/jscpd-client.test.ts +132 -132
  12. package/clients/jscpd-client.ts +155 -118
  13. package/clients/knip-client.test.ts +123 -133
  14. package/clients/knip-client.ts +231 -218
  15. package/clients/metrics-client.test.ts +171 -167
  16. package/clients/metrics-client.ts +283 -252
  17. package/clients/ruff-client.test.ts +128 -117
  18. package/clients/ruff-client.ts +300 -269
  19. package/clients/rust-client.test.ts +104 -85
  20. package/clients/rust-client.ts +241 -234
  21. package/clients/subprocess-client.ts +1 -1
  22. package/clients/test-runner-client.test.ts +248 -215
  23. package/clients/test-runner-client.ts +728 -608
  24. package/clients/test-utils.ts +10 -3
  25. package/clients/todo-scanner.test.ts +288 -202
  26. package/clients/todo-scanner.ts +225 -187
  27. package/clients/type-coverage-client.test.ts +119 -119
  28. package/clients/type-coverage-client.ts +142 -115
  29. package/clients/types.ts +28 -28
  30. package/clients/typescript-client.test.ts +99 -93
  31. package/clients/typescript-client.ts +527 -502
  32. package/index.ts +662 -212
  33. package/package.json +1 -1
  34. package/tsconfig.json +12 -12
@@ -1,220 +1,253 @@
1
- import { describe, it, expect, beforeEach, afterEach } from "vitest";
1
+ import * as path from "node:path";
2
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
2
3
  import { TestRunnerClient } from "./test-runner-client.js";
3
4
  import { createTempFile, setupTestEnvironment } from "./test-utils.js";
4
- import * as path from "node:path";
5
5
 
6
6
  describe("TestRunnerClient", () => {
7
- let client: TestRunnerClient;
8
- let tmpDir: string;
9
- let cleanup: () => void;
10
-
11
- beforeEach(() => {
12
- client = new TestRunnerClient();
13
- ({ tmpDir, cleanup } = setupTestEnvironment("pi-lens-test-runner-"));
14
- });
15
-
16
- afterEach(() => {
17
- cleanup();
18
- });
19
-
20
- afterEach(() => {
21
- cleanup();
22
- });
23
-
24
- describe("detectRunner", () => {
25
- it("should detect vitest from config file", () => {
26
- createTempFile(tmpDir, "vitest.config.ts", "export default {}");
27
- createTempFile(tmpDir, "src/app.ts", "export const app = {};");
28
-
29
- const result = client.detectRunner(tmpDir);
30
- expect(result).not.toBeNull();
31
- expect(result!.runner).toBe("vitest");
32
- });
33
-
34
- it("should detect jest from config file", () => {
35
- createTempFile(tmpDir, "jest.config.js", "module.exports = {}");
36
- createTempFile(tmpDir, "src/app.ts", "export const app = {};");
37
-
38
- const result = client.detectRunner(tmpDir);
39
- expect(result).not.toBeNull();
40
- expect(result!.runner).toBe("jest");
41
- });
42
-
43
- it("should detect pytest from config file", () => {
44
- createTempFile(tmpDir, "pytest.ini", "[tool:pytest]");
45
- createTempFile(tmpDir, "src/app.py", "x = 1");
46
-
47
- const result = client.detectRunner(tmpDir);
48
- expect(result).not.toBeNull();
49
- expect(result!.runner).toBe("pytest");
50
- });
51
-
52
- it("should detect runner from node_modules", () => {
53
- // Create a node_modules/vitest to simulate installed package
54
- createTempFile(tmpDir, "node_modules/vitest/package.json", "{}");
55
- createTempFile(tmpDir, "src/app.ts", "export const app = {};");
56
-
57
- const result = client.detectRunner(tmpDir);
58
- // Should detect vitest from node_modules
59
- expect(result).not.toBeNull();
60
- });
61
-
62
- it("should prefer vitest over jest when both exist", () => {
63
- createTempFile(tmpDir, "vitest.config.ts", "export default {}");
64
- createTempFile(tmpDir, "jest.config.js", "module.exports = {}");
65
- createTempFile(tmpDir, "src/app.ts", "export const app = {};");
66
-
67
- const result = client.detectRunner(tmpDir);
68
- expect(result!.runner).toBe("vitest");
69
- });
70
- });
71
-
72
- describe("findTestFile", () => {
73
- it("should find test file with .test.ts suffix", () => {
74
- createTempFile(tmpDir, "vitest.config.ts", "export default {}");
75
- createTempFile(tmpDir, "src/app.ts", "export const app = {};");
76
- createTempFile(tmpDir, "src/app.test.ts", "describe('app', () => {});");
77
-
78
- const result = client.findTestFile(path.join(tmpDir, "src/app.ts"), tmpDir);
79
- expect(result).not.toBeNull();
80
- expect(result!.testFile).toContain("app.test.ts");
81
- expect(result!.runner).toBe("vitest");
82
- });
83
-
84
- it("should find test file with .spec.ts suffix", () => {
85
- createTempFile(tmpDir, "vitest.config.ts", "export default {}");
86
- createTempFile(tmpDir, "src/app.ts", "export const app = {};");
87
- createTempFile(tmpDir, "src/app.spec.ts", "describe('app', () => {});");
88
-
89
- const result = client.findTestFile(path.join(tmpDir, "src/app.ts"), tmpDir);
90
- expect(result).not.toBeNull();
91
- expect(result!.testFile).toContain("app.spec.ts");
92
- });
93
-
94
- it("should find test file in __tests__ directory", () => {
95
- createTempFile(tmpDir, "vitest.config.ts", "export default {}");
96
- createTempFile(tmpDir, "src/app.ts", "export const app = {};");
97
- createTempFile(tmpDir, "src/__tests__/app.test.ts", "describe('app', () => {});");
98
-
99
- const result = client.findTestFile(path.join(tmpDir, "src/app.ts"), tmpDir);
100
- expect(result).not.toBeNull();
101
- expect(result!.testFile).toContain("__tests__");
102
- });
103
-
104
- it("should find test file in top-level tests/ directory", () => {
105
- createTempFile(tmpDir, "vitest.config.ts", "export default {}");
106
- createTempFile(tmpDir, "src/app.ts", "export const app = {};");
107
- createTempFile(tmpDir, "tests/app.test.ts", "describe('app', () => {});");
108
-
109
- const result = client.findTestFile(path.join(tmpDir, "src/app.ts"), tmpDir);
110
- expect(result).not.toBeNull();
111
- expect(result!.testFile).toContain(path.join("tests", "app.test.ts"));
112
- });
113
-
114
- it("should find pytest test file with test_ prefix", () => {
115
- createTempFile(tmpDir, "pytest.ini", "[tool:pytest]");
116
- createTempFile(tmpDir, "src/app.py", "x = 1");
117
- createTempFile(tmpDir, "tests/test_app.py", "def test_app(): pass");
118
-
119
- const result = client.findTestFile(path.join(tmpDir, "src/app.py"), tmpDir);
120
- expect(result).not.toBeNull();
121
- expect(result!.testFile).toContain("test_app.py");
122
- expect(result!.runner).toBe("pytest");
123
- });
124
-
125
- it("should return null when no test file found", () => {
126
- createTempFile(tmpDir, "vitest.config.ts", "export default {}");
127
- createTempFile(tmpDir, "src/app.ts", "export const app = {};");
128
-
129
- const result = client.findTestFile(path.join(tmpDir, "src/app.ts"), tmpDir);
130
- expect(result).toBeNull();
131
- });
132
-
133
- it("should find test file even without config (if runner installed)", () => {
134
- // Simulate vitest installed in node_modules
135
- createTempFile(tmpDir, "node_modules/vitest/package.json", "{}");
136
- createTempFile(tmpDir, "src/app.ts", "export const app = {};");
137
- createTempFile(tmpDir, "src/app.test.ts", "describe('app', () => {});");
138
-
139
- const result = client.findTestFile(path.join(tmpDir, "src/app.ts"), tmpDir);
140
- // Should find the test file since vitest is "installed"
141
- expect(result).not.toBeNull();
142
- });
143
- });
144
-
145
- describe("formatResult", () => {
146
- it("should format passing tests", () => {
147
- const result = {
148
- file: "/test/app.test.ts",
149
- sourceFile: "/test/app.ts",
150
- runner: "vitest",
151
- passed: 5,
152
- failed: 0,
153
- skipped: 0,
154
- failures: [],
155
- duration: 420,
156
- };
157
-
158
- const formatted = client.formatResult(result);
159
- expect(formatted).toContain("");
160
- expect(formatted).toContain("5/5 passed");
161
- expect(formatted).toContain("0.42s");
162
- });
163
-
164
- it("should format failing tests", () => {
165
- const result = {
166
- file: "/test/app.test.ts",
167
- sourceFile: "/test/app.ts",
168
- runner: "vitest",
169
- passed: 3,
170
- failed: 2,
171
- skipped: 0,
172
- failures: [
173
- { name: "should add", message: "expected 4, got 3", location: "app.test.ts:10" },
174
- { name: "should subtract", message: "expected 1, got 2", location: "app.test.ts:20" },
175
- ],
176
- duration: 420,
177
- };
178
-
179
- const formatted = client.formatResult(result);
180
- expect(formatted).toContain("✗");
181
- expect(formatted).toContain("2/5 failed");
182
- expect(formatted).toContain("should add");
183
- expect(formatted).toContain("should subtract");
184
- });
185
-
186
- it("should format runner errors", () => {
187
- const result = {
188
- file: "/test/app.test.ts",
189
- sourceFile: "/test/app.ts",
190
- runner: "vitest",
191
- passed: 0,
192
- failed: 0,
193
- skipped: 0,
194
- failures: [],
195
- duration: 0,
196
- error: "Test file not found",
197
- };
198
-
199
- const formatted = client.formatResult(result);
200
- expect(formatted).toContain("");
201
- expect(formatted).toContain("Could not run tests");
202
- });
203
-
204
- it("should return empty string for no tests", () => {
205
- const result = {
206
- file: "/test/app.test.ts",
207
- sourceFile: "/test/app.ts",
208
- runner: "vitest",
209
- passed: 0,
210
- failed: 0,
211
- skipped: 0,
212
- failures: [],
213
- duration: 0,
214
- };
215
-
216
- const formatted = client.formatResult(result);
217
- expect(formatted).toBe("");
218
- });
219
- });
7
+ let client: TestRunnerClient;
8
+ let tmpDir: string;
9
+ let cleanup: () => void;
10
+
11
+ beforeEach(() => {
12
+ client = new TestRunnerClient();
13
+ ({ tmpDir, cleanup } = setupTestEnvironment("pi-lens-test-runner-"));
14
+ });
15
+
16
+ afterEach(() => {
17
+ cleanup();
18
+ });
19
+
20
+ afterEach(() => {
21
+ cleanup();
22
+ });
23
+
24
+ describe("detectRunner", () => {
25
+ it("should detect vitest from config file", () => {
26
+ createTempFile(tmpDir, "vitest.config.ts", "export default {}");
27
+ createTempFile(tmpDir, "src/app.ts", "export const app = {};");
28
+
29
+ const result = client.detectRunner(tmpDir);
30
+ expect(result).not.toBeNull();
31
+ expect(result?.runner).toBe("vitest");
32
+ });
33
+
34
+ it("should detect jest from config file", () => {
35
+ createTempFile(tmpDir, "jest.config.js", "module.exports = {}");
36
+ createTempFile(tmpDir, "src/app.ts", "export const app = {};");
37
+
38
+ const result = client.detectRunner(tmpDir);
39
+ expect(result).not.toBeNull();
40
+ expect(result?.runner).toBe("jest");
41
+ });
42
+
43
+ it("should detect pytest from config file", () => {
44
+ createTempFile(tmpDir, "pytest.ini", "[tool:pytest]");
45
+ createTempFile(tmpDir, "src/app.py", "x = 1");
46
+
47
+ const result = client.detectRunner(tmpDir);
48
+ expect(result).not.toBeNull();
49
+ expect(result?.runner).toBe("pytest");
50
+ });
51
+
52
+ it("should detect runner from node_modules", () => {
53
+ // Create a node_modules/vitest to simulate installed package
54
+ createTempFile(tmpDir, "node_modules/vitest/package.json", "{}");
55
+ createTempFile(tmpDir, "src/app.ts", "export const app = {};");
56
+
57
+ const result = client.detectRunner(tmpDir);
58
+ // Should detect vitest from node_modules
59
+ expect(result).not.toBeNull();
60
+ });
61
+
62
+ it("should prefer vitest over jest when both exist", () => {
63
+ createTempFile(tmpDir, "vitest.config.ts", "export default {}");
64
+ createTempFile(tmpDir, "jest.config.js", "module.exports = {}");
65
+ createTempFile(tmpDir, "src/app.ts", "export const app = {};");
66
+
67
+ const result = client.detectRunner(tmpDir);
68
+ expect(result?.runner).toBe("vitest");
69
+ });
70
+ });
71
+
72
+ describe("findTestFile", () => {
73
+ it("should find test file with .test.ts suffix", () => {
74
+ createTempFile(tmpDir, "vitest.config.ts", "export default {}");
75
+ createTempFile(tmpDir, "src/app.ts", "export const app = {};");
76
+ createTempFile(tmpDir, "src/app.test.ts", "describe('app', () => {});");
77
+
78
+ const result = client.findTestFile(
79
+ path.join(tmpDir, "src/app.ts"),
80
+ tmpDir,
81
+ );
82
+ expect(result).not.toBeNull();
83
+ expect(result?.testFile).toContain("app.test.ts");
84
+ expect(result?.runner).toBe("vitest");
85
+ });
86
+
87
+ it("should find test file with .spec.ts suffix", () => {
88
+ createTempFile(tmpDir, "vitest.config.ts", "export default {}");
89
+ createTempFile(tmpDir, "src/app.ts", "export const app = {};");
90
+ createTempFile(tmpDir, "src/app.spec.ts", "describe('app', () => {});");
91
+
92
+ const result = client.findTestFile(
93
+ path.join(tmpDir, "src/app.ts"),
94
+ tmpDir,
95
+ );
96
+ expect(result).not.toBeNull();
97
+ expect(result?.testFile).toContain("app.spec.ts");
98
+ });
99
+
100
+ it("should find test file in __tests__ directory", () => {
101
+ createTempFile(tmpDir, "vitest.config.ts", "export default {}");
102
+ createTempFile(tmpDir, "src/app.ts", "export const app = {};");
103
+ createTempFile(
104
+ tmpDir,
105
+ "src/__tests__/app.test.ts",
106
+ "describe('app', () => {});",
107
+ );
108
+
109
+ const result = client.findTestFile(
110
+ path.join(tmpDir, "src/app.ts"),
111
+ tmpDir,
112
+ );
113
+ expect(result).not.toBeNull();
114
+ expect(result?.testFile).toContain("__tests__");
115
+ });
116
+
117
+ it("should find test file in top-level tests/ directory", () => {
118
+ createTempFile(tmpDir, "vitest.config.ts", "export default {}");
119
+ createTempFile(tmpDir, "src/app.ts", "export const app = {};");
120
+ createTempFile(tmpDir, "tests/app.test.ts", "describe('app', () => {});");
121
+
122
+ const result = client.findTestFile(
123
+ path.join(tmpDir, "src/app.ts"),
124
+ tmpDir,
125
+ );
126
+ expect(result).not.toBeNull();
127
+ expect(result?.testFile).toContain(path.join("tests", "app.test.ts"));
128
+ });
129
+
130
+ it("should find pytest test file with test_ prefix", () => {
131
+ createTempFile(tmpDir, "pytest.ini", "[tool:pytest]");
132
+ createTempFile(tmpDir, "src/app.py", "x = 1");
133
+ createTempFile(tmpDir, "tests/test_app.py", "def test_app(): pass");
134
+
135
+ const result = client.findTestFile(
136
+ path.join(tmpDir, "src/app.py"),
137
+ tmpDir,
138
+ );
139
+ expect(result).not.toBeNull();
140
+ expect(result?.testFile).toContain("test_app.py");
141
+ expect(result?.runner).toBe("pytest");
142
+ });
143
+
144
+ it("should return null when no test file found", () => {
145
+ createTempFile(tmpDir, "vitest.config.ts", "export default {}");
146
+ createTempFile(tmpDir, "src/app.ts", "export const app = {};");
147
+
148
+ const result = client.findTestFile(
149
+ path.join(tmpDir, "src/app.ts"),
150
+ tmpDir,
151
+ );
152
+ expect(result).toBeNull();
153
+ });
154
+
155
+ it("should find test file even without config (if runner installed)", () => {
156
+ // Simulate vitest installed in node_modules
157
+ createTempFile(tmpDir, "node_modules/vitest/package.json", "{}");
158
+ createTempFile(tmpDir, "src/app.ts", "export const app = {};");
159
+ createTempFile(tmpDir, "src/app.test.ts", "describe('app', () => {});");
160
+
161
+ const result = client.findTestFile(
162
+ path.join(tmpDir, "src/app.ts"),
163
+ tmpDir,
164
+ );
165
+ // Should find the test file since vitest is "installed"
166
+ expect(result).not.toBeNull();
167
+ });
168
+ });
169
+
170
+ describe("formatResult", () => {
171
+ it("should format passing tests", () => {
172
+ const result = {
173
+ file: "/test/app.test.ts",
174
+ sourceFile: "/test/app.ts",
175
+ runner: "vitest",
176
+ passed: 5,
177
+ failed: 0,
178
+ skipped: 0,
179
+ failures: [],
180
+ duration: 420,
181
+ };
182
+
183
+ const formatted = client.formatResult(result);
184
+ expect(formatted).toContain("✓");
185
+ expect(formatted).toContain("5/5 passed");
186
+ expect(formatted).toContain("0.42s");
187
+ });
188
+
189
+ it("should format failing tests", () => {
190
+ const result = {
191
+ file: "/test/app.test.ts",
192
+ sourceFile: "/test/app.ts",
193
+ runner: "vitest",
194
+ passed: 3,
195
+ failed: 2,
196
+ skipped: 0,
197
+ failures: [
198
+ {
199
+ name: "should add",
200
+ message: "expected 4, got 3",
201
+ location: "app.test.ts:10",
202
+ },
203
+ {
204
+ name: "should subtract",
205
+ message: "expected 1, got 2",
206
+ location: "app.test.ts:20",
207
+ },
208
+ ],
209
+ duration: 420,
210
+ };
211
+
212
+ const formatted = client.formatResult(result);
213
+ expect(formatted).toContain("✗");
214
+ expect(formatted).toContain("2/5 failed");
215
+ expect(formatted).toContain("should add");
216
+ expect(formatted).toContain("should subtract");
217
+ });
218
+
219
+ it("should format runner errors", () => {
220
+ const result = {
221
+ file: "/test/app.test.ts",
222
+ sourceFile: "/test/app.ts",
223
+ runner: "vitest",
224
+ passed: 0,
225
+ failed: 0,
226
+ skipped: 0,
227
+ failures: [],
228
+ duration: 0,
229
+ error: "Test file not found",
230
+ };
231
+
232
+ const formatted = client.formatResult(result);
233
+ expect(formatted).toContain("⚠");
234
+ expect(formatted).toContain("Could not run tests");
235
+ });
236
+
237
+ it("should return empty string for no tests", () => {
238
+ const result = {
239
+ file: "/test/app.test.ts",
240
+ sourceFile: "/test/app.ts",
241
+ runner: "vitest",
242
+ passed: 0,
243
+ failed: 0,
244
+ skipped: 0,
245
+ failures: [],
246
+ duration: 0,
247
+ };
248
+
249
+ const formatted = client.formatResult(result);
250
+ expect(formatted).toBe("");
251
+ });
252
+ });
220
253
  });