From f71de3b3dfd86ecefb486bf5faacb9ed4d615e47 Mon Sep 17 00:00:00 2001 From: Rens Baardman Date: Tue, 11 Jun 2019 16:50:42 +0200 Subject: [PATCH 1/2] Add Firefox compatibility to stack trace test --- testLib/sharedTestCases.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/testLib/sharedTestCases.js b/testLib/sharedTestCases.js index 9b709c2..ff7d8a5 100644 --- a/testLib/sharedTestCases.js +++ b/testLib/sharedTestCases.js @@ -280,7 +280,18 @@ module.exports = function () { try { throwError(); } catch (err) { - expect(err.stack.split("\n")[1]).to.match(/:6:26/); + + // Firefox implements a different error-stack format, + // but does offer line and column numbers on errors: we use + // those instead. + if (err.lineNumber !== undefined && err.columnNumber !== undefined) { + expect(err.lineNumber).to.equal(6) + expect(err.columnNumber).to.equal(26) + } + // This is for the V8 stack trace format (Node, Chrome) + else { + expect(err.stack.split("\n")[1]).to.match(/:6:26/); + } } }); From ae4bd02a1fbdc383241d72863b97718c77374d86 Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Sun, 19 Dec 2021 00:34:09 +0100 Subject: [PATCH 2/2] 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;