mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
This makes sure multiple require calls will not fail in case a file was created after the first attempt. PR-URL: https://github.com/nodejs/node/pull/26928 Fixes: https://github.com/nodejs/node/issues/26926 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com>
26 lines
712 B
JavaScript
26 lines
712 B
JavaScript
'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);
|