Skip to content

Commit 937d4e7

Browse files
authored
fix: ensure absolute directories in glob patterns are leading prior to removal (#23368)
* fix: ensure absolute directories in glob patterns are leading prior to removal * Removing errant slash
1 parent ae5cbb5 commit 937d4e7

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

packages/data-context/src/sources/FileDataSource.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ export class FileDataSource {
3636
// The working directory path may include characters that conflict with glob
3737
// syntax (brackets, parentheses, etc.) and cause our searches to inadvertently fail.
3838
// We scope our search to the working directory using the `cwd` globby option.
39-
return globPattern.replace(cwd, '.')
39+
if (globPattern.startsWith(cwd)) {
40+
return globPattern.replace(cwd, '.')
41+
}
42+
43+
return globPattern
4044
})
4145

4246
const ignoreGlob = (globOptions?.ignore ?? []).concat('**/node_modules/**')

packages/data-context/test/unit/sources/FileDataSource.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ describe('FileDataSource', () => {
5858
expect(files).to.have.length(2)
5959
})
6060

61+
it('does not replace working directory in glob pattern if it is not leading', async () => {
62+
// Create a redundant structure within the project dir matching its absolute path
63+
// and write a new script in that location
64+
const nestedScriptPath = path.join(projectPath, 'cypress', projectPath)
65+
66+
await fs.mkdirs(nestedScriptPath)
67+
await fs.writeFile(path.join(nestedScriptPath, 'nested-script.js'), '')
68+
69+
// Verify that the glob pattern is not impacted if if contains directories equivalent
70+
// to the working directory
71+
let files = await fileDataSource.getFilesByGlob(
72+
projectPath,
73+
`./cypress${projectPath}/nested-script.js`,
74+
)
75+
76+
expect(files).to.have.length(1)
77+
})
78+
6179
it('finds files matching multiple patterns', async () => {
6280
const files = await fileDataSource.getFilesByGlob(
6381
projectPath,

0 commit comments

Comments
 (0)