cli: print NODE_OPTIONS when DEBUG=cypress... is used, close #1673 (#1675)

This commit is contained in:
Gleb Bahmutov
2018-05-15 15:51:10 -04:00
committed by Jennifer Shehane
parent 1f1935b361
commit 8188a44192
3 changed files with 76 additions and 0 deletions

View File

@@ -171,6 +171,7 @@ module.exports = {
})
debug('cli starts with arguments %j', args)
util.printNodeOptions()
// if there are no arguments
if (args.length <= 2) {

View File

@@ -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
},

View File

@@ -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')
})
})
})
})