diff --git a/lib/sync.js b/lib/sync.js index 6b8576bd..8349ca64 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -13,7 +13,7 @@ module.exports = function (x, opts) { }; var readFileSync = opts.readFileSync || fs.readFileSync; - var extensions = opts.extensions || [ '.js' ]; + var extensions = opts.extensions || [ '.js', '.json' ]; var y = opts.basedir || path.dirname(require.cache[__filename].parent.filename) ; diff --git a/test/resolver.js b/test/resolver.js index 3fb64f58..92b757e8 100644 --- a/test/resolver.js +++ b/test/resolver.js @@ -20,6 +20,25 @@ test('async foo', function (t) { }); }); +test('async JSON', function (t) { + t.plan(3); + var dir = __dirname + '/resolver'; + + resolve('./box', { basedir : dir }, function (err, res) { + if (err) t.fail(err); + t.equal(res, dir + '/box.json'); + }); + + resolve('./box.json', { basedir : dir }, function (err, res) { + if (err) t.fail(err); + t.equal(res, dir + '/box.json'); + }); + + resolve('box', { basedir : dir }, function (err) { + t.equal(err.message, "Cannot find module 'box'"); + }); +}); + test('bar', function (t) { t.plan(2); var dir = __dirname + '/resolver'; diff --git a/test/resolver/box.json b/test/resolver/box.json new file mode 100644 index 00000000..56a6051c --- /dev/null +++ b/test/resolver/box.json @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/test/resolver_sync.js b/test/resolver_sync.js index 80f5aa55..1e9458e0 100644 --- a/test/resolver_sync.js +++ b/test/resolver_sync.js @@ -21,6 +21,26 @@ test('foo', function (t) { t.end(); }); +test('JSON', function (t) { + var dir = __dirname + '/resolver'; + + t.equal( + resolve.sync('./box', { basedir: dir }), + dir + '/box.json' + ); + + t.equal( + resolve.sync('./box.json', { basedir: dir }), + dir + '/box.json' + ); + + t.throws(function () { + resolve.sync('box', { basedir : dir }); + }); + + t.end(); +}); + test('bar', function (t) { var dir = __dirname + '/resolver';