feat(lwc): show Jest crash errors in Test Explorer with full stack tr… - #7940
feat(lwc): show Jest crash errors in Test Explorer with full stack tr…#7940madhur310 wants to merge 1 commit into
Conversation
…aces When Jest crashes before producing JSON results (e.g., syntax errors, module resolution failures), capture the error output and display it in Test Explorer instead of showing "No test results produced". Changes: - Switch from ShellExecution to CustomExecution with JestPseudoterminal to capture Jest stdout/stderr for error extraction - Extract error messages and stack traces from captured output when Jest exits with non-zero code - Display full error details in Test Results panel with proper multi-line formatting - Use run.failed() for both Jest crashes and runtime errors to show inline test decorations (red bar) consistently - Update test mocks to support CustomExecution and onDidEndTaskProcess Technical details: - JestPseudoterminal captures output while still displaying in terminal - Error extraction handles blank lines in Jest output to include full stack traces with code snippets - Task presentation set to Never/hidden since results appear in Test Results tab - Don't set message.location for Jest crashes - let VS Code use test item's own range for inline decoration Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
peternhale
left a comment
There was a problem hiding this comment.
Great architectural improvement for Jest crash error reporting! The pseudoterminal approach correctly captures errors before JSON output. However, there are several issues that need to be addressed before merge.
Must Fix Before Merge
1. Remove console.log statements (7 instances)
Production code should not use console.log. Either use the existing appendToChannel logger or remove these debug statements:
lwcTestController.ts:527-529- command/args logginglwcTestController.ts:548,lwcTestController.ts:551- task lifecycle logginglwcTestController.ts:574,lwcTestController.ts:589- error extraction logginglwcTestController.ts:655,lwcTestController.ts:672- runtime error location logging
2. Fix exit code handling race condition
In lwcTestController.ts awaitTaskEnd, the 100ms fallback timeout returns {} instead of {exitCode: undefined}:
setTimeout(() => {
// ... dispose handlers
resolve({}); // Should be resolve({ exitCode: undefined })
}, 100);This could cause the exitCode !== undefined && exitCode !== 0 check to miss errors when the fallback fires.
3. Remove unused method
JestPseudoterminal.extractErrorLocation() is defined but never called. Either use it or remove it.
Should Fix
4. Extract duplicate regex pattern
The stack trace pattern /at (?:.*?\()?(.* ?):(\d+):(\d+)\)?/ appears in both:
lwcTestController.ts:656jestPseudoterminal.ts:91
Consider extracting to a shared constant.
5. Add test coverage
Missing tests for:
- Error extraction from pseudoterminal output
- Exit code handling paths
JestPseudoterminalclass behavior
6. Verify Windows behavior
The spawn logic now uses shell: !isWin32. Confirm this doesn't regress Windows test execution compared to the original ShellExecution.
7. Document performance impact
waitForResultFile now runs after every test (not just debug runs). Measure and document the performance impact on large test suites.
Consider
8. Type test mocks properly
lwcTestController.test.ts:635 uses any instead of proper VS Code task types.
9. Explain waitForResultFile usage
Add a comment explaining why the file polling is needed for non-debug runs (not obvious from the current comment).
The core approach is solid, but the debug logging and exit code handling need cleanup before this ships.
…aces
When Jest crashes before producing JSON results (e.g., syntax errors, module resolution failures), capture the error output and display it in Test Explorer instead of showing "No test results produced".
Changes:
Technical details:
What does this PR do?
What issues does this PR fix or reference?
#, @@
Functionality Before
<insert gif and/or summary>
Functionality After
<insert gif and/or summary>