-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
Description
Summary
When Api.run() fails to glob test files (for instance because projectDir points to a file), AVA crashes with TypeError: Cannot read properties of undefined (reading 'length'). This happens before AVA can emit the actual glob error. Similarly, t.try() guard rails throw undefined when users call commit() after discard() (or vice versa), instead of surfacing the intended error.
Steps to reproduce
- Instantiate Api with projectDir set to a file path and call run().
- Alternatively, create a test with const attempt = await t.try(...); attempt.discard(); attempt.commit();.
Expected behavior
- Api.run() should gracefully propagate glob/config errors: the run finishes, runStatus.stats.internalErrors === 1, and the emitted internal-error event contains the original glob error (e.g. “The cwd option must be a path to a directory”), so users see the real failure.
- t.try() guard rails should raise the guard error ("Can’t commit a result that was previously discarded" / "Can’t discard a result that was previously committed") via AVA’s TestFailure sentinel, producing a meaningful failure report.
Actual behavior
- When globs.findTests() throws, testFiles stays undefined and Api.run() crashes with TypeError: Cannot read properties of undefined (reading 'length') before the real error is surfaced.
- Calling attempt.commit() after attempt.discard() (or vice versa) throws undefined, yielding “Thrown: undefined” with no stack, so the user never sees the intended guard-rail error.
Why it matters
Both bugs hide the user-facing error. Glob misconfiguration looks like an AVA crash, and t.try() misuse is nearly impossible todiagnose because the error message disappears.
Proposed fix
- Initialize testFiles to [] so selectionInsights and providers can still be set up, allowing setupOrGlobError to rethrow the real error.
- Throw test.testFailure inside the guard-rail checks so Runnable.run() treats it as AVA’s sentinel.
- Add tests to cover both scenarios (CLI fixture for t.try() and tap test for glob errors).