11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ciconst spawn = require('child_process').spawn;
71cb0ef41Sopenharmony_ciconst path = require('path');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_citmpdir.refresh();
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst requirePath = JSON.stringify(path.join(tmpdir.path, 'non-existent.json'));
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci// Use -i to force node into interactive mode, despite stdout not being a TTY
141cb0ef41Sopenharmony_ciconst child = spawn(process.execPath, ['-i']);
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_cilet out = '';
171cb0ef41Sopenharmony_ciconst input = `try { require(${requirePath}); } catch {} ` +
181cb0ef41Sopenharmony_ci              `require('fs').writeFileSync(${requirePath}, '1');` +
191cb0ef41Sopenharmony_ci              `require(${requirePath});`;
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_cichild.stderr.on('data', common.mustNotCall());
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_cichild.stdout.setEncoding('utf8');
241cb0ef41Sopenharmony_cichild.stdout.on('data', (c) => {
251cb0ef41Sopenharmony_ci  out += c;
261cb0ef41Sopenharmony_ci});
271cb0ef41Sopenharmony_cichild.stdout.on('end', common.mustCall(() => {
281cb0ef41Sopenharmony_ci  assert.ok(out.endsWith('> 1\n> '));
291cb0ef41Sopenharmony_ci}));
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_cichild.stdin.end(input);
32