Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(runner): a skip pattern after a file applies or is refused [C7]

Corey Olson06984429e67a
diff --git a/bin/run-tests.js b/bin/run-tests.js
index 18667b9d..b87c82a3 100644
--- a/bin/run-tests.js
+++ b/bin/run-tests.js
@@ -258,16 +258,20 @@ function testEnvironment(sandbox, gateMarkers = {}) {
*/
function runTests(args, env, concurrency) {
let files = concurrency.files;
- const forwarded = [];
- const namePatterns = [];
+ // Node reads an option only before the files, so every option is placed ahead of them, wherever it was written (#931).
+ const placed = [];
+ const selectors = [];
for (let at = 0; at < args.length; at += 1) {
const argument = args[at];
- if (argument === '--') { forwarded.push(...args.slice(at)); break; }
+ if (argument === '--') { selectors.push(...args.slice(at)); break; }
if (/^--test[-_]name[-_]pattern(?:=|$)/u.test(argument)) {
- // Node reads a name pattern only before the files, so a pattern written after them moves ahead [C7].
const value = argument.includes('=') ? argument.slice(argument.indexOf('=') + 1) : args[++at];
if (value === undefined) throw new Error('--test-name-pattern requires a value');
- namePatterns.push(`--test-name-pattern=${value}`);
+ placed.push(`--test-name-pattern=${value}`);
+ } else if (/^--test[-_]skip[-_]pattern(?:=|$)/u.test(argument)) {
+ const value = argument.includes('=') ? argument.slice(argument.indexOf('=') + 1) : args[++at];
+ if (value === undefined) throw new Error('--test-skip-pattern requires a value');
+ placed.push(`--test-skip-pattern=${value}`);
} else if (/^--test[-_]concurrency(?:=|$)/u.test(argument)) {
const value = argument.includes('=') ? argument.slice(argument.indexOf('=') + 1) : args[++at];
if (!/^[1-9][0-9]*$/u.test(value ?? '') || !Number.isSafeInteger(Number(value))) {
@@ -280,10 +284,15 @@ function runTests(args, env, concurrency) {
} else if (argument === '--test-only') {
// Node would apply it only to cases marked only, so a run would silently skip the rest of the file (#931).
throw new Error('unknown option --test-only; run-tests does not apply it, so select cases with --test-name-pattern');
- } else if (argument.startsWith('-') && !knownNodeOption(argument)) {
- // Node ignores an option it does not know after the files; name it instead of running without it (#931).
- throw new Error(`unknown option ${argument.split('=', 1)[0]}; check its spelling, or drop it`);
- } else forwarded.push(argument);
+ } else if (argument.startsWith('-')) {
+ // An option Node does not know would be ignored; name it instead of running without it (#931).
+ if (!knownNodeOption(argument)) throw new Error(`unknown option ${argument.split('=', 1)[0]}; check its spelling, or drop it`);
+ placed.push(argument);
+ if (!argument.includes('=') && optionTakesValue(argument)) {
+ if (args[at + 1] === undefined) throw new Error(`${argument} requires a value`);
+ placed.push(args[++at]);
+ }
+ } else selectors.push(argument);
}
const reporter = args.some((argument) => argument === '--test-reporter' || argument.startsWith('--test-reporter='));
const nodeArgs = [
@@ -293,8 +302,8 @@ function runTests(args, env, concurrency) {
...(!reporter ? ['--test-reporter=tap'] : []),
'--import',
runner,
- ...namePatterns,
- ...forwarded,
+ ...placed,
+ ...selectors,
];
return spawnSync(process.execPath, nodeArgs, { env, stdio: 'inherit' });
}
diff --git a/test/run-tests-options.test.js b/test/run-tests-options.test.js
index b0b0dd28..0c2c8e3e 100644
--- a/test/run-tests-options.test.js
+++ b/test/run-tests-options.test.js
@@ -27,3 +27,31 @@ test('--test-only after the file is refused by name [C7]', () => {
assert.match(`${result.stdout}${result.stderr}`, /run-tests: unknown option --test-only/u, 'the refusal names the option');
} finally { rmSync(root, { recursive: true, force: true }); }
});
+
+/** A two-case file; each case says its own name when it runs. */
+function twoCaseFile(name) {
+ const root = mkdtempSync(join(tmpdir(), 'pullboard-skip-after-')); try {
+ writeFileSync(join(root, name), "import { test } from 'node:test';\ntest('alpha case runs', () => {});\ntest('beta case runs', () => {});\n");
+ return { root, runSkip: (args) => runFixtureChild(process.execPath, [runner, name, ...args], { cwd: root, encoding: 'utf8' }) };
+ } catch (error) { rmSync(root, { recursive: true, force: true }); throw error; }
+}
+
+test('a skip pattern after the file in the equals form runs only the other case [C7]', () => {
+ const fixture = twoCaseFile('skip-equals.test.mjs');
+ try {
+ const result = fixture.runSkip(['--test-skip-pattern=alpha']);
+ assert.equal(result.status, 0, result.context);
+ assert.match(result.stdout, /beta case runs/u, 'the unskipped case runs');
+ assert.doesNotMatch(result.stdout, /alpha case runs/u, 'the skipped case does not run');
+ } finally { rmSync(fixture.root, { recursive: true, force: true }); }
+});
+
+test('a skip pattern after the file in the separate-value form runs only the other case [C7]', () => {
+ const fixture = twoCaseFile('skip-separate.test.mjs');
+ try {
+ const result = fixture.runSkip(['--test-skip-pattern', 'alpha']);
+ assert.equal(result.status, 0, result.context);
+ assert.match(result.stdout, /beta case runs/u, 'the unskipped case runs');
+ assert.doesNotMatch(result.stdout, /alpha case runs/u, 'the skipped case does not run');
+ } finally { rmSync(fixture.root, { recursive: true, force: true }); }
+});