1// Copyright Joyent, Inc. and other Node contributors. 2// 3// Permission is hereby granted, free of charge, to any person obtaining a 4// copy of this software and associated documentation files (the 5// "Software"), to deal in the Software without restriction, including 6// without limitation the rights to use, copy, modify, merge, publish, 7// distribute, sublicense, and/or sell copies of the Software, and to permit 8// persons to whom the Software is furnished to do so, subject to the 9// following conditions: 10// 11// The above copyright notice and this permission notice shall be included 12// in all copies or substantial portions of the Software. 13// 14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20// USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22'use strict'; 23 24const common = require('../common'); 25const assert = require('assert'); 26const _module = require('module'); 27 28const cases = { 29 'WIN': [{ 30 file: 'C:\\Users\\hefangshi\\AppData\\Roaming\ 31\\npm\\node_modules\\npm\\node_modules\\minimatch', 32 expect: [ 33 'C:\\Users\\hefangshi\\AppData\\Roaming\ 34\\npm\\node_modules\\npm\\node_modules\\minimatch\\node_modules', 35 'C:\\Users\\hefangshi\\AppData\\Roaming\ 36\\npm\\node_modules\\npm\\node_modules', 37 'C:\\Users\\hefangshi\\AppData\\Roaming\\npm\\node_modules', 38 'C:\\Users\\hefangshi\\AppData\\Roaming\\node_modules', 39 'C:\\Users\\hefangshi\\AppData\\node_modules', 40 'C:\\Users\\hefangshi\\node_modules', 41 'C:\\Users\\node_modules', 42 'C:\\node_modules', 43 ] 44 }, { 45 file: 'C:\\Users\\Rocko Artischocko\\node_stuff\\foo', 46 expect: [ 47 'C:\\Users\\Rocko Artischocko\\node_stuff\\foo\\node_modules', 48 'C:\\Users\\Rocko Artischocko\\node_stuff\\node_modules', 49 'C:\\Users\\Rocko Artischocko\\node_modules', 50 'C:\\Users\\node_modules', 51 'C:\\node_modules', 52 ] 53 }, { 54 file: 'C:\\Users\\Rocko Artischocko\\node_stuff\\foo_node_modules', 55 expect: [ 56 'C:\\Users\\Rocko \ 57Artischocko\\node_stuff\\foo_node_modules\\node_modules', 58 'C:\\Users\\Rocko Artischocko\\node_stuff\\node_modules', 59 'C:\\Users\\Rocko Artischocko\\node_modules', 60 'C:\\Users\\node_modules', 61 'C:\\node_modules', 62 ] 63 }, { 64 file: 'C:\\node_modules', 65 expect: [ 66 'C:\\node_modules', 67 ] 68 }, { 69 file: 'C:\\', 70 expect: [ 71 'C:\\node_modules', 72 ] 73 }], 74 'POSIX': [{ 75 file: '/usr/lib/node_modules/npm/node_modules/\ 76node-gyp/node_modules/glob/node_modules/minimatch', 77 expect: [ 78 '/usr/lib/node_modules/npm/node_modules/\ 79node-gyp/node_modules/glob/node_modules/minimatch/node_modules', 80 '/usr/lib/node_modules/npm/node_modules/\ 81node-gyp/node_modules/glob/node_modules', 82 '/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules', 83 '/usr/lib/node_modules/npm/node_modules', 84 '/usr/lib/node_modules', 85 '/usr/node_modules', 86 '/node_modules', 87 ] 88 }, { 89 file: '/usr/test/lib/node_modules/npm/foo', 90 expect: [ 91 '/usr/test/lib/node_modules/npm/foo/node_modules', 92 '/usr/test/lib/node_modules/npm/node_modules', 93 '/usr/test/lib/node_modules', 94 '/usr/test/node_modules', 95 '/usr/node_modules', 96 '/node_modules', 97 ] 98 }, { 99 file: '/usr/test/lib/node_modules/npm/foo_node_modules', 100 expect: [ 101 '/usr/test/lib/node_modules/npm/foo_node_modules/node_modules', 102 '/usr/test/lib/node_modules/npm/node_modules', 103 '/usr/test/lib/node_modules', 104 '/usr/test/node_modules', 105 '/usr/node_modules', 106 '/node_modules', 107 ] 108 }, { 109 file: '/node_modules', 110 expect: [ 111 '/node_modules', 112 ] 113 }, { 114 file: '/', 115 expect: [ 116 '/node_modules', 117 ] 118 }] 119}; 120 121const platformCases = common.isWindows ? cases.WIN : cases.POSIX; 122platformCases.forEach((c) => { 123 const paths = _module._nodeModulePaths(c.file); 124 assert.deepStrictEqual( 125 c.expect, paths, 126 `case ${c.file} failed, actual paths is ${JSON.stringify(paths)}`); 127}); 128