@@ -204,15 +204,20 @@ func TestJest_DiscoverTestFiles_StripsInheritedNodeOptions(t *testing.T) {
204204 }
205205}
206206
207- func TestJest_DiscoverTestFiles_WithTestsLocationUsesTestMatch (t * testing.T ) {
207+ func TestJest_DiscoverTestFiles_WithTestsLocationFiltersListTestsOutput (t * testing.T ) {
208208 tempDir := t .TempDir ()
209209 oldWd , _ := os .Getwd ()
210210 defer func () { _ = os .Chdir (oldWd ) }()
211211 if err := os .Chdir (tempDir ); err != nil {
212212 t .Fatalf ("failed to chdir: %v" , err )
213213 }
214214
215- for _ , file := range []string {"custom/a.check.js" , "custom/b.check.js" , "src/c.test.js" } {
215+ for _ , file := range []string {
216+ "custom/unit/a.check.js" ,
217+ "custom/unit/b.check.js" ,
218+ "custom/not-listed.check.js" ,
219+ "src/c.test.js" ,
220+ } {
216221 if err := os .MkdirAll (filepath .Dir (file ), 0755 ); err != nil {
217222 t .Fatalf ("failed to create dir for %s: %v" , file , err )
218223 }
@@ -221,13 +226,14 @@ func TestJest_DiscoverTestFiles_WithTestsLocationUsesTestMatch(t *testing.T) {
221226 }
222227 }
223228
224- setTestsLocation (t , "custom/*.check.js" )
229+ setTestsLocation (t , "./ custom/** /*.check.js" )
225230
226231 var capturedName string
227232 var capturedArgs []string
228233 mockExecutor := & jestCommandExecutor {
229- output : []byte (filepath .Join (tempDir , "custom" , "b.check.js" ) + "\n " +
230- filepath .Join (tempDir , "custom" , "a.check.js" ) + "\n " ),
234+ output : []byte (filepath .Join (tempDir , "custom" , "unit" , "b.check.js" ) + "\n " +
235+ filepath .Join (tempDir , "src" , "c.test.js" ) + "\n " +
236+ filepath .Join (tempDir , "custom" , "unit" , "a.check.js" ) + "\n " ),
231237 onExecution : func (name string , args []string ) {
232238 capturedName = name
233239 capturedArgs = slices .Clone (args )
@@ -242,12 +248,73 @@ func TestJest_DiscoverTestFiles_WithTestsLocationUsesTestMatch(t *testing.T) {
242248 if capturedName != "npx" {
243249 t .Errorf ("expected command %q, got %q" , "npx" , capturedName )
244250 }
245- expectedArgs := []string {"jest" , "--listTests" , "--testMatch" , "custom/*.check.js" }
251+ expectedArgs := []string {"jest" , "--listTests" }
246252 if ! slices .Equal (capturedArgs , expectedArgs ) {
247253 t .Errorf ("expected args %v, got %v" , expectedArgs , capturedArgs )
248254 }
249255
250- expected := []string {"custom/a.check.js" , "custom/b.check.js" }
256+ expected := []string {"custom/unit/a.check.js" , "custom/unit/b.check.js" }
257+ if ! slices .Equal (files , expected ) {
258+ t .Errorf ("expected files %v, got %v" , expected , files )
259+ }
260+ }
261+
262+ func TestJest_DiscoverTestFiles_WithTestsLocationReturnsInvalidPatternError (t * testing.T ) {
263+ setTestsLocation (t , "custom/[" )
264+
265+ mockExecutor := & jestCommandExecutor {
266+ output : []byte ("custom/a.check.js\n " ),
267+ }
268+ jest := & Jest {executor : mockExecutor , platformEnv : make (map [string ]string )}
269+
270+ _ , err := jest .DiscoverTestFiles (context .Background (), discovery.TestFileSet {Pattern : jest .TestPattern ()})
271+ if err == nil {
272+ t .Fatal ("expected error" )
273+ }
274+ if ! strings .Contains (err .Error (), "invalid tests location pattern" ) {
275+ t .Fatalf ("unexpected error: %v" , err )
276+ }
277+ }
278+
279+ func TestJest_DiscoverTestFiles_WithTestsExcludePatternFiltersListTestsOutput (t * testing.T ) {
280+ tempDir := t .TempDir ()
281+ oldWd , _ := os .Getwd ()
282+ defer func () { _ = os .Chdir (oldWd ) }()
283+ if err := os .Chdir (tempDir ); err != nil {
284+ t .Fatalf ("failed to chdir: %v" , err )
285+ }
286+
287+ for _ , file := range []string {"src/a.test.js" , "src/system/b.test.js" } {
288+ if err := os .MkdirAll (filepath .Dir (file ), 0755 ); err != nil {
289+ t .Fatalf ("failed to create dir for %s: %v" , file , err )
290+ }
291+ if err := os .WriteFile (file , []byte ("test" ), 0644 ); err != nil {
292+ t .Fatalf ("failed to create %s: %v" , file , err )
293+ }
294+ }
295+
296+ setTestsExcludePattern (t , "src/system/**/*.test.js" )
297+
298+ var capturedArgs []string
299+ mockExecutor := & jestCommandExecutor {
300+ output : []byte (filepath .Join (tempDir , "src" , "system" , "b.test.js" ) + "\n " +
301+ filepath .Join (tempDir , "src" , "a.test.js" ) + "\n " ),
302+ onExecution : func (name string , args []string ) {
303+ capturedArgs = slices .Clone (args )
304+ },
305+ }
306+ jest := & Jest {executor : mockExecutor , platformEnv : make (map [string ]string )}
307+ files , err := jest .DiscoverTestFiles (context .Background (), discovery.TestFileSet {Pattern : jest .TestPattern ()})
308+ if err != nil {
309+ t .Fatalf ("DiscoverTestFiles failed: %v" , err )
310+ }
311+
312+ expectedArgs := []string {"jest" , "--listTests" }
313+ if ! slices .Equal (capturedArgs , expectedArgs ) {
314+ t .Errorf ("expected args %v, got %v" , expectedArgs , capturedArgs )
315+ }
316+
317+ expected := []string {"src/a.test.js" }
251318 if ! slices .Equal (files , expected ) {
252319 t .Errorf ("expected files %v, got %v" , expected , files )
253320 }
0 commit comments