From 8c0f776f23e54814c95a1c8fa68bcf2f1d62c2f6 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 19 Jul 2016 11:36:15 -0400 Subject: [PATCH] test: add known issue test for #7788 15157c3c3d7594cefb7f5941cbe925657e7d88bd changed the CLI REPL to default to useGlobal: false by default. This caused the regression seen in https://github.com/nodejs/node/issues/7788. This commit adds a known issue test while a proper resolution is determined. Refs: https://github.com/nodejs/node/pull/5703 Refs: https://github.com/nodejs/node/issues/7788 PR-URL: https://github.com/nodejs/node/pull/7793 Reviewed-By: Rich Trott --- test/fixtures/is-object.js | 2 ++ .../known_issues/test-repl-require-context.js | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/fixtures/is-object.js create mode 100644 test/known_issues/test-repl-require-context.js diff --git a/test/fixtures/is-object.js b/test/fixtures/is-object.js new file mode 100644 index 00000000000000..c283221e965123 --- /dev/null +++ b/test/fixtures/is-object.js @@ -0,0 +1,2 @@ +'use strict'; +module.exports.isObject = (obj) => obj.constructor === Object; diff --git a/test/known_issues/test-repl-require-context.js b/test/known_issues/test-repl-require-context.js new file mode 100644 index 00000000000000..2c9195d940e2e4 --- /dev/null +++ b/test/known_issues/test-repl-require-context.js @@ -0,0 +1,32 @@ +'use strict'; +// Refs: https://github.com/nodejs/node/issues/7788 +const common = require('../common'); +const assert = require('assert'); +const path = require('path'); +const repl = require('repl'); +const stream = require('stream'); +const inputStream = new stream.PassThrough(); +const outputStream = new stream.PassThrough(); +const fixture = path.join(common.fixturesDir, 'is-object.js'); +const r = repl.start({ + input: inputStream, + output: outputStream, + useGlobal: false +}); + +let output = ''; +outputStream.setEncoding('utf8'); +outputStream.on('data', (data) => output += data); + +r.on('exit', common.mustCall(() => { + const results = output.split('\n').map((line) => { + return line.replace(/\w*>\w*/, '').trim(); + }); + + assert.deepStrictEqual(results, ['undefined', 'true', 'true', '']); +})); + +inputStream.write('const isObject = (obj) => obj.constructor === Object;\n'); +inputStream.write('isObject({});\n'); +inputStream.write(`require('${fixture}').isObject({});\n`); +r.close();