Skip to content

fix: guard against undefined testFiles when findTests throws - #3473

Open
tsushanth wants to merge 1 commit into
avajs:mainfrom
tsushanth:fix/testfiles-undefined-on-glob-error
Open

fix: guard against undefined testFiles when findTests throws#3473
tsushanth wants to merge 1 commit into
avajs:mainfrom
tsushanth:fix/testfiles-undefined-on-glob-error

Conversation

@tsushanth

Copy link
Copy Markdown

What

When globs.findTests rejects (bad glob config, permission error, IO failure), the catch block in Api#run stores the error in setupOrGlobError but leaves testFiles as undefined. The very next statement builds selectionInsights:

const selectionInsights = {
  ...
  testFileCount: testFiles.length,   // ← TypeError: Cannot read properties of undefined
  ...
};

This crashes before setupOrGlobError is ever re-thrown, so the original error is swallowed and the user sees a confusing TypeError instead.

Fix

Use optional chaining so the property access is safe when testFiles is undefined:

testFileCount: testFiles?.length ?? 0,

Reproduction

Configure ava with a files glob that causes findTests to throw (e.g., pass an invalid pattern that triggers the internal validation error), or simulate an IO failure in globs.findTests. The run crashes with:

TypeError: Cannot read properties of undefined (reading 'length')
    at Api.run (lib/api.js:...)

instead of surfacing the underlying glob/config error.

@tsushanth
tsushanth force-pushed the fix/testfiles-undefined-on-glob-error branch 8 times, most recently from eb37946 to 3421c66 Compare August 15, 2026 11:26
@tsushanth
tsushanth force-pushed the fix/testfiles-undefined-on-glob-error branch from 3421c66 to 79d7c13 Compare August 16, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants