projax 3.3.36 → 3.3.38

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.
@@ -0,0 +1,375 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const fs = __importStar(require("fs"));
37
+ const path = __importStar(require("path"));
38
+ const detector_1 = require("../detector");
39
+ // Mock fs module
40
+ jest.mock('fs');
41
+ const mockedFs = fs;
42
+ describe('detector', () => {
43
+ beforeEach(() => {
44
+ jest.clearAllMocks();
45
+ });
46
+ describe('detectTestFramework', () => {
47
+ const projectPath = '/fake/project';
48
+ const packageJsonPath = path.join(projectPath, 'package.json');
49
+ it('should detect jest from dependencies', () => {
50
+ const packageJson = {
51
+ devDependencies: {
52
+ jest: '^29.0.0',
53
+ },
54
+ };
55
+ mockedFs.existsSync.mockReturnValue(true);
56
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
57
+ const result = (0, detector_1.detectTestFramework)(projectPath);
58
+ expect(result).toBe('jest');
59
+ });
60
+ it('should detect vitest from dependencies', () => {
61
+ const packageJson = {
62
+ devDependencies: {
63
+ vitest: '^1.0.0',
64
+ },
65
+ };
66
+ mockedFs.existsSync.mockReturnValue(true);
67
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
68
+ const result = (0, detector_1.detectTestFramework)(projectPath);
69
+ expect(result).toBe('vitest');
70
+ });
71
+ it('should detect mocha from dependencies', () => {
72
+ const packageJson = {
73
+ devDependencies: {
74
+ mocha: '^10.0.0',
75
+ },
76
+ };
77
+ mockedFs.existsSync.mockReturnValue(true);
78
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
79
+ const result = (0, detector_1.detectTestFramework)(projectPath);
80
+ expect(result).toBe('mocha');
81
+ });
82
+ it('should detect jest from jest config in package.json', () => {
83
+ const packageJson = {
84
+ jest: {
85
+ preset: 'ts-jest',
86
+ },
87
+ };
88
+ mockedFs.existsSync.mockReturnValue(true);
89
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
90
+ const result = (0, detector_1.detectTestFramework)(projectPath);
91
+ expect(result).toBe('jest');
92
+ });
93
+ it('should detect jest from test script', () => {
94
+ const packageJson = {
95
+ scripts: {
96
+ test: 'jest',
97
+ },
98
+ };
99
+ mockedFs.existsSync.mockReturnValue(true);
100
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
101
+ const result = (0, detector_1.detectTestFramework)(projectPath);
102
+ expect(result).toBe('jest');
103
+ });
104
+ it('should detect framework from config files', () => {
105
+ const packageJson = {};
106
+ mockedFs.existsSync.mockImplementation((filePath) => {
107
+ const pathStr = filePath.toString();
108
+ if (pathStr === packageJsonPath)
109
+ return true;
110
+ if (pathStr === path.join(projectPath, 'jest.config.js'))
111
+ return true;
112
+ return false;
113
+ });
114
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
115
+ const result = (0, detector_1.detectTestFramework)(projectPath);
116
+ expect(result).toBe('jest');
117
+ });
118
+ it('should return null if no framework is detected', () => {
119
+ mockedFs.existsSync.mockImplementation((filePath) => {
120
+ const pathStr = filePath.toString();
121
+ return pathStr === packageJsonPath;
122
+ });
123
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify({}));
124
+ const result = (0, detector_1.detectTestFramework)(projectPath);
125
+ expect(result).toBeNull();
126
+ });
127
+ it('should handle missing package.json', () => {
128
+ mockedFs.existsSync.mockReturnValue(false);
129
+ const result = (0, detector_1.detectTestFramework)(projectPath);
130
+ expect(result).toBeNull();
131
+ });
132
+ it('should handle invalid JSON in package.json', () => {
133
+ const packageJson = {};
134
+ mockedFs.existsSync.mockImplementation((filePath) => {
135
+ const pathStr = filePath.toString();
136
+ // Return true only for package.json, false for all config files
137
+ return pathStr === packageJsonPath;
138
+ });
139
+ mockedFs.readFileSync.mockReturnValue('invalid json');
140
+ const result = (0, detector_1.detectTestFramework)(projectPath);
141
+ expect(result).toBeNull();
142
+ });
143
+ });
144
+ describe('isTestFile', () => {
145
+ it('should detect test files with .test.ts extension', () => {
146
+ expect((0, detector_1.isTestFile)('/path/to/file.test.ts')).toBe(true);
147
+ });
148
+ it('should detect test files with .spec.ts extension', () => {
149
+ expect((0, detector_1.isTestFile)('/path/to/file.spec.ts')).toBe(true);
150
+ });
151
+ it('should detect test files with .test.js extension', () => {
152
+ expect((0, detector_1.isTestFile)('/path/to/file.test.js')).toBe(true);
153
+ });
154
+ it('should detect test files with .spec.jsx extension', () => {
155
+ expect((0, detector_1.isTestFile)('/path/to/file.spec.jsx')).toBe(true);
156
+ });
157
+ it('should detect files in __tests__ directory', () => {
158
+ expect((0, detector_1.isTestFile)('/path/to/__tests__/mytest.ts')).toBe(true);
159
+ });
160
+ it('should detect files in test directory (mocha pattern)', () => {
161
+ expect((0, detector_1.isTestFile)('/path/to/test/mytest.ts')).toBe(true);
162
+ });
163
+ it('should not detect regular files', () => {
164
+ expect((0, detector_1.isTestFile)('/path/to/regular.ts')).toBe(false);
165
+ });
166
+ it('should not detect files in non-test directories', () => {
167
+ expect((0, detector_1.isTestFile)('/path/to/src/component.tsx')).toBe(false);
168
+ });
169
+ it('should detect test files when framework is specified', () => {
170
+ expect((0, detector_1.isTestFile)('/path/to/file.test.ts', 'jest')).toBe(true);
171
+ });
172
+ it('should detect files in framework-specific test directories', () => {
173
+ expect((0, detector_1.isTestFile)('/path/to/__tests__/file.ts', 'jest')).toBe(true);
174
+ });
175
+ it('should handle files with uppercase extensions', () => {
176
+ expect((0, detector_1.isTestFile)('/path/to/FILE.TEST.TS')).toBe(true);
177
+ });
178
+ });
179
+ describe('detectProjectFramework', () => {
180
+ const projectPath = '/fake/project';
181
+ const packageJsonPath = path.join(projectPath, 'package.json');
182
+ it('should detect Next.js projects', () => {
183
+ const packageJson = {
184
+ dependencies: {
185
+ next: '^14.0.0',
186
+ },
187
+ };
188
+ mockedFs.existsSync.mockReturnValue(true);
189
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
190
+ const result = (0, detector_1.detectProjectFramework)(projectPath);
191
+ expect(result).toBe('next.js');
192
+ });
193
+ it('should detect React projects', () => {
194
+ const packageJson = {
195
+ dependencies: {
196
+ react: '^18.0.0',
197
+ 'react-dom': '^18.0.0',
198
+ },
199
+ };
200
+ mockedFs.existsSync.mockReturnValue(true);
201
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
202
+ const result = (0, detector_1.detectProjectFramework)(projectPath);
203
+ expect(result).toBe('react');
204
+ });
205
+ it('should detect Vue projects', () => {
206
+ const packageJson = {
207
+ dependencies: {
208
+ vue: '^3.0.0',
209
+ },
210
+ };
211
+ mockedFs.existsSync.mockReturnValue(true);
212
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
213
+ const result = (0, detector_1.detectProjectFramework)(projectPath);
214
+ expect(result).toBe('vue 3');
215
+ });
216
+ it('should detect Angular projects', () => {
217
+ const packageJson = {
218
+ dependencies: {
219
+ '@angular/core': '^17.0.0',
220
+ },
221
+ };
222
+ mockedFs.existsSync.mockReturnValue(true);
223
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
224
+ const result = (0, detector_1.detectProjectFramework)(projectPath);
225
+ expect(result).toBe('angular');
226
+ });
227
+ it('should detect Express projects', () => {
228
+ const packageJson = {
229
+ dependencies: {
230
+ express: '^4.18.0',
231
+ },
232
+ };
233
+ mockedFs.existsSync.mockReturnValue(true);
234
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
235
+ const result = (0, detector_1.detectProjectFramework)(projectPath);
236
+ expect(result).toBe('express');
237
+ });
238
+ it('should detect NestJS projects', () => {
239
+ const packageJson = {
240
+ dependencies: {
241
+ '@nestjs/core': '^10.0.0',
242
+ },
243
+ };
244
+ mockedFs.existsSync.mockReturnValue(true);
245
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
246
+ const result = (0, detector_1.detectProjectFramework)(projectPath);
247
+ expect(result).toBe('nest.js');
248
+ });
249
+ it('should detect Electron projects', () => {
250
+ const packageJson = {
251
+ devDependencies: {
252
+ electron: '^28.0.0',
253
+ },
254
+ };
255
+ mockedFs.existsSync.mockReturnValue(true);
256
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
257
+ const result = (0, detector_1.detectProjectFramework)(projectPath);
258
+ expect(result).toBe('electron');
259
+ });
260
+ it('should detect React Native projects before React', () => {
261
+ const packageJson = {
262
+ dependencies: {
263
+ react: '^18.0.0',
264
+ 'react-native': '^0.72.0',
265
+ },
266
+ };
267
+ mockedFs.existsSync.mockReturnValue(true);
268
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
269
+ const result = (0, detector_1.detectProjectFramework)(projectPath);
270
+ expect(result).toBe('react-native');
271
+ });
272
+ it('should detect Rust projects without package.json', () => {
273
+ mockedFs.existsSync.mockImplementation((filePath) => {
274
+ const pathStr = filePath.toString();
275
+ if (pathStr === packageJsonPath)
276
+ return false;
277
+ if (pathStr === path.join(projectPath, 'Cargo.toml'))
278
+ return true;
279
+ return false;
280
+ });
281
+ const result = (0, detector_1.detectProjectFramework)(projectPath);
282
+ expect(result).toBe('rust');
283
+ });
284
+ it('should detect Go projects without package.json', () => {
285
+ mockedFs.existsSync.mockImplementation((filePath) => {
286
+ const pathStr = filePath.toString();
287
+ if (pathStr === packageJsonPath)
288
+ return false;
289
+ if (pathStr === path.join(projectPath, 'go.mod'))
290
+ return true;
291
+ return false;
292
+ });
293
+ const result = (0, detector_1.detectProjectFramework)(projectPath);
294
+ expect(result).toBe('go');
295
+ });
296
+ it('should detect Python projects without package.json', () => {
297
+ mockedFs.existsSync.mockImplementation((filePath) => {
298
+ const pathStr = filePath.toString();
299
+ if (pathStr === packageJsonPath)
300
+ return false;
301
+ if (pathStr === path.join(projectPath, 'requirements.txt'))
302
+ return true;
303
+ return false;
304
+ });
305
+ const result = (0, detector_1.detectProjectFramework)(projectPath);
306
+ expect(result).toBe('python');
307
+ });
308
+ it('should return node.js as fallback for projects with package.json', () => {
309
+ const packageJson = {
310
+ dependencies: {},
311
+ };
312
+ mockedFs.existsSync.mockReturnValue(true);
313
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
314
+ const result = (0, detector_1.detectProjectFramework)(projectPath);
315
+ expect(result).toBe('node.js');
316
+ });
317
+ it('should return null if no indicators are found', () => {
318
+ mockedFs.existsSync.mockReturnValue(false);
319
+ const result = (0, detector_1.detectProjectFramework)(projectPath);
320
+ expect(result).toBeNull();
321
+ });
322
+ it('should handle invalid JSON in package.json', () => {
323
+ mockedFs.existsSync.mockReturnValue(true);
324
+ mockedFs.readFileSync.mockReturnValue('invalid json');
325
+ const result = (0, detector_1.detectProjectFramework)(projectPath);
326
+ expect(result).toBeNull();
327
+ });
328
+ it('should prioritize Next.js over React', () => {
329
+ const packageJson = {
330
+ dependencies: {
331
+ next: '^14.0.0',
332
+ react: '^18.0.0',
333
+ },
334
+ };
335
+ mockedFs.existsSync.mockReturnValue(true);
336
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
337
+ const result = (0, detector_1.detectProjectFramework)(projectPath);
338
+ expect(result).toBe('next.js');
339
+ });
340
+ it('should detect Vite projects', () => {
341
+ const packageJson = {
342
+ devDependencies: {
343
+ vite: '^5.0.0',
344
+ },
345
+ };
346
+ mockedFs.existsSync.mockReturnValue(true);
347
+ mockedFs.readFileSync.mockReturnValue(JSON.stringify(packageJson));
348
+ const result = (0, detector_1.detectProjectFramework)(projectPath);
349
+ expect(result).toBe('vite');
350
+ });
351
+ });
352
+ describe('FRAMEWORKS constant', () => {
353
+ it('should contain jest framework definition', () => {
354
+ const jest = detector_1.FRAMEWORKS.find(f => f.name === 'jest');
355
+ expect(jest).toBeDefined();
356
+ expect(jest?.configFiles).toContain('jest.config.js');
357
+ expect(jest?.testDirs).toContain('__tests__');
358
+ });
359
+ it('should contain vitest framework definition', () => {
360
+ const vitest = detector_1.FRAMEWORKS.find(f => f.name === 'vitest');
361
+ expect(vitest).toBeDefined();
362
+ expect(vitest?.configFiles).toContain('vitest.config.ts');
363
+ });
364
+ it('should contain mocha framework definition', () => {
365
+ const mocha = detector_1.FRAMEWORKS.find(f => f.name === 'mocha');
366
+ expect(mocha).toBeDefined();
367
+ expect(mocha?.testDirs).toContain('test');
368
+ });
369
+ it('should have test patterns for all frameworks', () => {
370
+ detector_1.FRAMEWORKS.forEach(framework => {
371
+ expect(framework.testPatterns.length).toBeGreaterThan(0);
372
+ });
373
+ });
374
+ });
375
+ });
@@ -0,0 +1 @@
1
+ export {};