]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/lifecycle-path.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / lifecycle-path.js
1 var fs = require('fs')
2 var path = require('path')
3
4 var mkdirp = require('mkdirp')
5 var osenv = require('osenv')
6 var rimraf = require('rimraf')
7 var test = require('tap').test
8
9 var common = require('../common-tap.js')
10
11 var pkg = path.resolve(__dirname, 'lifecycle-path')
12 var link = path.resolve(pkg, 'node-bin')
13
14 var PATH
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.
18   PATH = 'C:\\foo\\bar'
19 } else {
20   // On non-Windows, without the path to the shell, nothing usually works.
21   PATH = '/bin:/usr/bin'
22 }
23
24 var printPath = 'console.log(process.env.PATH)\n'
25
26 var json = {
27   name: 'glorb',
28   version: '1.2.3',
29   scripts: {
30     path: './node-bin/node print-path.js'
31   }
32 }
33
34 test('setup', function (t) {
35   cleanup()
36   mkdirp.sync(pkg)
37   fs.writeFileSync(
38     path.join(pkg, 'package.json'),
39     JSON.stringify(json, null, 2)
40   )
41   fs.writeFileSync(path.join(pkg, 'print-path.js'), printPath)
42   fs.symlinkSync(path.dirname(process.execPath), link, 'dir')
43   t.end()
44 })
45
46 test('make sure the path is correct', function (t) {
47   common.npm(['run-script', 'path'], {
48     cwd: pkg,
49     env: {
50       PATH: PATH,
51       stdio: [ 0, 'pipe', 2 ]
52     }
53   }, function (er, code, stdout) {
54     if (er) throw er
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)
63       }
64       return p.replace(/\\/g, '/')
65     })
66
67     // get the ones we tacked on, then the system-specific requirements
68     var expect = [
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, '/')
74     }))
75     t.same(actual, expect)
76     t.end()
77   })
78 })
79
80 test('cleanup', function (t) {
81   cleanup()
82   t.end()
83 })
84
85 function cleanup () {
86   process.chdir(osenv.tmpdir())
87   rimraf.sync(pkg)
88 }