Skip to content

Commit d84d9fb

Browse files
committed
test: add test for setupHistory callback error
1 parent 0e8e266 commit d84d9fb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const { spawnSync } = require('child_process');
5+
6+
// This test verifies that setupHistory callback errors propagate.
7+
// On main branch (without your fix), this test MUST FAIL.
8+
// After your patch, it MUST PASS.
9+
10+
const child = spawnSync(process.execPath, ['-e', `
11+
const repl = require('repl');
12+
const server = repl.start({ prompt: "" });
13+
server.setupHistory('/tmp/history-test', (err) => {
14+
throw new Error("INTENTIONAL_CALLBACK_THROW");
15+
});
16+
`], {
17+
encoding: 'utf8'
18+
});
19+
20+
// The bug: before your fix, Node *does NOT* propagate the thrown error,
21+
// so stderr does NOT contain the message.
22+
// After your fix, stderr WILL contain INTENTIONAL_CALLBACK_THROW.
23+
24+
assert.match(child.stderr, /INTENTIONAL_CALLBACK_THROW/,
25+
'setupHistory callback error did NOT propagate');
26+

0 commit comments

Comments
 (0)