mo3ta-coverage 1.3.0 → 1.3.3
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/AGENT.md +26 -4
- package/README.md +99 -3
- package/index.js +39 -4
- package/mcp/createServer.js +12 -2
- package/mcp/server.test.js +31 -1
- package/package.json +1 -1
- package/src/api.js +71 -9
- package/src/api.test.js +108 -0
- package/src/cli.js +150 -21
- package/src/cli.spawn.test.js +95 -0
- package/src/cli.test.js +225 -0
package/src/cli.test.js
CHANGED
|
@@ -6,12 +6,16 @@ import {
|
|
|
6
6
|
buildMarkdownCoverageReport,
|
|
7
7
|
classifyChangedLineCoverage,
|
|
8
8
|
dryRun,
|
|
9
|
+
filterTestFiles,
|
|
9
10
|
formatMissedLinesSummary,
|
|
10
11
|
getChangedFiles,
|
|
11
12
|
getExplicitFiles,
|
|
12
13
|
normalizeExplicitFiles,
|
|
14
|
+
parseFilter,
|
|
15
|
+
parseJestArgs,
|
|
13
16
|
parseLcov,
|
|
14
17
|
readExplicitFilesFromFile,
|
|
18
|
+
resolveTestPlan,
|
|
15
19
|
summarizeCoverageResult,
|
|
16
20
|
writeMarkdownReport
|
|
17
21
|
} from './cli.js';
|
|
@@ -238,6 +242,207 @@ describe('getExplicitFiles', () => {
|
|
|
238
242
|
});
|
|
239
243
|
});
|
|
240
244
|
|
|
245
|
+
describe('parseJestArgs', () => {
|
|
246
|
+
it('returns an empty array for no input', () => {
|
|
247
|
+
expect(parseJestArgs()).toEqual([]);
|
|
248
|
+
expect(parseJestArgs(null)).toEqual([]);
|
|
249
|
+
expect(parseJestArgs(undefined)).toEqual([]);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it('accepts a single flag string', () => {
|
|
253
|
+
expect(parseJestArgs('--silent')).toEqual(['--silent']);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('splits a comma-separated string into flags', () => {
|
|
257
|
+
expect(parseJestArgs('--maxWorkers=2,--silent')).toEqual(['--maxWorkers=2', '--silent']);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('accepts an array of flags (repeatable --jest)', () => {
|
|
261
|
+
expect(parseJestArgs(['--maxWorkers=2', '--silent'])).toEqual(['--maxWorkers=2', '--silent']);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('trims, drops empty entries, and de-duplicates preserving order', () => {
|
|
265
|
+
expect(parseJestArgs([' --silent', ' --silent', '', ' ', '--ci'])).toEqual(['--silent', '--ci']);
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe('parseFilter', () => {
|
|
270
|
+
it('returns null for no input', () => {
|
|
271
|
+
expect(parseFilter()).toBeNull();
|
|
272
|
+
expect(parseFilter(null)).toBeNull();
|
|
273
|
+
expect(parseFilter('')).toBeNull();
|
|
274
|
+
expect(parseFilter(' ')).toBeNull();
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('compiles a string pattern into a RegExp', () => {
|
|
278
|
+
const filter = parseFilter('src/__tests__/login');
|
|
279
|
+
expect(filter).toBeInstanceOf(RegExp);
|
|
280
|
+
expect(filter.test('src/__tests__/login.spec.js')).toBe(true);
|
|
281
|
+
expect(filter.test('src/auth/logout.spec.js')).toBe(false);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('trims surrounding whitespace from the pattern', () => {
|
|
285
|
+
expect(parseFilter(' login ').source).toBe('login');
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it('accepts a RegExp input and drops global/sticky flags', () => {
|
|
289
|
+
const filter = parseFilter(/login/g);
|
|
290
|
+
expect(filter.source).toBe('login');
|
|
291
|
+
expect(filter.flags).toBe('');
|
|
292
|
+
// Repeating .test() must not depend on lastIndex.
|
|
293
|
+
expect(filter.test('a/login.spec.js')).toBe(true);
|
|
294
|
+
expect(filter.test('a/login.spec.js')).toBe(true);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('throws an INVALID_FILTER error for a malformed pattern', () => {
|
|
298
|
+
expect(() => parseFilter('(unclosed')).toThrow(/Invalid filter regex/);
|
|
299
|
+
try {
|
|
300
|
+
parseFilter('(unclosed');
|
|
301
|
+
} catch (error) {
|
|
302
|
+
expect(error.code).toBe('INVALID_FILTER');
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
describe('filterTestFiles', () => {
|
|
308
|
+
it('returns a copy of the input when no filter is given', () => {
|
|
309
|
+
const files = ['src/a.test.js', 'src/b.test.js'];
|
|
310
|
+
const result = filterTestFiles(files);
|
|
311
|
+
expect(result).toEqual(files);
|
|
312
|
+
expect(result).not.toBe(files);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('keeps only the paths that match the regex', () => {
|
|
316
|
+
const files = ['src/__tests__/login.spec.js', 'src/auth/logout.spec.js', 'src/login.tsx.test.ts'];
|
|
317
|
+
const result = filterTestFiles(files, 'login');
|
|
318
|
+
expect(result).toEqual(['src/__tests__/login.spec.js', 'src/login.tsx.test.ts']);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('supports a RegExp instance as the filter', () => {
|
|
322
|
+
const files = ['src/foo.test.js', 'src/bar.test.js'];
|
|
323
|
+
const result = filterTestFiles(files, /foo/);
|
|
324
|
+
expect(result).toEqual(['src/foo.test.js']);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
describe('resolveTestPlan spec filter', () => {
|
|
329
|
+
let tempDir;
|
|
330
|
+
let originalCwd;
|
|
331
|
+
|
|
332
|
+
beforeEach(() => {
|
|
333
|
+
originalCwd = process.cwd();
|
|
334
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mo3ta-filter-plan-'));
|
|
335
|
+
fs.mkdirSync(path.join(tempDir, 'src'), { recursive: true });
|
|
336
|
+
fs.writeFileSync(path.join(tempDir, 'src', 'example.js'), 'export const example = 1;\n');
|
|
337
|
+
fs.writeFileSync(
|
|
338
|
+
path.join(tempDir, 'src', 'example.test.js'),
|
|
339
|
+
"import { example } from './example';\n\ntest('naming match', () => expect(example).toBe(1));\n"
|
|
340
|
+
);
|
|
341
|
+
fs.mkdirSync(path.join(tempDir, 'specs'), { recursive: true });
|
|
342
|
+
fs.writeFileSync(
|
|
343
|
+
path.join(tempDir, 'specs', 'custom-name.spec.js'),
|
|
344
|
+
"import { example } from '../src/example';\n\ntest('import match', () => expect(example).toBe(1));\n"
|
|
345
|
+
);
|
|
346
|
+
process.chdir(tempDir);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
afterEach(() => {
|
|
350
|
+
process.chdir(originalCwd);
|
|
351
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it('filters selected tests and keeps the pre-filter list for validation', () => {
|
|
355
|
+
const plan = resolveTestPlan(['src/example.js'], 'smart', 2, tempDir, [], 'specs\\/');
|
|
356
|
+
|
|
357
|
+
expect(plan.filter).toBe('specs\\/');
|
|
358
|
+
expect(plan.allTestsToRun).toEqual(['specs/custom-name.spec.js', 'src/example.test.js']);
|
|
359
|
+
expect(plan.testsToRun).toEqual(['specs/custom-name.spec.js']);
|
|
360
|
+
expect(plan.jestTargets).toEqual(['specs/custom-name.spec.js']);
|
|
361
|
+
expect(plan.jestArgs).toEqual(['--passWithNoTests', '--coverage', 'specs/custom-name.spec.js']);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it('removes test files when the filter matches none', () => {
|
|
365
|
+
const plan = resolveTestPlan(['src/example.js'], 'smart', 2, tempDir, [], 'not-a-match');
|
|
366
|
+
|
|
367
|
+
expect(plan.allTestsToRun).toEqual(['specs/custom-name.spec.js', 'src/example.test.js']);
|
|
368
|
+
expect(plan.testsToRun).toEqual([]);
|
|
369
|
+
expect(plan.jestArgs).toEqual(['--passWithNoTests', '--coverage']);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it('keeps the per-source "allTests" for the validation log when the filter drops everything', () => {
|
|
373
|
+
const plan = resolveTestPlan(['src/example.js'], 'smart', 2, tempDir, [], 'not-a-match');
|
|
374
|
+
|
|
375
|
+
plan.mappings.forEach(mapping => {
|
|
376
|
+
expect(mapping.tests).toEqual([]);
|
|
377
|
+
expect(mapping.allTests).toEqual(['specs/custom-name.spec.js', 'src/example.test.js']);
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it('leaves the plan untouched when no filter is given', () => {
|
|
382
|
+
const plan = resolveTestPlan(['src/example.js'], 'smart', 2, tempDir);
|
|
383
|
+
|
|
384
|
+
expect(plan.filter).toBeNull();
|
|
385
|
+
expect(plan.allTestsToRun).toEqual(['specs/custom-name.spec.js', 'src/example.test.js']);
|
|
386
|
+
expect(plan.testsToRun).toEqual(['specs/custom-name.spec.js', 'src/example.test.js']);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it('forwards the filter to Jest via --testPathPatterns in full mode', () => {
|
|
390
|
+
const plan = resolveTestPlan(
|
|
391
|
+
['src/example.js', 'src/example.test.js'],
|
|
392
|
+
'full',
|
|
393
|
+
2,
|
|
394
|
+
tempDir,
|
|
395
|
+
[],
|
|
396
|
+
'example'
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
expect(plan.delegatedToJest).toBe(true);
|
|
400
|
+
expect(plan.allTestsToRun).toEqual(['src/example.test.js']);
|
|
401
|
+
expect(plan.testsToRun).toEqual(['src/example.test.js']);
|
|
402
|
+
expect(plan.jestTargets).toEqual(['src/example.js', 'src/example.test.js']);
|
|
403
|
+
expect(plan.jestArgs).toContain('--findRelatedTests');
|
|
404
|
+
expect(plan.jestArgs).toContain('--testPathPatterns');
|
|
405
|
+
expect(plan.jestArgs).toContain('example');
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
it('does not duplicate a Jest path pattern the caller already set in full mode', () => {
|
|
409
|
+
const plan = resolveTestPlan(
|
|
410
|
+
['src/example.js'],
|
|
411
|
+
'full',
|
|
412
|
+
2,
|
|
413
|
+
tempDir,
|
|
414
|
+
['--testPathPatterns=login'],
|
|
415
|
+
'example'
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
expect(plan.jestArgs).toContain('--testPathPatterns=login');
|
|
419
|
+
expect(plan.jestArgs).not.toContain('--testPathPatterns');
|
|
420
|
+
expect(plan.jestArgs.filter(arg => arg.startsWith('--testPathPatterns'))).toEqual(
|
|
421
|
+
['--testPathPatterns=login']
|
|
422
|
+
);
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
describe('resolveTestPlan jest flags', () => {
|
|
427
|
+
it('appends extra flags to fast mode jestArgs after the test files', () => {
|
|
428
|
+
const plan = resolveTestPlan(['src/example.test.js'], 'fast', 2, process.cwd(), ['--maxWorkers=2', '--silent']);
|
|
429
|
+
|
|
430
|
+
expect(plan.jestArgs).toEqual(['--passWithNoTests', '--coverage', 'src/example.test.js', '--maxWorkers=2', '--silent']);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it('appends extra flags to full mode jestArgs after the targets', () => {
|
|
434
|
+
const plan = resolveTestPlan(['src/example.js', 'src/example.test.js'], 'full', 2, process.cwd(), ['--silent']);
|
|
435
|
+
|
|
436
|
+
expect(plan.jestArgs).toEqual(['--findRelatedTests', '--passWithNoTests', '--coverage', 'src/example.js', 'src/example.test.js', '--silent']);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it('omits extra flags when none are provided', () => {
|
|
440
|
+
const plan = resolveTestPlan(['src/example.test.js'], 'fast', 2, process.cwd());
|
|
441
|
+
|
|
442
|
+
expect(plan.jestArgs).toEqual(['--passWithNoTests', '--coverage', 'src/example.test.js']);
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
|
|
241
446
|
describe('getChangedFiles', () => {
|
|
242
447
|
let tempDir;
|
|
243
448
|
let originalCwd;
|
|
@@ -381,4 +586,24 @@ describe('dryRun', () => {
|
|
|
381
586
|
expect(stdoutLines).toEqual(['src/example.test.js']);
|
|
382
587
|
expect(stderrLines.some(line => line.includes('--findRelatedTests'))).toBe(true);
|
|
383
588
|
});
|
|
589
|
+
|
|
590
|
+
it('prints the before/after filter log on stderr and only filtered paths on stdout', () => {
|
|
591
|
+
expect(() => dryRun(['src/example.js'], 'smart', 2, 'example\\.test\\.js$')).toThrow(/^exit:/);
|
|
592
|
+
|
|
593
|
+
// The changed file's naming-match test survives the filter; the import-scan
|
|
594
|
+
// spec does not.
|
|
595
|
+
expect(stdoutLines).toEqual(['src/example.test.js']);
|
|
596
|
+
expect(stderrLines.some(line => line.includes('Filter regex'))).toBe(true);
|
|
597
|
+
expect(stderrLines.some(line => line.includes('specs/custom-name.spec.js'))).toBe(true);
|
|
598
|
+
expect(stderrLines.some(line => line.includes('src/example.test.js'))).toBe(true);
|
|
599
|
+
expect(exitSpy).toHaveBeenCalledWith(0);
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
it('prints nothing on stdout when the filter matches no test file', () => {
|
|
603
|
+
expect(() => dryRun(['src/example.js'], 'smart', 2, 'zzz-no-match')).toThrow(/^exit:/);
|
|
604
|
+
|
|
605
|
+
expect(stdoutLines).toEqual([]);
|
|
606
|
+
expect(stderrLines.some(line => line.includes('after filter (0)'))).toBe(true);
|
|
607
|
+
expect(exitSpy).toHaveBeenCalledWith(0);
|
|
608
|
+
});
|
|
384
609
|
});
|