From b70fdc0f4d987d4675811ec0ad1e5ec13a66dda1 Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Sun, 19 Dec 2021 00:34:09 +0100 Subject: [PATCH] Improve shebang test --- lib/moduleEnv.js | 2 +- testLib/sharedTestCases.js | 8 +++++--- testLib/shebangModule.js | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/moduleEnv.js b/lib/moduleEnv.js index e5bb2e8..d7657ac 100644 --- a/lib/moduleEnv.js +++ b/lib/moduleEnv.js @@ -44,7 +44,7 @@ var moduleWrapper0 = Module.wrapper[0], // Test the regular expresssion at https://regex101.com/r/dvnZPv/2 and also check out testLib/constModule.js. matchConst = /(^|\s|\}|;)const(\/\*|\s|{)/gm, // Required for importing modules with shebang declarations, since NodeJS 12.16.0 - shebang = /^(#!).+/, + shebang = /^#!.+/, nodeRequire, currentModule; diff --git a/testLib/sharedTestCases.js b/testLib/sharedTestCases.js index 803f59e..0cf9d8b 100644 --- a/testLib/sharedTestCases.js +++ b/testLib/sharedTestCases.js @@ -409,8 +409,10 @@ module.exports = function () { }); it("should be possible to rewire shebang modules", function () { - expect(function () { - rewire("./shebangModule"); - }).to.not.throwError(); + var shebangModule = rewire("./shebangModule"); + var shebangs = shebangModule.__get__("shebangs"); + + expect(typeof shebangs).to.be("function"); + expect(shebangModule.shebangs()).to.be(true); }); }; diff --git a/testLib/shebangModule.js b/testLib/shebangModule.js index da6ac74..c273724 100644 --- a/testLib/shebangModule.js +++ b/testLib/shebangModule.js @@ -4,4 +4,4 @@ function shebangs() { return true; } -module.exports.shebangs = shebangs; +exports.shebangs = shebangs;