Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions test/napi/napi-app/test_experimental_with_timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ proc.stdout.on('data', (data) => {
proc.stderr.on('data', (data) => {
stderr += data.toString();
process.stderr.write(data);
// Check if we've seen the expected crash messages
if (data.toString().includes('FATAL ERROR')) {

// Check the accumulated output: a marker can be split across two chunks.
if (stderr.includes('FATAL ERROR')) {
sawFatalError = true;
}
if (data.toString().includes('panic(main thread)')) {
if (stderr.includes('panic(main thread)')) {
sawPanic = true;
}

// If we've seen both messages, kill the process immediately
// This avoids hanging on llvm-symbolizer
if (sawFatalError && sawPanic) {
Expand All @@ -57,9 +57,11 @@ const timeout = setTimeout(() => {
proc.kill('SIGKILL');
}, 5000);

proc.on('exit', (code, signal) => {
// 'close', not 'exit': 'exit' can fire before the stdio pipes have been
// drained, and the verdict below depends on everything the child wrote.
proc.on('close', (code, signal) => {
clearTimeout(timeout);

// Check if the test passed
if (sawFatalError && sawPanic) {
console.log('\n\nTEST PASSED: Process crashed as expected');
Expand Down
6 changes: 3 additions & 3 deletions test/napi/napi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1329,18 +1329,18 @@ describe.concurrent.skipIf(!canBuildNodeAddons())("napi", () => {
bunProc.exited,
]);

// The wrapper script should exit with 0 if the test passed
expect(bunExitCode).toBe(0);
// Combined output first, so a failure shows what the wrapper and child wrote.
expect(bunStdout + "\n---- stderr ----\n" + bunStderr).toContain("TEST PASSED: Process crashed as expected");
expect(bunStdout + bunStderr).toContain("Loading experimental module");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Assert the fixture output on stdout.

The panic report can echo the full -e source into bunStderr, as documented on Lines [1387]-[1390]. That source contains "Loading experimental module" on Line [10]. Therefore, this assertion can pass even when the child did not write the message to stdout.

Proposed fix
-      expect(bunStdout + bunStderr).toContain("Loading experimental module");
+      expect(bunStdout).toContain("Loading experimental module");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expect(bunStdout + bunStderr).toContain("Loading experimental module");
expect(bunStdout).toContain("Loading experimental module");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/napi/napi.test.ts` at line 1383, Update the assertion in the relevant
NAPI test to validate that “Loading experimental module” appears in bunStdout
specifically, rather than in the combined bunStdout + bunStderr output. Keep the
existing fixture-output expectation unchanged otherwise.

expect(bunStdout + bunStderr).toContain("Created");
expect(bunStderr).toContain("FATAL ERROR");
expect(bunStdout + bunStderr).toContain("TEST PASSED: Process crashed as expected");

// The marker must NOT have actually been printed. Only check stdout: the
// fixture prints the marker via console.log (stdout), while stderr contains
// the debug-build panic report whose "Args:" line echoes the full -e script
// source, including the literal "ERROR: Did not crash! Test failed!".
expect(bunStdout).not.toContain("ERROR: Did not crash");
expect(bunExitCode).toBe(0);
},
25_000,
);
Expand Down