Skip to content

Commit aa9979e

Browse files
committed
test: switch repl import-no-crash to in-process REPL
Replace the child_process.spawn-based regression test with the in-process startNewREPLServer pattern (similar to test-repl-null.js). This is faster, avoids subprocess flake, and lets the test assert on the REPL output stream directly instead of bytes piped through stdio. Verified to still catch the regression: the test exits with code 1 against unpatched v26.1.0 (acorn SyntaxError escapes) and exits 0 against the fix. Signed-off-by: Abdelhadi Sabani <asabani.work@gmail.com>
1 parent 24a6f35 commit aa9979e

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
// Regression test for https://github.com/nodejs/node/issues/63551:
3+
// Typing a bare `import` keyword in the REPL used to terminate the process.
4+
//
5+
// V8 throws SyntaxError("Cannot use import statement outside a module"),
6+
// which the REPL enriched with a dynamic-import suggestion via
7+
// `toDynamicImport`. That helper called acorn without a try/catch; on
8+
// incomplete input acorn threw, and the exception escaped the REPL's input
9+
// pipeline to crash the process.
10+
//
11+
// The fix wraps the acorn call in try/catch and falls back to a plain
12+
// error message when the line cannot be parsed as a complete import
13+
// statement. This test asserts that:
14+
// 1. Emitting an incomplete `import` line through the REPL does not
15+
// throw out of the line-handler, and
16+
// 2. The REPL still surfaces a SyntaxError to the user.
17+
18+
require('../common');
19+
const assert = require('assert');
20+
const { startNewREPLServer } = require('../common/repl');
21+
22+
const { replServer, output } = startNewREPLServer();
23+
24+
replServer.emit('line', 'import');
25+
replServer.emit('line', '.exit');
26+
27+
assert.match(output.accumulator, /SyntaxError/);
28+
assert.match(
29+
output.accumulator,
30+
/Cannot use import statement inside the Node\.js REPL\b/,
31+
);

0 commit comments

Comments
 (0)