node/test/parallel/test-repl-require-self-referential.js
Daniele Belardi ec2ffd6b9d module: self referential modules in repl or -r
Load self referential modules from the repl and using the preload flag
`-r`. In both cases the base path used for resolution is the current
`process.cwd()`. Also fixes an internal cycle bug in the REPL exports
resolution.

PR-URL: https://github.com/nodejs/node/pull/32261
Fixes: https://github.com/nodejs/node/issues/31595
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
2020-07-23 07:50:01 -07:00

26 lines
794 B
JavaScript

'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const { spawn } = require('child_process');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
const selfRefModule = fixtures.path('self_ref_module');
const child = spawn(process.execPath,
['--interactive'],
{ cwd: selfRefModule }
);
let output = '';
child.stdout.on('data', (chunk) => output += chunk);
child.on('exit', common.mustCall(() => {
const results = output.replace(/^> /mg, '').split('\n').slice(2);
assert.deepStrictEqual(results, [ "'Self resolution working'", '' ]);
}));
child.stdin.write('require("self_ref");\n');
child.stdin.write('.exit');
child.stdin.end();