|
1 | 1 | 'use strict';
|
2 |
| -var common = require('../common'); |
3 |
| -var assert = require('assert'); |
4 | 2 |
|
5 |
| -var module = require('module'); |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const _module = require('module'); |
6 | 6 |
|
7 |
| -var file, delimiter, paths; |
| 7 | +const cases = { |
| 8 | + 'WIN': [{ |
| 9 | + file: 'C:\\Users\\hefangshi\\AppData\\Roaming\ |
| 10 | +\\npm\\node_modules\\npm\\node_modules\\minimatch', |
| 11 | + expect: [ |
| 12 | + 'C:\\Users\\hefangshi\\AppData\\Roaming\ |
| 13 | +\\npm\\node_modules\\npm\\node_modules\\minimatch\\node_modules', |
| 14 | + 'C:\\Users\\hefangshi\\AppData\\Roaming\ |
| 15 | +\\npm\\node_modules\\npm\\node_modules', |
| 16 | + 'C:\\Users\\hefangshi\\AppData\\Roaming\\npm\\node_modules', |
| 17 | + 'C:\\Users\\hefangshi\\AppData\\Roaming\\node_modules', |
| 18 | + 'C:\\Users\\hefangshi\\AppData\\node_modules', |
| 19 | + 'C:\\Users\\hefangshi\\node_modules', |
| 20 | + 'C:\\Users\\node_modules', |
| 21 | + 'C:\\node_modules' |
| 22 | + ] |
| 23 | + }, { |
| 24 | + file: 'C:\\Users\\Rocko Artischocko\\node_stuff\\foo', |
| 25 | + expect: [ |
| 26 | + 'C:\\Users\\Rocko Artischocko\\node_stuff\\foo\\node_modules', |
| 27 | + 'C:\\Users\\Rocko Artischocko\\node_stuff\\node_modules', |
| 28 | + 'C:\\Users\\Rocko Artischocko\\node_modules', |
| 29 | + 'C:\\Users\\node_modules', |
| 30 | + 'C:\\node_modules' |
| 31 | + ] |
| 32 | + }, { |
| 33 | + file: 'C:\\Users\\Rocko Artischocko\\node_stuff\\foo_node_modules', |
| 34 | + expect: [ |
| 35 | + 'C:\\Users\\Rocko \ |
| 36 | +Artischocko\\node_stuff\\foo_node_modules\\node_modules', |
| 37 | + 'C:\\Users\\Rocko Artischocko\\node_stuff\\node_modules', |
| 38 | + 'C:\\Users\\Rocko Artischocko\\node_modules', |
| 39 | + 'C:\\Users\\node_modules', |
| 40 | + 'C:\\node_modules' |
| 41 | + ] |
| 42 | + }, { |
| 43 | + file: 'C:\\node_modules', |
| 44 | + expect: [ |
| 45 | + 'C:\\node_modules' |
| 46 | + ] |
| 47 | + }, { |
| 48 | + file: 'C:\\', |
| 49 | + expect: [ |
| 50 | + 'C:\\node_modules' |
| 51 | + ] |
| 52 | + }], |
| 53 | + 'POSIX': [{ |
| 54 | + file: '/usr/lib/node_modules/npm/node_modules/\ |
| 55 | +node-gyp/node_modules/glob/node_modules/minimatch', |
| 56 | + expect: [ |
| 57 | + '/usr/lib/node_modules/npm/node_modules/\ |
| 58 | +node-gyp/node_modules/glob/node_modules/minimatch/node_modules', |
| 59 | + '/usr/lib/node_modules/npm/node_modules/\ |
| 60 | +node-gyp/node_modules/glob/node_modules', |
| 61 | + '/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules', |
| 62 | + '/usr/lib/node_modules/npm/node_modules', |
| 63 | + '/usr/lib/node_modules', |
| 64 | + '/usr/node_modules', |
| 65 | + '/node_modules' |
| 66 | + ] |
| 67 | + }, { |
| 68 | + file: '/usr/test/lib/node_modules/npm/foo', |
| 69 | + expect: [ |
| 70 | + '/usr/test/lib/node_modules/npm/foo/node_modules', |
| 71 | + '/usr/test/lib/node_modules/npm/node_modules', |
| 72 | + '/usr/test/lib/node_modules', |
| 73 | + '/usr/test/node_modules', |
| 74 | + '/usr/node_modules', |
| 75 | + '/node_modules' |
| 76 | + ] |
| 77 | + }, { |
| 78 | + file: '/usr/test/lib/node_modules/npm/foo_node_modules', |
| 79 | + expect: [ |
| 80 | + '/usr/test/lib/node_modules/npm/foo_node_modules/node_modules', |
| 81 | + '/usr/test/lib/node_modules/npm/node_modules', |
| 82 | + '/usr/test/lib/node_modules', |
| 83 | + '/usr/test/node_modules', |
| 84 | + '/usr/node_modules', |
| 85 | + '/node_modules' |
| 86 | + ] |
| 87 | + }, { |
| 88 | + file: '/node_modules', |
| 89 | + expect: [ |
| 90 | + '/node_modules' |
| 91 | + ] |
| 92 | + }, { |
| 93 | + file: '/', |
| 94 | + expect: [ |
| 95 | + '/node_modules' |
| 96 | + ] |
| 97 | + }] |
| 98 | +}; |
8 | 99 |
|
9 |
| -if (common.isWindows) { |
10 |
| - file = 'C:\\Users\\Rocko Artischocko\\node_stuff\\foo'; |
11 |
| - delimiter = '\\'; |
12 |
| -} else { |
13 |
| - file = '/usr/test/lib/node_modules/npm/foo'; |
14 |
| - delimiter = '/'; |
15 |
| -} |
16 |
| - |
17 |
| -paths = module._nodeModulePaths(file); |
18 |
| - |
19 |
| -assert.ok(paths.indexOf(file + delimiter + 'node_modules') !== -1); |
20 |
| -assert.ok(Array.isArray(paths)); |
| 100 | +const platformCases = common.isWindows ? cases.WIN : cases.POSIX; |
| 101 | +platformCases.forEach((c) => { |
| 102 | + const paths = _module._nodeModulePaths(c.file); |
| 103 | + assert.deepStrictEqual(c.expect, paths, 'case ' + c.file + |
| 104 | + ' failed, actual paths is ' + JSON.stringify(paths)); |
| 105 | +}); |
0 commit comments