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

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 8 times, most recently from 4ca3efe to 1f6f2c6 Compare August 23, 2026 06:01
@tsushanth
tsushanth force-pushed the fix/testfiles-undefined-on-glob-error branch 7 times, most recently from 7eaf886 to 0f12dfd Compare August 31, 2026 03:40
@tsushanth
tsushanth force-pushed the fix/testfiles-undefined-on-glob-error branch 6 times, most recently from bac6c66 to 1c06bfa Compare September 5, 2026 18:40
@tsushanth
tsushanth force-pushed the fix/testfiles-undefined-on-glob-error branch from 1c06bfa to fe7156b Compare September 8, 2026 14:47
@tsushanth
tsushanth force-pushed the fix/testfiles-undefined-on-glob-error branch 8 times, most recently from ed59b4a to f7b92f9 Compare September 16, 2026 13:21
@tsushanth
tsushanth force-pushed the fix/testfiles-undefined-on-glob-error branch 3 times, most recently from d0d4494 to 1b15170 Compare September 20, 2026 06:13
@tsushanth
tsushanth force-pushed the fix/testfiles-undefined-on-glob-error branch from 1b15170 to 12229cb Compare September 21, 2026 06:04

This branch has not been deployed

No deployments
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