mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
Currently, the test creates a file in the cwd and doesn't clean it up. Use a temporary directory instead. PR-URL: https://github.com/nodejs/node/pull/27088 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
32 lines
866 B
JavaScript
32 lines
866 B
JavaScript
'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.strictEqual(out, '> 1\n> ');
|
|
}));
|
|
|
|
child.stdin.end(input);
|