@@ -90,6 +90,22 @@ async function findTests(
9090
9191const normalizePath = ( path : string ) : string => path . replace ( / \\ / g, '/' ) ;
9292
93+ const removeLeadingSlash = ( pattern : string ) : string => {
94+ if ( pattern . charAt ( 0 ) === '/' ) {
95+ return pattern . substring ( 1 ) ;
96+ }
97+
98+ return pattern ;
99+ } ;
100+
101+ const removeRelativeRoot = ( path : string , root : string ) : string => {
102+ if ( path . startsWith ( root ) ) {
103+ return path . substring ( root . length ) ;
104+ }
105+
106+ return path ;
107+ } ;
108+
93109async function findMatchingTests (
94110 pattern : string ,
95111 ignore : string [ ] ,
@@ -98,17 +114,13 @@ async function findMatchingTests(
98114) : Promise < string [ ] > {
99115 // normalize pattern, glob lib only accepts forward slashes
100116 let normalizedPattern = normalizePath ( pattern ) ;
101- if ( normalizedPattern . charAt ( 0 ) === '/' ) {
102- normalizedPattern = normalizedPattern . substring ( 1 ) ;
103- }
117+ normalizedPattern = removeLeadingSlash ( normalizedPattern ) ;
104118
105119 const relativeProjectRoot = normalizePath ( relative ( workspaceRoot , projectSourceRoot ) + '/' ) ;
106120
107121 // remove relativeProjectRoot to support relative paths from root
108122 // such paths are easy to get when running scripts via IDEs
109- if ( normalizedPattern . startsWith ( relativeProjectRoot ) ) {
110- normalizedPattern = normalizedPattern . substring ( relativeProjectRoot . length ) ;
111- }
123+ normalizedPattern = removeRelativeRoot ( normalizedPattern , relativeProjectRoot ) ;
112124
113125 // special logic when pattern does not look like a glob
114126 if ( ! isDynamicPattern ( normalizedPattern ) ) {
@@ -130,10 +142,15 @@ async function findMatchingTests(
130142 }
131143 }
132144
145+ // normalize the patterns in the ignore list
146+ const normalizedIgnorePatternList = ignore . map ( ( pattern : string ) =>
147+ removeRelativeRoot ( removeLeadingSlash ( normalizePath ( pattern ) ) , relativeProjectRoot ) ,
148+ ) ;
149+
133150 return glob ( normalizedPattern , {
134151 cwd : projectSourceRoot ,
135152 absolute : true ,
136- ignore : [ '**/node_modules/**' , ...ignore ] ,
153+ ignore : [ '**/node_modules/**' , ...normalizedIgnorePatternList ] ,
137154 } ) ;
138155}
139156
0 commit comments