mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add spec for resolving compatible module paths
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
path = require 'path'
|
||||
Module = require 'module'
|
||||
fs = require 'fs-plus'
|
||||
temp = require 'temp'
|
||||
ModuleCache = require '../src/module-cache'
|
||||
|
||||
describe 'ModuleCache', ->
|
||||
@@ -20,3 +22,34 @@ describe 'ModuleCache', ->
|
||||
}
|
||||
expect(require('./fixtures/module-cache/file.json').foo).toBe 'bar'
|
||||
expect(Module._findPath.callCount).toBe 0
|
||||
|
||||
it 'resolves module paths to a compatible version provided by core', ->
|
||||
packagePath = fs.realpathSync(temp.mkdirSync('atom-package'))
|
||||
ModuleCache.add packagePath, {
|
||||
_atomModuleCache:
|
||||
folders: [{
|
||||
paths: [
|
||||
""
|
||||
]
|
||||
dependencies:
|
||||
'underscore-plus': '*'
|
||||
}]
|
||||
}
|
||||
ModuleCache.add atom.getLoadSettings().resourcePath, {
|
||||
_atomModuleCache:
|
||||
dependencies: [{
|
||||
name: 'underscore-plus'
|
||||
version: require('underscore-plus/package.json').version
|
||||
path: path.join('node_modules', 'underscore-plus', 'lib', 'underscore-plus.js')
|
||||
}]
|
||||
}
|
||||
|
||||
indexPath = path.join(packagePath, 'index.js')
|
||||
fs.writeFileSync indexPath, """
|
||||
exports.load = function() {require('underscore-plus');};
|
||||
"""
|
||||
|
||||
packageMain = require(indexPath)
|
||||
Module._findPath.reset()
|
||||
packageMain.load()
|
||||
expect(Module._findPath.callCount).toBe 0
|
||||
|
||||
Reference in New Issue
Block a user