Permalink
Browse files

require.resolve throws an error if path was not found [#19]

  • Loading branch information...
David Kudera
David Kudera committed Jan 20, 2014
1 parent 9ccf73c commit c182a6b30ac5b1cefbd77d2b8f42c5b970bfcdbb
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -14,8 +14,6 @@ if !@require
require = (name, parent = null) ->
fullName = resolve(name, parent)
if fullName == null
throw new Error 'Module ' + name + ' was not found.'
if typeof cache[fullName] == 'undefined'
m =
@@ -45,6 +43,8 @@ if !@require
resolve = (name, parent = null) ->
original = name
if parent != null && name[0] == '.'
# get directory path
@@ -78,7 +78,7 @@ if !@require
for ext in SUPPORTED
return name + '/index.' + ext if typeof modules[name + '/index.' + ext] != 'undefined'
return null
throw new Error "Module #{original} was not found."
arrayIndexOf = (array, search) ->

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -47,6 +47,9 @@ describe 'require', ->
it 'should resolve name for package file withoud extension', ->
expect(require.resolve('/package')).to.be.equal('/package.json')
it 'should throw an error if module with given path does not exists', ->
expect( -> require.resolve('./any-random-name')).to.throw(Error, 'Module ./any-random-name was not found.')
describe '#require()', ->
it 'should load simple module', ->
expect(require('/app/Application.coffee')).to.be.equal('Application')

0 comments on commit c182a6b

Please sign in to comment.