-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-repl-require-after-write.js
More file actions
31 lines (23 loc) · 866 Bytes
/
test-repl-require-after-write.js
File metadata and controls
31 lines (23 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict';
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const spawn = require('child_process').spawn;
const path = require('path');
tmpdir.refresh();
const requirePath = JSON.stringify(path.join(tmpdir.path, 'non-existent.json'));
// 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(${requirePath}); } catch {} ` +
`require('fs').writeFileSync(${requirePath}, '1');` +
`require(${requirePath});`;
child.stderr.on('data', common.mustNotCall());
child.stdout.setEncoding('utf8');
child.stdout.on('data', (c) => {
out += c;
});
child.stdout.on('end', common.mustCall(() => {
assert.ok(out.endsWith('> 1\n> '));
}));
child.stdin.end(input);