Skip to content

Commit d39bae6

Browse files
committed
fixup!
1 parent 1690897 commit d39bae6

3 files changed

Lines changed: 46 additions & 72 deletions

File tree

test/parallel/test-repl-autolibs.js

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as common from '../common/index.mjs';
2+
import { startNewREPLServer } from '../common/repl.js';
3+
import assert from 'node:assert';
4+
import util from 'node:util';
5+
import { createRequire } from 'node:module';
6+
7+
const require = createRequire(import.meta.url);
8+
9+
const { output, run } = startNewREPLServer({ useGlobal: true, terminal: false });
10+
11+
// Referencing a builtin by bare name auto-requires it onto the real global,
12+
// and the value is identity-equal to the normally-required module.
13+
{
14+
output.accumulator = '';
15+
await run(['fs']);
16+
assert.strictEqual(output.accumulator,
17+
`${util.inspect(require('fs'), null, 2, false)}\n`);
18+
assert.strictEqual(globalThis.fs, require('fs'));
19+
}
20+
21+
// A user-defined global with a builtin's name is NOT overwritten by the
22+
// auto-require, and the REPL prints the user's value.
23+
{
24+
const val = {};
25+
globalThis.url = val;
26+
common.allowGlobals(val);
27+
28+
output.accumulator = '';
29+
await run(['url']);
30+
assert.strictEqual(output.accumulator, '{}\n');
31+
assert.strictEqual(val, globalThis.url);
32+
}

test/parallel/test-repl-tab-complete-on-editor-mode.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,19 @@ const { startNewREPLServer } = require('../common/repl');
2929
replServer.write('.editor\n');
3030

3131
replServer.write('a');
32-
replServer.write(null, { name: 'tab' }); // Should not throw
3332

34-
replServer.close();
33+
// Tab completion is asynchronous (it is driven by the inspector), so the
34+
// REPL must only be closed once the completion has settled. Closing it while
35+
// a completion is still in flight would make the completion callback resume a
36+
// closed readline interface and throw `ERR_USE_AFTER_CLOSE`.
37+
const originalCompleter = replServer.completer;
38+
replServer.completer = common.mustCall((text, cb) => {
39+
originalCompleter.call(replServer, text, common.mustCall((...args) => {
40+
const result = cb(...args);
41+
replServer.close();
42+
return result;
43+
}));
44+
});
45+
46+
replServer.write(null, { name: 'tab' }); // Should not throw
3547
}

0 commit comments

Comments
 (0)