forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: fix repl require calling the same file again
This makes sure multiple require calls will not fail in case a file was created after the first attempt. PR-URL: nodejs#26928 Fixes: nodejs#26926 Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Jan Krems <[email protected]>
- Loading branch information
Showing
2 changed files
with
34 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const spawn = require('child_process').spawn; | ||
// Use -i to force node into interactive mode, despite stdout not being a TTY | ||
const child = spawn(process.execPath, ['-i']); | ||
|
||
let out = ''; | ||
const input = "try { require('./non-existent.json'); } catch {} " + | ||
"require('fs').writeFileSync('./non-existent.json', '1');" + | ||
"require('./non-existent.json');"; | ||
|
||
child.stderr.on('data', common.mustNotCall()); | ||
|
||
child.stdout.setEncoding('utf8'); | ||
child.stdout.on('data', (c) => { | ||
out += c; | ||
}); | ||
child.stdout.on('end', common.mustCall(() => { | ||
assert.strictEqual(out, '> 1\n> '); | ||
})); | ||
|
||
child.stdin.end(input); |