From 55dd0b3a436064d6885a98ee6dba1d1a05df88e1 Mon Sep 17 00:00:00 2001 From: Rikkert Koppes Date: Sat, 10 Dec 2016 20:54:39 +0100 Subject: [PATCH 1/2] Test for requiring native modules in node 6 --- test/test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/test.js b/test/test.js index dd9f08e..058ecd6 100644 --- a/test/test.js +++ b/test/test.js @@ -88,6 +88,14 @@ describe("intercept-require", function () { restore(); }); + it("should not throw on native modules", function () { + const restore = intercept(() => {}); + expect(function() { + require('fs'); + }).toNotThrow(); + restore(); + }); + it("passes the result and some info to the listener", function () { let calc, result, info; function listener (r, i) { From 4544023bcee2298d72d033d1c493686c83839c1a Mon Sep 17 00:00:00 2001 From: Rikkert Koppes Date: Sat, 10 Dec 2016 20:55:58 +0100 Subject: [PATCH 2/2] fix for requiring native modules in node 6. path.extname no longer accepts undefined --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 7056641..59196d9 100644 --- a/lib/index.js +++ b/lib/index.js @@ -121,7 +121,7 @@ function generateRequireInfo (moduleId) { moduleId: moduleId, callingFile: callingFile, native: native, - extname: path.extname(absPath), + extname: absPath? path.extname(absPath): '', thirdParty: thirdParty, absPath: absPath, absPathResolvedCorrectly: absPathResolvedCorrectly,