@@ -90,6 +90,22 @@ async function findTests(
90
90
91
91
const normalizePath = ( path : string ) : string => path . replace ( / \\ / g, '/' ) ;
92
92
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
+
93
109
async function findMatchingTests (
94
110
pattern : string ,
95
111
ignore : string [ ] ,
@@ -98,17 +114,13 @@ async function findMatchingTests(
98
114
) : Promise < string [ ] > {
99
115
// normalize pattern, glob lib only accepts forward slashes
100
116
let normalizedPattern = normalizePath ( pattern ) ;
101
- if ( normalizedPattern . charAt ( 0 ) === '/' ) {
102
- normalizedPattern = normalizedPattern . substring ( 1 ) ;
103
- }
117
+ normalizedPattern = removeLeadingSlash ( normalizedPattern ) ;
104
118
105
119
const relativeProjectRoot = normalizePath ( relative ( workspaceRoot , projectSourceRoot ) + '/' ) ;
106
120
107
121
// remove relativeProjectRoot to support relative paths from root
108
122
// 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 ) ;
112
124
113
125
// special logic when pattern does not look like a glob
114
126
if ( ! isDynamicPattern ( normalizedPattern ) ) {
@@ -130,10 +142,15 @@ async function findMatchingTests(
130
142
}
131
143
}
132
144
145
+ // normalize the patterns in the ignore list
146
+ const normalizedIgnorePatternList = ignore . map ( ( pattern : string ) =>
147
+ removeRelativeRoot ( removeLeadingSlash ( normalizePath ( pattern ) ) , relativeProjectRoot ) ,
148
+ ) ;
149
+
133
150
return glob ( normalizedPattern , {
134
151
cwd : projectSourceRoot ,
135
152
absolute : true ,
136
- ignore : [ '**/node_modules/**' , ...ignore ] ,
153
+ ignore : [ '**/node_modules/**' , ...normalizedIgnorePatternList ] ,
137
154
} ) ;
138
155
}
139
156
0 commit comments