0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-repl-require-context.js
Rich Trott 950ef82aaf test: simplify output handling in repl tests
Replace .map() + .replace().trim() with a single .replace().

PR-URL: https://github.com/nodejs/node/pull/11124
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
2017-02-05 12:27:07 -08:00

26 lines
876 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
const path = require('path');
const child = cp.spawn(process.execPath, ['--interactive']);
const fixture = path.join(common.fixturesDir, 'is-object.js').replace(/\\/g,
'/');
let output = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', (data) => {
output += data;
});
child.on('exit', common.mustCall(() => {
const results = output.replace(/^> /mg, '').split('\n');
assert.deepStrictEqual(results, ['undefined', 'true', 'true', '']);
}));
child.stdin.write('const isObject = (obj) => obj.constructor === Object;\n');
child.stdin.write('isObject({});\n');
child.stdin.write(`require('${fixture}').isObject({});\n`);
child.stdin.write('.exit');
child.stdin.end();