|
8 | 8 |
|
9 | 9 | import { type PathLike, constants, promises as fs } from 'node:fs'; |
10 | 10 | import os from 'node:os'; |
11 | | -import { basename, dirname, extname, isAbsolute, join, relative } from 'node:path'; |
| 11 | +import { basename, dirname, extname, isAbsolute, join, posix, relative } from 'node:path'; |
12 | 12 | import { glob, isDynamicPattern } from 'tinyglobby'; |
13 | 13 | import { calculateHash, initializeHash } from '../../utils/hash'; |
14 | 14 | import { toPosixPath } from '../../utils/path'; |
@@ -62,11 +62,39 @@ export async function findTests( |
62 | 62 |
|
63 | 63 | // 2. Execute a single glob for all dynamic patterns |
64 | 64 | if (dynamicPatterns.length > 0) { |
65 | | - const globMatches = await glob(dynamicPatterns, { |
66 | | - cwd: projectSourceRoot, |
| 65 | + let maxParentPrefix = ''; |
| 66 | + for (const pattern of [...dynamicPatterns, ...normalizedExcludes]) { |
| 67 | + if (isAbsolute(pattern)) { |
| 68 | + continue; |
| 69 | + } |
| 70 | + |
| 71 | + const parentMatch = /^(?:\.\.\/)+/.exec(pattern); |
| 72 | + if (parentMatch && parentMatch[0].length > maxParentPrefix.length) { |
| 73 | + maxParentPrefix = parentMatch[0]; |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + let globCwd = projectSourceRoot; |
| 78 | + let patternsToGlob = dynamicPatterns; |
| 79 | + let excludesToGlob = normalizedExcludes; |
| 80 | + if (maxParentPrefix) { |
| 81 | + globCwd = join(projectSourceRoot, maxParentPrefix.slice(0, -1)); |
| 82 | + const relativeSourceRoot = toPosixPath(relative(globCwd, projectSourceRoot)); |
| 83 | + if (relativeSourceRoot) { |
| 84 | + patternsToGlob = dynamicPatterns.map((p) => |
| 85 | + isAbsolute(p) ? p : posix.join(relativeSourceRoot, p), |
| 86 | + ); |
| 87 | + excludesToGlob = normalizedExcludes.map((p) => |
| 88 | + isAbsolute(p) || p.startsWith('**/') ? p : posix.join(relativeSourceRoot, p), |
| 89 | + ); |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + const globMatches = await glob(patternsToGlob, { |
| 94 | + cwd: globCwd, |
67 | 95 | absolute: true, |
68 | 96 | expandDirectories: false, |
69 | | - ignore: ['**/node_modules/**', ...normalizedExcludes], |
| 97 | + ignore: ['**/node_modules/**', ...excludesToGlob], |
70 | 98 | }); |
71 | 99 |
|
72 | 100 | for (const match of globMatches) { |
|
0 commit comments