|
1 | 1 | const t = require('tap') |
2 | | -const requireInject = require('require-inject') |
3 | | -const isWindows = require('../lib/is-windows.js') |
| 2 | +const { resolve, delimiter } = require('path').posix |
4 | 3 |
|
5 | | -if (!process.env.__FAKE_TESTING_PLATFORM__) { |
6 | | - const fake = isWindows ? 'posix' : 'win32' |
7 | | - t.spawn(process.execPath, [__filename, fake], { env: { |
8 | | - ...process.env, |
9 | | - __FAKE_TESTING_PLATFORM__: fake, |
10 | | - } }) |
11 | | -} |
| 4 | +const setPATH = t.mock('../lib/set-path.js', { |
| 5 | + // Always use posix path functions so tests are consistent |
| 6 | + path: require('path').posix, |
| 7 | +}) |
12 | 8 |
|
13 | | -if (isWindows) { |
14 | | - const setPATH = requireInject('../lib/set-path.js', { |
15 | | - path: require('path').win32, |
16 | | - }) |
17 | | - const expect = [ |
18 | | - 'c:\\x\\y\\z\\node_modules\\a\\node_modules\\b\\node_modules\\.bin', |
19 | | - 'c:\\x\\y\\z\\node_modules\\a\\node_modules\\node_modules\\.bin', |
20 | | - 'c:\\x\\y\\z\\node_modules\\a\\node_modules\\.bin', |
21 | | - 'c:\\x\\y\\z\\node_modules\\node_modules\\.bin', |
22 | | - 'c:\\x\\y\\z\\node_modules\\.bin', |
23 | | - 'c:\\x\\y\\node_modules\\.bin', |
24 | | - 'c:\\x\\node_modules\\.bin', |
25 | | - 'c:\\node_modules\\.bin', |
26 | | - require('path').win32.resolve(__dirname, '../lib/node-gyp-bin'), |
27 | | - 'c:\\usr\\local\\bin', |
28 | | - 'c:\\usr\\local\\sbin', |
29 | | - 'c:\\usr\\bin', |
30 | | - 'c:\\usr\\sbin', |
31 | | - 'c:\\bin', |
32 | | - 'c:\\sbin', |
33 | | - ].join(';') |
34 | | - t.strictSame(setPATH('c:\\x\\y\\z\\node_modules\\a\\node_modules\\b', { |
| 9 | +const paths = [ |
| 10 | + '/x/y/z/node_modules/a/node_modules/b/node_modules/.bin', |
| 11 | + '/x/y/z/node_modules/a/node_modules/node_modules/.bin', |
| 12 | + '/x/y/z/node_modules/a/node_modules/.bin', |
| 13 | + '/x/y/z/node_modules/node_modules/.bin', |
| 14 | + '/x/y/z/node_modules/.bin', |
| 15 | + '/x/y/node_modules/.bin', |
| 16 | + '/x/node_modules/.bin', |
| 17 | + '/node_modules/.bin', |
| 18 | + resolve(__dirname, '../lib/node-gyp-bin'), |
| 19 | + '/usr/local/bin', |
| 20 | + '/usr/local/sbin', |
| 21 | + '/usr/bin', |
| 22 | + '/usr/sbin', |
| 23 | + '/bin', |
| 24 | + '/sbin', |
| 25 | +] |
| 26 | +t.test('no binPaths', async t => { |
| 27 | + const projectPath = '/x/y/z/node_modules/a/node_modules/b' |
| 28 | + t.strictSame(setPATH(projectPath, false, { |
35 | 29 | foo: 'bar', |
36 | | - PATH: 'c:\\usr\\local\\bin;c:\\usr\\local\\sbin', |
37 | | - Path: 'c:\\usr\\local\\bin;c:\\usr\\bin;c:\\usr\\sbin;c:\\bin;c:\\sbin', |
| 30 | + PATH: '/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin', |
38 | 31 | }), { |
39 | 32 | foo: 'bar', |
40 | | - PATH: expect, |
41 | | - Path: expect, |
| 33 | + PATH: paths.join(delimiter), |
42 | 34 | }) |
43 | | -} else { |
44 | | - const setPATH = requireInject('../lib/set-path.js', { |
45 | | - path: require('path').posix, |
46 | | - }) |
47 | | - t.strictSame(setPATH('/x/y/z/node_modules/a/node_modules/b', { |
| 35 | +}) |
| 36 | + |
| 37 | +t.test('binPaths end up at beginning of PATH', async t => { |
| 38 | + const projectPath = '/x/y/z/node_modules/a/node_modules/b' |
| 39 | + const binPaths = [ |
| 40 | + '/q/r/s/node_modules/.bin', |
| 41 | + '/t/u/v/node_modules/.bin', |
| 42 | + ] |
| 43 | + t.strictSame(setPATH(projectPath, binPaths, { |
48 | 44 | foo: 'bar', |
49 | 45 | PATH: '/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin', |
50 | 46 | }), { |
51 | 47 | foo: 'bar', |
52 | | - PATH: |
53 | | - '/x/y/z/node_modules/a/node_modules/b/node_modules/.bin:' + |
54 | | - '/x/y/z/node_modules/a/node_modules/node_modules/.bin:' + |
55 | | - '/x/y/z/node_modules/a/node_modules/.bin:' + |
56 | | - '/x/y/z/node_modules/node_modules/.bin:' + |
57 | | - '/x/y/z/node_modules/.bin:' + |
58 | | - '/x/y/node_modules/.bin:' + |
59 | | - '/x/node_modules/.bin:' + |
60 | | - '/node_modules/.bin:' + |
61 | | - require('path').posix.resolve(__dirname, '../lib/node-gyp-bin') + ':' + |
62 | | - '/usr/local/bin:' + |
63 | | - '/usr/local/sbin:' + |
64 | | - '/usr/bin:' + |
65 | | - '/usr/sbin:' + |
66 | | - '/bin:' + |
67 | | - '/sbin', |
| 48 | + PATH: [ |
| 49 | + ...binPaths, |
| 50 | + ...paths, |
| 51 | + ].join(delimiter), |
68 | 52 | }) |
69 | | -} |
| 53 | +}) |
0 commit comments