GeezerVison is showing github.com — test_runner: restore directory search for --test · nodejs/node@1ad7ca3
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/runner.js +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,6 +19,7 @@ const { | 19 | 19 | ObjectAssign, | 20 | 20 | PromisePrototypeThen, | 21 | 21 | PromiseWithResolvers, | | 22 | + RegExpPrototypeSymbolReplace, | 22 | 23 | SafeMap, | 23 | 24 | SafePromiseAll, | 24 | 25 | SafePromiseAllReturnVoid, | @@ -35,6 +36,7 @@ const { | 35 | 36 | } = primordials; | 36 | 37 |
| 37 | 38 | const { spawn } = require('child_process'); | | 39 | +const { statSync } = require('fs'); | 38 | 40 | const { finished } = require('internal/streams/end-of-stream'); | 39 | 41 | const { availableParallelism } = require('os'); | 40 | 42 | const { resolve, sep, isAbsolute } = require('path'); | @@ -154,6 +156,23 @@ function createTestFileList(patterns, cwd) { | 154 | 156 | const hasUserSuppliedPattern = patterns != null; | 155 | 157 | if (!patterns || patterns.length === 0) { | 156 | 158 | patterns = [kDefaultPattern]; | | 159 | + } else { | | 160 | + patterns = ArrayPrototypeMap(patterns, (pattern) => { | | 161 | + // A directory argument is expanded to search for the default test files | | 162 | + // within it, matching the behavior from before glob patterns were | | 163 | + // supported. Glob patterns always use forward slashes, so a trailing | | 164 | + // path separator (of either kind) is stripped before appending. | | 165 | + const resolved = isAbsolute(pattern) ? pattern : resolve(cwd, pattern); | | 166 | + try { | | 167 | + if (statSync(resolved).isDirectory()) { | | 168 | + return `${RegExpPrototypeSymbolReplace(/[\\/]+$/, pattern, '')}/${kDefaultPattern}`; | | 169 | + } | | 170 | + } catch { | | 171 | + // Not a directory or not accessible; leave the pattern as-is so the | | 172 | + // existing "Could not find" handling still applies. | | 173 | + } | | 174 | + return pattern; | | 175 | + }); | 157 | 176 | } | 158 | 177 | const glob = new Glob(patterns, { | 159 | 178 | __proto__: null, | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-runner-cli.js +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -62,6 +62,27 @@ for (const isolation of ['none', 'process']) { | 62 | 62 | assert.doesNotMatch(stdout, /ok 4 - this should pass/); | 63 | 63 | } | 64 | 64 |
| | 65 | + { | | 66 | + // A directory argument is searched for the default test files within it, | | 67 | + // both bare and with a trailing separator. | | 68 | + // Refs: https://github.com/nodejs/node/issues/64555 | | 69 | + for (const dir of ['matching-patterns', 'matching-patterns/']) { | | 70 | + const args = ['--test', '--test-reporter=tap', | | 71 | + '--no-experimental-strip-types', | | 72 | + `--test-isolation=${isolation}`, dir]; | | 73 | + const child = spawnSync(process.execPath, args, { cwd: testFixtures }); | | 74 | + | | 75 | + assert.strictEqual(child.status, 0); | | 76 | + assert.strictEqual(child.signal, null); | | 77 | + assert.strictEqual(child.stderr.toString(), ''); | | 78 | + const stdout = child.stdout.toString(); | | 79 | + | | 80 | + assert.match(stdout, /ok 1 - this should pass/); | | 81 | + assert.match(stdout, /ok 2 - this should pass/); | | 82 | + assert.match(stdout, /ok 3 - this should pass/); | | 83 | + } | | 84 | + } | | 85 | + | 65 | 86 | { | 66 | 87 | // Should match files with "-test.(c|m)(t|j)s" suffix when typescript support is enabled | 67 | 88 | const args = ['--test', '--test-reporter=tap', '--no-warnings', | |
|