File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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/**' )
Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments