[Pkg-javascript-commits] [node-module-deps] 390/444: Fix ignoreMissing when using cache

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 15 09:48:16 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-module-deps.

commit c2553d88cab068295af65a2591e5da2c169fdfd4
Author: Andres Suarez <zertosh at gmail.com>
Date:   Sat Jun 6 16:13:11 2015 -0400

    Fix ignoreMissing when using cache
---
 index.js                     |  2 +-
 test/ignore_missing.js       | 60 ++++++++++++++++++++++++++++++++++++++++++++
 test/ignore_missing/main.js  |  1 +
 test/ignore_missing/other.js |  1 +
 test/ignore_missing_cache.js | 52 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 115 insertions(+), 1 deletion(-)

diff --git a/index.js b/index.js
index 5417a7d..53fe143 100644
--- a/index.js
+++ b/index.js
@@ -136,7 +136,7 @@ Deps.prototype.resolve = function (id, parent, cb) {
     var opts = self.options;
     
     if (xhas(self.cache, parent.id, 'deps', id)
-    && self.cache[parent.id].deps) {
+    && self.cache[parent.id].deps[id]) {
         var file = self.cache[parent.id].deps[id];
         var pkg = self.pkgCache[file];
         if (pkg) return cb(null, file, pkg);
diff --git a/test/ignore_missing.js b/test/ignore_missing.js
new file mode 100644
index 0000000..a868457
--- /dev/null
+++ b/test/ignore_missing.js
@@ -0,0 +1,60 @@
+var parser = require('../');
+var test = require('tap').test;
+var fs = require('fs');
+var path = require('path');
+
+var files = {
+    main: path.join(__dirname, '/ignore_missing/main.js'),
+    other: path.join(__dirname, '/ignore_missing/other.js')
+};
+
+var sources = Object.keys(files).reduce(function (acc, file) {
+    acc[file] = fs.readFileSync(files[file], 'utf8');
+    return acc;
+}, {});
+
+test('ignoreMissing', function (t) {
+    t.plan(1);
+    var p = parser({ignoreMissing: true});
+    p.end({file: files.main, entry: true});
+    
+    var rows = [];
+    p.on('data', function (row) { rows.push(row) });
+    p.on('end', function () {
+        t.same(rows.sort(cmp), [
+            {
+                id: files.main,
+                file: files.main,
+                source: sources.main,
+                entry: true,
+                deps: { './other': files.other }
+            },
+            {
+                id: files.other,
+                file: files.other,
+                source: sources.other,
+                deps: { 'missingModule': undefined }
+            }
+        ].sort(cmp));
+    });
+});
+
+test('ignoreMissing off', function (t) {
+    t.plan(1);
+    var p = parser();
+    p.end({file: files.main, entry: true});
+    
+    var rows = [];
+    p.on('data', function (row) { rows.push(row) });
+    p.on('error', function (err) {
+        t.match(
+            String(err),
+            /Cannot find module 'missingModule'/
+        );
+    });
+    p.on('end', function () {
+        t.fail('should have errored');
+    });
+});
+
+function cmp (a, b) { return a.id < b.id ? -1 : 1 }
diff --git a/test/ignore_missing/main.js b/test/ignore_missing/main.js
new file mode 100644
index 0000000..709d2db
--- /dev/null
+++ b/test/ignore_missing/main.js
@@ -0,0 +1 @@
+require('./other');
diff --git a/test/ignore_missing/other.js b/test/ignore_missing/other.js
new file mode 100644
index 0000000..d173b34
--- /dev/null
+++ b/test/ignore_missing/other.js
@@ -0,0 +1 @@
+require('missingModule');
diff --git a/test/ignore_missing_cache.js b/test/ignore_missing_cache.js
new file mode 100644
index 0000000..7152015
--- /dev/null
+++ b/test/ignore_missing_cache.js
@@ -0,0 +1,52 @@
+var parser = require('../');
+var test = require('tap').test;
+var fs = require('fs');
+var path = require('path');
+
+var files = {
+    main: path.join(__dirname, '/ignore_missing/main.js'),
+    other: path.join(__dirname, '/ignore_missing/other.js')
+};
+
+var sources = Object.keys(files).reduce(function (acc, file) {
+    acc[file] = fs.readFileSync(files[file], 'utf8');
+    return acc;
+}, {});
+
+var cache = {};
+cache[files.main] = {
+    source: sources.main,
+    deps: { './other': files.other }
+};
+cache[files.other] = {
+    source: sources.other,
+    deps: { 'missingModule': undefined }
+};
+
+test('ignoreMissing with cache', function (t) {
+    t.plan(1);
+    var p = parser({ cache: cache, ignoreMissing: true });
+    p.end({file: files.main, entry: true});
+    
+    var rows = [];
+    p.on('data', function (row) { rows.push(row) });
+    p.on('end', function () {
+        t.same(rows.sort(cmp), [
+            {
+                id: files.main,
+                file: files.main,
+                source: sources.main,
+                entry: true,
+                deps: { './other': files.other }
+            },
+            {
+                id: files.other,
+                file: files.other,
+                source: sources.other,
+                deps: { 'missingModule': undefined }
+            }
+        ].sort(cmp));
+    });
+});
+
+function cmp (a, b) { return a.id < b.id ? -1 : 1 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-module-deps.git



More information about the Pkg-javascript-commits mailing list