diff options
Diffstat (limited to 'deps/npm/test/tap/lifecycle-path.js')
-rw-r--r-- | deps/npm/test/tap/lifecycle-path.js | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/deps/npm/test/tap/lifecycle-path.js b/deps/npm/test/tap/lifecycle-path.js index 39761b48d7..3264fe87be 100644 --- a/deps/npm/test/tap/lifecycle-path.js +++ b/deps/npm/test/tap/lifecycle-path.js @@ -7,54 +7,45 @@ var rimraf = require('rimraf') var test = require('tap').test var common = require('../common-tap.js') +var isWindows = require('../../lib/utils/is-windows.js') var pkg = path.resolve(__dirname, 'lifecycle-path') -var link = path.resolve(pkg, 'node-bin') var PATH -if (process.platform === 'win32') { +if (isWindows) { // On Windows the 'comspec' environment variable is used, // so cmd.exe does not need to be on the path. - PATH = 'C:\\foo\\bar' + PATH = path.dirname(process.env.ComSpec) } else { // On non-Windows, without the path to the shell, nothing usually works. PATH = '/bin:/usr/bin' } -var printPath = 'console.log(process.env.PATH)\n' - -var json = { - name: 'glorb', - version: '1.2.3', - scripts: { - path: './node-bin/node print-path.js' - } -} - test('setup', function (t) { cleanup() mkdirp.sync(pkg) fs.writeFileSync( path.join(pkg, 'package.json'), - JSON.stringify(json, null, 2) + JSON.stringify({}, null, 2) ) - fs.writeFileSync(path.join(pkg, 'print-path.js'), printPath) - fs.symlinkSync(path.dirname(process.execPath), link, 'dir') t.end() }) test('make sure the path is correct', function (t) { - common.npm(['run-script', 'path'], { + common.npm(['run-script', 'env'], { cwd: pkg, env: { - PATH: PATH, - stdio: [ 0, 'pipe', 2 ] - } + PATH: PATH + }, + stdio: [ 0, 'pipe', 2 ] }, function (er, code, stdout) { if (er) throw er t.equal(code, 0, 'exit code') - // remove the banner, we just care about the last line - stdout = stdout.trim().split(/\r|\n/).pop() + var lineMatch = function (line) { + return /^PATH=/i.test(line) + } + // extract just the path value + stdout = stdout.split(/\r?\n/).filter(lineMatch).pop().replace(/^PATH=/, '') var pathSplit = process.platform === 'win32' ? ';' : ':' var root = path.resolve(__dirname, '../..') var actual = stdout.split(pathSplit).map(function (p) { @@ -63,15 +54,19 @@ test('make sure the path is correct', function (t) { } return p.replace(/\\/g, '/') }) + // spawn-wrap adds itself to the path when coverage is enabled + actual = actual.filter(function (p) { + return !p.match(/\.node-spawn-wrap/) + }) // get the ones we tacked on, then the system-specific requirements var expect = [ '{{ROOT}}/bin/node-gyp-bin', '{{ROOT}}/test/tap/lifecycle-path/node_modules/.bin', path.dirname(process.execPath) - ].concat(PATH.split(pathSplit).map(function (p) { + ].concat(PATH.split(pathSplit)).map(function (p) { return p.replace(/\\/g, '/') - })) + }) t.same(actual, expect) t.end() }) |