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/src/api.test.js CHANGED
@@ -3,6 +3,7 @@ import os from 'os';
3
3
  import path from 'path';
4
4
  import { execSync } from 'child_process';
5
5
  import {
6
+ buildCapturedJestArgs,
6
7
  checkChangedLineCoverage,
7
8
  listChangedFiles,
8
9
  mapRelatedTests,
@@ -59,6 +60,18 @@ describe('programmatic coverage API', () => {
59
60
  root = undefined;
60
61
  });
61
62
 
63
+ it('adds --runInBand by default for captured runs', () => {
64
+ expect(buildCapturedJestArgs(['--coverage'])).toEqual(['--coverage', '--watchAll=false', '--runInBand']);
65
+ });
66
+
67
+ it('drops --runInBand when the caller sets a worker strategy', () => {
68
+ expect(buildCapturedJestArgs(['--maxWorkers=2'])).toEqual(['--maxWorkers=2', '--watchAll=false']);
69
+ expect(buildCapturedJestArgs(['--maxWorkers', '2'])).toEqual(['--maxWorkers', '2', '--watchAll=false']);
70
+ expect(buildCapturedJestArgs(['-w', '2'])).toEqual(['-w', '2', '--watchAll=false']);
71
+ expect(buildCapturedJestArgs(['--runInBand'])).toEqual(['--runInBand', '--watchAll=false']);
72
+ expect(buildCapturedJestArgs(['-i'])).toEqual(['-i', '--watchAll=false']);
73
+ });
74
+
62
75
  it('rejects a directory that is not a git repo', () => {
63
76
  root = fs.mkdtempSync(path.join(os.tmpdir(), 'mo3ta-not-git-'));
64
77
  expect(() => listChangedFiles({ root, useConfig: false })).toThrow(Mo3taError);
@@ -176,6 +189,47 @@ describe('programmatic coverage API', () => {
176
189
  expect(override.mode).toBe('full');
177
190
  });
178
191
 
192
+ it('accepts extra Jest flags and reads a jest default from the config file', () => {
193
+ root = initRepo('mo3ta-jest-config-');
194
+ writeMathFeature(root);
195
+ const source = path.join(root, 'src', 'math.js');
196
+ const lcov = path.join(root, 'coverage', 'lcov.info');
197
+ fs.mkdirSync(path.dirname(lcov), { recursive: true });
198
+ fs.writeFileSync(lcov, ['TN:', `SF:${source}`, 'DA:2,1', 'end_of_record', ''].join('\n'));
199
+
200
+ const explicit = checkChangedLineCoverage({
201
+ root,
202
+ base: 'main',
203
+ files: ['src/math.js'],
204
+ mode: 'fast',
205
+ runTests: false,
206
+ jest: ['--maxWorkers=2', '--silent'],
207
+ useConfig: false
208
+ });
209
+ expect(explicit.jestArgs).toEqual(['--maxWorkers=2', '--silent']);
210
+
211
+ fs.writeFileSync(path.join(root, '.mo3ta-coverage.json'), JSON.stringify({
212
+ base: 'main',
213
+ mode: 'fast',
214
+ jest: ['--bail']
215
+ }));
216
+
217
+ const fromConfig = checkChangedLineCoverage({
218
+ root,
219
+ files: ['src/math.js'],
220
+ runTests: false
221
+ });
222
+ expect(fromConfig.jestArgs).toEqual(['--bail']);
223
+
224
+ const override = checkChangedLineCoverage({
225
+ root,
226
+ files: ['src/math.js'],
227
+ runTests: false,
228
+ jest: '--maxWorkers=1,--silent'
229
+ });
230
+ expect(override.jestArgs).toEqual(['--maxWorkers=1', '--silent']);
231
+ });
232
+
179
233
  it('reports an invalid config file instead of throwing a raw parse error', () => {
180
234
  root = initRepo('mo3ta-bad-config-');
181
235
  fs.writeFileSync(path.join(root, '.mo3ta-coverage.json'), '{');
@@ -319,4 +373,58 @@ describe('programmatic coverage API', () => {
319
373
  expect(error.code).toBe('INVALID_LIMIT');
320
374
  }
321
375
  });
376
+
377
+ it('narrowing tests with a filter keeps the pre-filter list for validation', () => {
378
+ root = initRepo('mo3ta-filter-');
379
+ writeMathFeature(root);
380
+
381
+ const result = mapRelatedTests({
382
+ root,
383
+ base: 'main',
384
+ files: ['src/math.js', 'src/bare.js'],
385
+ mode: 'smart',
386
+ filter: 'math',
387
+ useConfig: false
388
+ });
389
+
390
+ expect(result.filter).toBe('math');
391
+ expect(result.allTestsToRun).toEqual(expect.arrayContaining([
392
+ 'src/math.test.js',
393
+ 'specs/custom-name.spec.js'
394
+ ]));
395
+ expect(result.allTestsToRun).toHaveLength(2);
396
+ expect(result.testsToRun).toEqual(['src/math.test.js']);
397
+ expect(result.summary).toContain('Filter /math/ kept 1 of 2 candidate test file(s).');
398
+ });
399
+
400
+ it('accepts a filter default from .mo3ta-coverage.json and overrides it explicitly', () => {
401
+ root = initRepo('mo3ta-filter-config-');
402
+ writeMathFeature(root);
403
+ fs.writeFileSync(path.join(root, '.mo3ta-coverage.json'), JSON.stringify({
404
+ base: 'main',
405
+ mode: 'smart',
406
+ filter: 'specs/'
407
+ }));
408
+
409
+ const fromConfig = mapRelatedTests({ root, files: ['src/math.js'] });
410
+ expect(fromConfig.filter).toBe('specs\\/');
411
+ expect(fromConfig.testsToRun).toEqual([]);
412
+
413
+ const override = mapRelatedTests({ root, files: ['src/math.js'], filter: 'math' });
414
+ expect(override.filter).toBe('math');
415
+ expect(override.testsToRun).toEqual(['src/math.test.js']);
416
+ });
417
+
418
+ it('fails fast on an invalid filter regex before running anything', () => {
419
+ root = initRepo('mo3ta-bad-filter-');
420
+ writeMathFeature(root);
421
+
422
+ expect(() => mapRelatedTests({ root, base: 'main', files: ['src/math.js'], filter: '(unclosed', useConfig: false })).toThrow(Mo3taError);
423
+ try {
424
+ mapRelatedTests({ root, base: 'main', files: ['src/math.js'], filter: '(unclosed', useConfig: false });
425
+ } catch (error) {
426
+ expect(error.code).toBe('INVALID_FILTER');
427
+ expect(error.hint).toMatch(/regular expression/i);
428
+ }
429
+ });
322
430
  });
package/src/cli.js CHANGED
@@ -34,12 +34,14 @@ export function main(options) {
34
34
  const CI_REPORT_PATH = options.ciReport
35
35
  ? path.resolve(options.ciReport)
36
36
  : path.resolve('coverage', 'mo3ta-coverage-report.md');
37
+ const JEST_FLAGS = parseJestArgs(options.jest);
38
+ const FILTER = parseFilter(options.filter);
37
39
 
38
40
  // In dry run, stdout must stay a clean one-path-per-line list, so
39
41
  // diagnostics go to stderr instead of stdout.
40
42
  const infoLog = DRY_RUN ? console.error : console.log;
41
43
 
42
- infoLog(`Options:\nBase Branch: ${BASE_BRANCH} \nLCOV Path: ${LCOV_PATH} \nCoverage Limit: ${COVERAGE_LIMIT} \nShow Covered Lines: ${SHOW_COVERED} \nMode: ${MODE} \nDepth: ${DEPTH} \nDry Run: ${DRY_RUN} \nCI Mode: ${CI}`);
44
+ infoLog(`Options:\nBase Branch: ${BASE_BRANCH} \nLCOV Path: ${LCOV_PATH} \nCoverage Limit: ${COVERAGE_LIMIT} \nShow Covered Lines: ${SHOW_COVERED} \nMode: ${MODE} \nDepth: ${DEPTH} \nDry Run: ${DRY_RUN} \nCI Mode: ${CI} \nJest Flags: ${JEST_FLAGS.length ? JEST_FLAGS.join(' ') : '(none)'} \nFilter: ${FILTER ? FILTER.source : '(none)'}`);
43
45
 
44
46
  const explicitFiles = getExplicitFiles(options);
45
47
  let changedFiles;
@@ -54,11 +56,11 @@ export function main(options) {
54
56
  }
55
57
 
56
58
  if (DRY_RUN) {
57
- dryRun(changedFiles, MODE, DEPTH);
59
+ dryRun(changedFiles, MODE, DEPTH, FILTER);
58
60
  return;
59
61
  }
60
62
 
61
- runRelatedTests(changedFiles, MODE, DEPTH);
63
+ runRelatedTests(changedFiles, MODE, DEPTH, JEST_FLAGS, FILTER);
62
64
  reportUncoveredChangedLines(changedFiles, LCOV_PATH, BASE_BRANCH, COVERAGE_LIMIT, SHOW_COVERED, CI, CI_REPORT_PATH);
63
65
 
64
66
  if (testsFailed) {
@@ -66,7 +68,11 @@ export function main(options) {
66
68
  exit(1);
67
69
  }
68
70
  } catch (error) {
69
- console.error('❌ An unexpected error occurred:', error.message || error);
71
+ if (error.code === 'INVALID_FILTER') {
72
+ console.error(`❌ ${error.message}`);
73
+ } else {
74
+ console.error('❌ An unexpected error occurred:', error.message || error);
75
+ }
70
76
  exit(1);
71
77
  }
72
78
  }
@@ -134,6 +140,67 @@ export function getExplicitFiles(options = {}, root = process.cwd()) {
134
140
  return Array.from(new Set(files));
135
141
  }
136
142
 
143
+ /**
144
+ * Normalizes user-provided extra Jest CLI flags into an argument array.
145
+ * Accepts a single value, a comma-separated string, or an array (the CLI's
146
+ * repeatable `--jest` option collects each flag as its own entry). Each flag
147
+ * is trimmed, empty entries dropped, and duplicates removed preserving order.
148
+ *
149
+ * Values may start with `--` (they are Jest flags, e.g. `--maxWorkers=2`).
150
+ * @param {string|string[]} [input]
151
+ * @returns {string[]}
152
+ */
153
+ export function parseJestArgs(input) {
154
+ if (input === undefined || input === null) return [];
155
+
156
+ const values = Array.isArray(input) ? input : [input];
157
+
158
+ return values
159
+ .flatMap(value => String(value ?? '').split(','))
160
+ .map(flag => flag.trim())
161
+ .filter(flag => flag.length > 0)
162
+ .filter((flag, index, all) => all.indexOf(flag) === index);
163
+ }
164
+
165
+ /**
166
+ * Compiles a user-provided spec filter into a RegExp. Returns null when the
167
+ * filter is empty. Global/sticky flags are dropped so repeated `.test()` calls
168
+ * do not depend on `lastIndex`.
169
+ * @param {string|RegExp} [input]
170
+ * @returns {RegExp|null}
171
+ */
172
+ export function parseFilter(input) {
173
+ if (input === undefined || input === null) return null;
174
+
175
+ if (input instanceof RegExp) {
176
+ return new RegExp(input.source, input.flags.replace(/[gy]/g, ''));
177
+ }
178
+
179
+ const pattern = String(input).trim();
180
+ if (pattern === '') return null;
181
+
182
+ try {
183
+ return new RegExp(pattern);
184
+ } catch (error) {
185
+ const invalid = new Error(`Invalid filter regex "${pattern}": ${error.message}`);
186
+ invalid.code = 'INVALID_FILTER';
187
+ throw invalid;
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Keeps the test file paths that match a user-provided regex. An empty filter
193
+ * returns a copy of the input unchanged.
194
+ * @param {string[]} files
195
+ * @param {string|RegExp|null} [filter]
196
+ * @returns {string[]}
197
+ */
198
+ export function filterTestFiles(files, filter) {
199
+ const regex = parseFilter(filter);
200
+ if (!regex) return [...files];
201
+ return files.filter(file => regex.test(file));
202
+ }
203
+
137
204
  /**
138
205
  * Lists changed JS/TS files vs `baseBranch` without logging or exiting.
139
206
  * Includes commits from every author since the merge base, plus staged and
@@ -219,28 +286,44 @@ function runJest(jestArgs) {
219
286
 
220
287
  /**
221
288
  * Resolves the test files a mode would run, without logging, running Jest, or exiting.
222
- * `testsToRun` keeps CLI insertion order (changed tests first, then matches).
289
+ * `testsToRun` keeps CLI insertion order (changed tests first, then matches) and
290
+ * is filtered by `filter` when provided. `allTestsToRun` keeps the unfiltered
291
+ * list so callers can log both and let the user validate the filter.
223
292
  * Full mode cannot discover related tests without Jest; `testsToRun` is then
224
293
  * only the changed test files, and `jestTargets` is what `--findRelatedTests` receives.
225
294
  * @param {string[]} files
226
295
  * @param {string} mode
227
296
  * @param {number} [depth]
228
297
  * @param {string} [root]
298
+ * @param {string[]} [jestArgs] extra Jest CLI flags to append (e.g. `--maxWorkers=2`)
299
+ * @param {string|RegExp|null} [filter] regex matched against the final test paths
229
300
  */
230
- export function resolveTestPlan(files, mode, depth = 2, root = process.cwd()) {
301
+ export function resolveTestPlan(files, mode, depth = 2, root = process.cwd(), jestArgs = [], filter = null) {
231
302
  const { sourceFiles, testFiles } = separateSourceAndTestFiles(files);
303
+ const filterRegex = parseFilter(filter);
304
+ const extra = parseJestArgs(jestArgs);
232
305
 
233
306
  if (mode === 'full') {
234
- const jestTargets = [...sourceFiles, ...testFiles];
307
+ const allTestsToRun = [...testFiles];
308
+ const testsToRun = filterTestFiles(allTestsToRun, filterRegex);
309
+ const jestTargets = [...sourceFiles, ...testsToRun];
310
+ // Jest discovers the related specs itself in full mode, so the filter must
311
+ // also reach Jest. Modern Jest spells the option in the plural.
312
+ const fullExtra = filterRegex && !hasJestPathPattern(extra)
313
+ ? [...extra, '--testPathPatterns', filterRegex.source]
314
+ : extra;
315
+
235
316
  return {
236
317
  mode,
237
318
  depth,
319
+ filter: filterRegex ? filterRegex.source : null,
238
320
  sourceFiles,
239
321
  testFiles,
240
322
  mappings: [],
241
- testsToRun: [...testFiles],
323
+ allTestsToRun,
324
+ testsToRun,
242
325
  jestTargets,
243
- jestArgs: ['--findRelatedTests', '--passWithNoTests', '--coverage', ...jestTargets],
326
+ jestArgs: ['--findRelatedTests', '--passWithNoTests', '--coverage', ...jestTargets, ...fullExtra],
244
327
  delegatedToJest: true
245
328
  };
246
329
  }
@@ -248,6 +331,7 @@ export function resolveTestPlan(files, mode, depth = 2, root = process.cwd()) {
248
331
  // Fast: naming-convention mapping with a direct-import fallback.
249
332
  // Smart: naming-convention mapping plus a depth-limited reverse-dependency walk.
250
333
  const testFilesToRun = new Set(testFiles);
334
+ const allTestFilesToRun = new Set(testFiles);
251
335
  const mappings = [];
252
336
 
253
337
  sourceFiles.forEach(sourceFile => {
@@ -269,29 +353,64 @@ export function resolveTestPlan(files, mode, depth = 2, root = process.cwd()) {
269
353
  }
270
354
  }
271
355
 
356
+ const filteredTests = filterTestFiles(relatedTests, filterRegex);
272
357
  mappings.push({
273
358
  source: sourceFile,
274
- tests: [...relatedTests],
359
+ tests: filteredTests,
360
+ allTests: [...relatedTests],
275
361
  matchType
276
362
  });
277
- relatedTests.forEach(test => testFilesToRun.add(test));
363
+ relatedTests.forEach(test => allTestFilesToRun.add(test));
364
+ filteredTests.forEach(test => testFilesToRun.add(test));
278
365
  });
279
366
 
280
- const testsToRun = Array.from(testFilesToRun);
367
+ const allTestsToRun = Array.from(allTestFilesToRun);
368
+ const testsToRun = filterTestFiles(allTestsToRun, filterRegex);
281
369
  return {
282
370
  mode,
283
371
  depth,
372
+ filter: filterRegex ? filterRegex.source : null,
284
373
  sourceFiles,
285
374
  testFiles,
286
375
  mappings,
376
+ allTestsToRun,
287
377
  testsToRun,
288
378
  jestTargets: testsToRun,
289
- jestArgs: ['--passWithNoTests', '--coverage', ...testsToRun],
379
+ jestArgs: ['--passWithNoTests', '--coverage', ...testsToRun, ...extra],
290
380
  delegatedToJest: false
291
381
  };
292
382
  }
293
383
 
294
- function runRelatedTests(files, mode, depth = 2) {
384
+ function hasJestPathPattern(jestArgs) {
385
+ return jestArgs.some(arg =>
386
+ arg === '--testPathPatterns' ||
387
+ arg.startsWith('--testPathPatterns=') ||
388
+ arg === '--testPathPattern' ||
389
+ arg.startsWith('--testPathPattern=')
390
+ );
391
+ }
392
+
393
+ /**
394
+ * Logs the full candidate list and the filtered list so the user can validate
395
+ * the regex before any tests run.
396
+ * @param {ReturnType<typeof resolveTestPlan>} plan
397
+ * @param {(...args: any[]) => void} [log]
398
+ */
399
+ function logFilteredTestFiles(plan, log = console.log) {
400
+ if (!plan.filter) return;
401
+
402
+ log(`\n🔎 Filter regex: /${plan.filter}/`);
403
+ log(` All test files before filter (${plan.allTestsToRun.length}):`);
404
+ plan.allTestsToRun.forEach(file => log(` - ${file}`));
405
+ log(` Test files after filter (${plan.testsToRun.length}):`);
406
+ if (plan.testsToRun.length === 0) {
407
+ log(' (none)');
408
+ } else {
409
+ plan.testsToRun.forEach(file => log(` - ${file}`));
410
+ }
411
+ }
412
+
413
+ function runRelatedTests(files, mode, depth = 2, jestArgs = [], filter = null) {
295
414
  if (files.length === 0) {
296
415
  console.log('✅ No changed source files found.');
297
416
  exit(0);
@@ -299,7 +418,7 @@ function runRelatedTests(files, mode, depth = 2) {
299
418
 
300
419
  console.log('🔍 Analyzing changed files for optimal test execution...');
301
420
 
302
- const plan = resolveTestPlan(files, mode, depth);
421
+ const plan = resolveTestPlan(files, mode, depth, process.cwd(), jestArgs, filter);
303
422
  const { sourceFiles, testFiles } = plan;
304
423
 
305
424
  console.log(`\n📊 Changed files breakdown:`);
@@ -314,6 +433,8 @@ function runRelatedTests(files, mode, depth = 2) {
314
433
  testFiles.forEach(file => console.log(` - ${file}`));
315
434
  }
316
435
 
436
+ logFilteredTestFiles(plan);
437
+
317
438
  // Full mode delegates discovery to Jest, so pass the changed files themselves.
318
439
  if (mode === 'full') {
319
440
  const jestTargets = plan.jestTargets;
@@ -324,7 +445,7 @@ function runRelatedTests(files, mode, depth = 2) {
324
445
  }
325
446
 
326
447
  console.log(`\n📝 Test strategy: full (Jest --findRelatedTests, unbounded traversal)`);
327
- console.log(` Running tests related to ${sourceFiles.length} source file(s) + ${testFiles.length} changed test(s)`);
448
+ console.log(` Running tests related to ${sourceFiles.length} source file(s) + ${plan.testsToRun.length} changed test(s)`);
328
449
  console.log(` ⚠️ If this expands to too many tests, switch to --mode smart`);
329
450
  console.log(' Files passed to Jest:');
330
451
  jestTargets.forEach(file => console.log(` - ${file}`));
@@ -333,9 +454,11 @@ function runRelatedTests(files, mode, depth = 2) {
333
454
  return;
334
455
  }
335
456
 
336
- plan.mappings.forEach(({ source, tests, matchType }) => {
457
+ plan.mappings.forEach(({ source, tests, allTests, matchType }) => {
337
458
  if (tests.length > 0) {
338
459
  console.log(` ✓ ${source} → ${tests.length} test file(s) (${matchType})`);
460
+ } else if (allTests.length > 0) {
461
+ console.log(` ⚠ ${source} → No test file after filter (${allTests.length} matched before filter)`);
339
462
  } else {
340
463
  console.log(` ⚠ ${source} → No test file found`);
341
464
  }
@@ -371,30 +494,36 @@ function runRelatedTests(files, mode, depth = 2) {
371
494
  * then print one path per line and exit without running Jest or checking
372
495
  * coverage. The stdout is clean enough for another tool to consume:
373
496
  * node index.js --dryRun true --files src/a.js --base origin/main
497
+ * When a filter is given, the before/after filter log goes to stderr so
498
+ * stdout stays a clean one-path-per-line list.
374
499
  * Errors still go to stderr via the catch in main().
375
500
  *
376
501
  * @param {string[]} files - Changed source and test files (repo-relative)
377
502
  * @param {string} mode - Execution mode (fast, smart, or full)
378
503
  * @param {number} depth - Max reverse-dependency depth for smart mode
504
+ * @param {string|RegExp|null} [filter] regex matched against the final test paths
379
505
  */
380
- export function dryRun(files, mode, depth = 2) {
506
+ export function dryRun(files, mode, depth = 2, filter = null) {
381
507
  if (files.length === 0) {
382
508
  // Keep stdout a clean file list; informational messages go to stderr.
383
509
  console.error('✅ No changed source files found.');
384
510
  exit(0);
385
511
  }
386
512
 
387
- const plan = resolveTestPlan(files, mode, depth);
513
+ const plan = resolveTestPlan(files, mode, depth, process.cwd(), [], filter);
514
+
515
+ // Filter diagnostics stay on stderr so stdout remains a clean list.
516
+ logFilteredTestFiles(plan, console.error);
388
517
 
389
518
  // Full mode delegates discovery to Jest; without running it, the only
390
519
  // guaranteed output is the changed test files themselves.
391
520
  if (mode === 'full') {
392
521
  // Keep stdout clean (one path per line) for other tools; warn on stderr.
393
522
  console.error('⚠️ full mode relies on Jest --findRelatedTests; --dry-run prints only the changed test files.');
394
- plan.testFiles.forEach(file => console.log(file));
395
- exit(0);
396
523
  }
397
524
 
525
+ // In full mode testsToRun is the changed test files (already filtered),
526
+ // which is the same as plan.testFiles when no filter is given.
398
527
  [...plan.testsToRun].sort().forEach(file => console.log(file));
399
528
  exit(0);
400
529
  }
@@ -35,6 +35,101 @@ describe('CLI process behavior', () => {
35
35
  expect(result.stdout).not.toContain('--dry-run');
36
36
  });
37
37
 
38
+ it('lists the --jest option in help', () => {
39
+ const result = runCli(root, ['--help']);
40
+
41
+ expect(result.status).toBe(0);
42
+ expect(result.stdout).toContain('--jest <value>');
43
+ });
44
+
45
+ it('lists the --filter option in help', () => {
46
+ const result = runCli(root, ['--help']);
47
+
48
+ expect(result.status).toBe(0);
49
+ expect(result.stdout).toContain('--filter <regex>');
50
+ });
51
+
52
+ it('keeps only matching spec files in a dry run and logs both lists', () => {
53
+ git(root, 'git init -b main -q');
54
+ git(root, 'git config user.email test@example.com');
55
+ git(root, 'git config user.name Test');
56
+ fs.mkdirSync(path.join(root, 'src'));
57
+ fs.writeFileSync(path.join(root, 'src', 'a.js'), 'module.exports = 1;\n');
58
+ fs.writeFileSync(path.join(root, 'src', 'a.test.js'), 'test("a", () => expect(1).toBe(1));\n');
59
+ git(root, 'git add -A && git commit -q -m init');
60
+
61
+ const result = runCli(root, ['--dryRun', 'true', '--files', 'src/a.js', '--base', 'main', '--mode', 'fast', '--filter', 'does-not-match']);
62
+
63
+ expect(result.status).toBe(0);
64
+ expect(result.stdout).toBe('');
65
+ expect(result.stderr).toContain('Filter regex');
66
+ expect(result.stderr).toContain('src/a.test.js');
67
+ expect(result.stderr).toContain('after filter (0)');
68
+ });
69
+
70
+ it('runs only the matching spec in a real dry run and exits 0', () => {
71
+ git(root, 'git init -b main -q');
72
+ git(root, 'git config user.email test@example.com');
73
+ git(root, 'git config user.name Test');
74
+ fs.mkdirSync(path.join(root, 'src'));
75
+ fs.writeFileSync(path.join(root, 'src', 'a.js'), 'module.exports = 1;\n');
76
+ fs.writeFileSync(path.join(root, 'src', 'a.test.js'), 'test("a", () => expect(1).toBe(1));\n');
77
+ git(root, 'git add -A && git commit -q -m init');
78
+
79
+ const result = runCli(root, ['--dryRun', 'true', '--files', 'src/a.js', '--base', 'main', '--mode', 'fast', '--filter', 'a\\.test\\.js']);
80
+
81
+ expect(result.status).toBe(0);
82
+ expect(result.stdout.trim()).toBe('src/a.test.js');
83
+ expect(result.stderr).toContain('before filter (1)');
84
+ expect(result.stderr).toContain('after filter (1)');
85
+ });
86
+
87
+ it('exits 1 with a clear message when the filter regex is invalid', () => {
88
+ git(root, 'git init -b main -q');
89
+ git(root, 'git config user.email test@example.com');
90
+ git(root, 'git config user.name Test');
91
+ fs.mkdirSync(path.join(root, 'src'));
92
+ fs.writeFileSync(path.join(root, 'src', 'a.js'), 'module.exports = 1;\n');
93
+ git(root, 'git add -A && git commit -q -m init');
94
+
95
+ const result = runCli(root, ['--files', 'src/a.js', '--base', 'main', '--mode', 'fast', '--filter', '(unclosed']);
96
+
97
+ expect(result.status).toBe(1);
98
+ expect(result.stderr).toContain('Invalid filter regex "(unclosed"');
99
+ });
100
+
101
+ it('shows the provided jest flags in the options summary', () => {
102
+ git(root, 'git init -b main -q');
103
+ git(root, 'git config user.email test@example.com');
104
+ git(root, 'git config user.name Test');
105
+ fs.mkdirSync(path.join(root, 'src'));
106
+ fs.writeFileSync(path.join(root, 'src', 'a.js'), 'module.exports = 1;\n');
107
+ fs.writeFileSync(path.join(root, 'src', 'a.test.js'), 'test("a", () => expect(1).toBe(1));\n');
108
+ git(root, 'git add -A && git commit -q -m init');
109
+
110
+ const result = runCli(root, ['--dryRun', 'true', '--files', 'src/a.js', '--base', 'main', '--mode', 'fast', '--jest', '--maxWorkers=2', '--jest', '--silent']);
111
+
112
+ expect(result.status).toBe(0);
113
+ expect(result.stderr).toContain('--maxWorkers=2');
114
+ expect(result.stderr).toContain('--silent');
115
+ });
116
+
117
+ it('reads a comma-separated jest flag list into separate flags', () => {
118
+ git(root, 'git init -b main -q');
119
+ git(root, 'git config user.email test@example.com');
120
+ git(root, 'git config user.name Test');
121
+ fs.mkdirSync(path.join(root, 'src'));
122
+ fs.writeFileSync(path.join(root, 'src', 'a.js'), 'module.exports = 1;\n');
123
+ fs.writeFileSync(path.join(root, 'src', 'a.test.js'), 'test("a", () => expect(1).toBe(1));\n');
124
+ git(root, 'git add -A && git commit -q -m init');
125
+
126
+ const result = runCli(root, ['--dryRun', 'true', '--files', 'src/a.js', '--base', 'main', '--mode', 'fast', '--jest', '--maxWorkers=2,--silent']);
127
+
128
+ expect(result.status).toBe(0);
129
+ expect(result.stderr).toContain('--maxWorkers=2');
130
+ expect(result.stderr).toContain('--silent');
131
+ });
132
+
38
133
  it('dryRun prints only the selected test path on stdout', () => {
39
134
  git(root, 'git init -b main -q');
40
135
  git(root, 'git config user.email test@example.com');