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 7 times, most recently from 1b15170 to 12229cb Compare September 21, 2026 06:04
@tsushanth
tsushanth force-pushed the fix/testfiles-undefined-on-glob-error branch 6 times, most recently from 6f86367 to c0cc59e Compare September 29, 2026 06:14
@tsushanth
tsushanth force-pushed the fix/testfiles-undefined-on-glob-error branch 7 times, most recently from 6ebfbcc to a59364c Compare October 6, 2026 06:09
@tsushanth
tsushanth force-pushed the fix/testfiles-undefined-on-glob-error branch 7 times, most recently from e3daef6 to 25305ac Compare October 13, 2026 06:06
@tsushanth
tsushanth force-pushed the fix/testfiles-undefined-on-glob-error branch from 25305ac to 29cafbe Compare October 14, 2026 14:08
@tsushanth
tsushanth force-pushed the fix/testfiles-undefined-on-glob-error branch from 29cafbe to 67e3b2f Compare October 15, 2026 06:12

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