Skip to content

Commit

Permalink
cli: print NODE_OPTIONS when DEBUG=cypress... is used, close #1673 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov authored and jennifer-shehane committed May 15, 2018
1 parent 1f1935b commit 8188a44
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions cli/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ module.exports = {
})

debug('cli starts with arguments %j', args)
util.printNodeOptions()

// if there are no arguments
if (args.length <= 2) {
Expand Down
19 changes: 19 additions & 0 deletions cli/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`

Expand Down Expand Up @@ -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
},
Expand Down
56 changes: 56 additions & 0 deletions cli/test/lib/util_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
})
})

0 comments on commit 8188a44

Please sign in to comment.