From 1592a19e52180d30da89e2887f37b79fb694779a Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Tue, 5 Jan 2016 00:47:38 +0100 Subject: [PATCH] Fixes error handling to create a Node Object when a child package is not exist --- rpt.js | 6 +++++- test/basic.js | 8 ++++++++ test/fixtures/badlink/node_modules/foo | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) create mode 120000 test/fixtures/badlink/node_modules/foo diff --git a/rpt.js b/rpt.js index 5229897..ea2a5da 100644 --- a/rpt.js +++ b/rpt.js @@ -98,7 +98,11 @@ function loadNode (logical, physical, cache, cb) { var realpath function thenReadPackageJson (er, real) { - if (er) return cb(er) + var node + if (er) { + node = new Node(null, logical, physical, er, cache) + return cb(null, node) + } debug('realpath l=%j p=%j real=%j', dpath(logical), dpath(physical), dpath(real)) var pj = path.join(real, 'package.json') realpath = real diff --git a/test/basic.js b/test/basic.js index 0dcb538..8a757f0 100644 --- a/test/basic.js +++ b/test/basic.js @@ -123,6 +123,14 @@ test('missing folder', function (t) { t.end() }) }) +test('missing symlinks', function (t) { + rpt(path.resolve(fixtures, 'badlink'), function (er, d) { + if (er && er.code !== 'ENOENT') throw er + var childError = d.children.length === 1 && d.children[0].error + t.ok(childError, 'Child node has an error') + t.end() + }) +}) function archyize (d, seen) { diff --git a/test/fixtures/badlink/node_modules/foo b/test/fixtures/badlink/node_modules/foo new file mode 120000 index 0000000..1910281 --- /dev/null +++ b/test/fixtures/badlink/node_modules/foo @@ -0,0 +1 @@ +foo \ No newline at end of file