From 8188a4419201d44b45f416b8bd32fa90f87544c3 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Tue, 15 May 2018 15:51:10 -0400 Subject: [PATCH] cli: print NODE_OPTIONS when DEBUG=cypress... is used, close #1673 (#1675) --- cli/lib/cli.js | 1 + cli/lib/util.js | 19 +++++++++++++ cli/test/lib/util_spec.js | 56 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/cli/lib/cli.js b/cli/lib/cli.js index 784f7cd0a9ab..bb8e35411485 100644 --- a/cli/lib/cli.js +++ b/cli/lib/cli.js @@ -171,6 +171,7 @@ module.exports = { }) debug('cli starts with arguments %j', args) + util.printNodeOptions() // if there are no arguments if (args.length <= 2) { diff --git a/cli/lib/util.js b/cli/lib/util.js index fe45ad4ab34d..176e6d5b9f07 100644 --- a/cli/lib/util.js +++ b/cli/lib/util.js @@ -7,6 +7,7 @@ const supportsColor = require('supports-color') const isInstalledGlobally = require('is-installed-globally') const pkg = require(path.join(__dirname, '..', 'package.json')) const logger = require('./logger') +const debug = require('debug')('cypress:cli') const joinWithEq = (x, y) => `${x}=${y}` @@ -36,9 +37,27 @@ function stdoutLineMatches (expectedLine, stdout) { return lines.some(lineMatches) } +/** + * Prints NODE_OPTIONS using debug() module, but only + * if DEBUG=cypress... is set + */ +function printNodeOptions (log = debug) { + if (!log.enabled) { + return + } + + if (process.env.NODE_OPTIONS) { + log('NODE_OPTIONS=%s', process.env.NODE_OPTIONS) + } else { + log('NODE_OPTIONS is not set') + } +} + const util = { normalizeModuleOptions, + printNodeOptions, + isCi () { return isCi }, diff --git a/cli/test/lib/util_spec.js b/cli/test/lib/util_spec.js index dbf353b16779..72aa3f723ea1 100644 --- a/cli/test/lib/util_spec.js +++ b/cli/test/lib/util_spec.js @@ -139,4 +139,60 @@ describe('util', function () { expect(process.exit).to.be.calledWith(1) expect(logger.error).to.be.calledWith('foo') }) + + context('.printNodeOptions', function () { + describe('NODE_OPTIONS is not set', function () { + beforeEach(function () { + this.node_options = process.env.NODE_OPTIONS + delete process.env.NODE_OPTIONS + }) + + afterEach(function () { + if (typeof this.node_options !== 'undefined') { + process.env.NODE_OPTIONS = this.node_options + } + }) + + it('does nothing if debug is not enabled', function () { + const log = this.sandbox.spy() + log.enabled = false + util.printNodeOptions(log) + expect(log).not.have.been.called + }) + + it('prints message when debug is enabled', function () { + const log = this.sandbox.spy() + log.enabled = true + util.printNodeOptions(log) + expect(log).to.be.calledWith('NODE_OPTIONS is not set') + }) + }) + + describe('NODE_OPTIONS is set', function () { + beforeEach(function () { + this.node_options = process.env.NODE_OPTIONS + process.env.NODE_OPTIONS = 'foo' + }) + + afterEach(function () { + if (typeof this.node_options !== 'undefined') { + process.env.NODE_OPTIONS = this.node_options + } + }) + + it('does nothing if debug is not enabled', function () { + const log = this.sandbox.spy() + log.enabled = false + util.printNodeOptions(log) + expect(log).not.have.been.called + }) + + it('prints value when debug is enabled', function () { + const log = this.sandbox.spy() + log.enabled = true + util.printNodeOptions(log) + expect(log).to.be.calledWith('NODE_OPTIONS=%s', 'foo') + }) + }) + }) })