Add specs for Module._nodeModulesPath
This commit is contained in:
Родитель
d959ccb47c
Коммит
eed240be1c
|
@ -1,4 +1,5 @@
|
|||
const assert = require('assert')
|
||||
const Module = require('module')
|
||||
const path = require('path')
|
||||
const temp = require('temp')
|
||||
|
||||
|
@ -47,3 +48,50 @@ describe('third-party module', function () {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Module._nodeModulePaths', function () {
|
||||
describe('when the path is inside the resources path', function () {
|
||||
it('does not include paths outside of the resources path', function () {
|
||||
let modulePath = process.resourcesPath
|
||||
assert.deepEqual(Module._nodeModulePaths(modulePath), [
|
||||
path.join(process.resourcesPath, 'node_modules')
|
||||
])
|
||||
|
||||
modulePath = path.join(process.resourcesPath, 'foo')
|
||||
assert.deepEqual(Module._nodeModulePaths(modulePath), [
|
||||
path.join(process.resourcesPath, 'foo', 'node_modules'),
|
||||
path.join(process.resourcesPath, 'node_modules')
|
||||
])
|
||||
|
||||
modulePath = path.join(process.resourcesPath, 'node_modules', 'foo')
|
||||
assert.deepEqual(Module._nodeModulePaths(modulePath), [
|
||||
path.join(process.resourcesPath, 'node_modules', 'foo', 'node_modules'),
|
||||
path.join(process.resourcesPath, 'node_modules')
|
||||
])
|
||||
|
||||
modulePath = path.join(process.resourcesPath, 'node_modules', 'foo', 'bar')
|
||||
assert.deepEqual(Module._nodeModulePaths(modulePath), [
|
||||
path.join(process.resourcesPath, 'node_modules', 'foo', 'bar', 'node_modules'),
|
||||
path.join(process.resourcesPath, 'node_modules', 'foo', 'node_modules'),
|
||||
path.join(process.resourcesPath, 'node_modules')
|
||||
])
|
||||
|
||||
modulePath = path.join(process.resourcesPath, 'node_modules', 'foo', 'node_modules', 'bar')
|
||||
assert.deepEqual(Module._nodeModulePaths(modulePath), [
|
||||
path.join(process.resourcesPath, 'node_modules', 'foo', 'node_modules', 'bar', 'node_modules'),
|
||||
path.join(process.resourcesPath, 'node_modules', 'foo', 'node_modules'),
|
||||
path.join(process.resourcesPath, 'node_modules')
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the path is outside the resources path', function () {
|
||||
it('includes paths outside of the resources path', function () {
|
||||
let modulePath = path.resolve('/foo')
|
||||
assert.deepEqual(Module._nodeModulePaths(modulePath), [
|
||||
path.join(modulePath, 'node_modules'),
|
||||
path.join('node_modules')
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Загрузка…
Ссылка в новой задаче