Skip to content

Commit 78b3b52

Browse files
gustav0dcpojer
andauthored
fix(testPathPatterns) fix absPath breaking (#15648)
Co-authored-by: Christoph Nakazawa <[email protected]>
1 parent 9a3ec0f commit 78b3b52

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

packages/jest-pattern/src/TestPathPatterns.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ export class TestPathPatternsExecutor {
115115
if (this.toRegex(regexStr).test(pathToTest)) {
116116
return true;
117117
}
118+
119+
if (this.toRegex(regexStr).test(absPath)) {
120+
return true;
121+
}
118122
}
119123
return false;
120124
}

packages/jest-pattern/src/__tests__/TestPathPatterns.test.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,21 @@ describe('TestPathPatternsExecutor', () => {
186186
});
187187

188188
it('returns true only if matches relative path', () => {
189+
const rootDir = '/home/myuser/';
190+
189191
const testPathPatterns = makeExecutor(['home'], {
190-
rootDir: '/home/myuser/',
192+
rootDir,
191193
});
192-
expect(testPathPatterns.isMatch('/home/myuser/LoginPage.js')).toBe(false);
193-
expect(testPathPatterns.isMatch('/home/myuser/HomePage.js')).toBe(true);
194+
expect(
195+
testPathPatterns.isMatch(
196+
path.relative(rootDir, '/home/myuser/LoginPage.js'),
197+
),
198+
).toBe(false);
199+
expect(
200+
testPathPatterns.isMatch(
201+
path.relative(rootDir, '/home/myuser/HomePage.js'),
202+
),
203+
).toBe(true);
194204
});
195205

196206
it('matches absolute paths regardless of rootDir', () => {
@@ -230,5 +240,20 @@ describe('TestPathPatternsExecutor', () => {
230240
const testPathPatterns = makeExecutor(['a/b'], config);
231241
expect(testPathPatterns.isMatch('C:\\foo\\a\\b')).toBe(true);
232242
});
243+
244+
it('matches absolute path with absPath', () => {
245+
const pattern = '^/home/app/';
246+
const rootDir = '/home/app';
247+
const absolutePath = '/home/app/packages/';
248+
249+
const testPathPatterns = makeExecutor([pattern], {
250+
rootDir,
251+
});
252+
253+
const relativePath = path.relative(rootDir, absolutePath);
254+
255+
expect(testPathPatterns.isMatch(relativePath)).toBe(false);
256+
expect(testPathPatterns.isMatch(absolutePath)).toBe(true);
257+
});
233258
});
234259
});

0 commit comments

Comments
 (0)