Permalink
Browse files

adding tests to reproduce the problem

- resolver test shows that async resolve fails when main field in package.json is incorrect
- resolver_sync test shows that sync resolve finds index.js under same circumstance
  • Loading branch information...
1 parent eed74a4 commit ad3a4772ddd7187ff38cb56e00635b37a491e1fa @thlorenz thlorenz committed Jul 30, 2013
Showing with 30 additions and 0 deletions.
  1. +12 −0 test/resolver.js
  2. +2 −0 test/resolver/incorrect_main/index.js
  3. +3 −0 test/resolver/incorrect_main/package.json
  4. +13 −0 test/resolver_sync.js
View
@@ -204,3 +204,15 @@ test('other path', function (t) {
t.equal(err.message, "Cannot find module 'zzz'");
});
});
+
+test('incorrect main', function (t) {
+ t.plan(1)
+
+ var resolverDir = __dirname + '/resolver';
+ var dir = resolverDir + '/incorrect_main';
+
+ resolve('./incorrect_main', { basedir : resolverDir }, function (err, res, pkg) {
+ if (err) t.fail(err);
+ t.equal(res, dir + '/index.js');
+ });
+});
@@ -0,0 +1,2 @@
+// this is the actual main file 'index.js', not 'wrong.js' like the package.json would indicate
+module.exports = 1;
@@ -0,0 +1,3 @@
+{
+ "main" : "wrong.js"
+}
View
@@ -155,3 +155,16 @@ test('other path', function (t) {
t.end();
});
+
+
+test('incorrect main', function (t) {
+ var resolverDir = __dirname + '/resolver';
+ var dir = resolverDir + '/incorrect_main';
+
+ t.equal(
+ resolve.sync('./incorrect_main', { basedir : resolverDir }),
+ dir + '/index.js'
+ )
+
+ t.end()
+});

0 comments on commit ad3a477

Please sign in to comment.