2 var path = require('path')
4 var mkdirp = require('mkdirp')
5 var osenv = require('osenv')
6 var rimraf = require('rimraf')
7 var test = require('tap').test
9 var common = require('../common-tap.js')
11 var pkg = path.resolve(__dirname, 'lifecycle-path')
12 var link = path.resolve(pkg, 'node-bin')
15 if (process.platform === 'win32') {
16 // On Windows the 'comspec' environment variable is used,
17 // so cmd.exe does not need to be on the path.
20 // On non-Windows, without the path to the shell, nothing usually works.
21 PATH = '/bin:/usr/bin'
24 var printPath = 'console.log(process.env.PATH)\n'
30 path: './node-bin/node print-path.js'
34 test('setup', function (t) {
38 path.join(pkg, 'package.json'),
39 JSON.stringify(json, null, 2)
41 fs.writeFileSync(path.join(pkg, 'print-path.js'), printPath)
42 fs.symlinkSync(path.dirname(process.execPath), link, 'dir')
46 test('make sure the path is correct', function (t) {
47 common.npm(['run-script', 'path'], {
51 stdio: [ 0, 'pipe', 2 ]
53 }, function (er, code, stdout) {
55 t.equal(code, 0, 'exit code')
56 // remove the banner, we just care about the last line
57 stdout = stdout.trim().split(/\r|\n/).pop()
58 var pathSplit = process.platform === 'win32' ? ';' : ':'
59 var root = path.resolve(__dirname, '../..')
60 var actual = stdout.split(pathSplit).map(function (p) {
61 if (p.indexOf(root) === 0) {
62 p = '{{ROOT}}' + p.substr(root.length)
64 return p.replace(/\\/g, '/')
67 // get the ones we tacked on, then the system-specific requirements
69 '{{ROOT}}/bin/node-gyp-bin',
70 '{{ROOT}}/test/tap/lifecycle-path/node_modules/.bin',
71 path.dirname(process.execPath)
72 ].concat(PATH.split(pathSplit).map(function (p) {
73 return p.replace(/\\/g, '/')
75 t.same(actual, expect)
80 test('cleanup', function (t) {
86 process.chdir(osenv.tmpdir())