From 44d6912a55fecc63ab4f0a8eb28653268556851a Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 24 Apr 2020 18:30:37 +0100 Subject: improve `--reduce-test` on `Error.message` (#3816) closes #3815 --- test/mocha/reduce.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'test/mocha/reduce.js') diff --git a/test/mocha/reduce.js b/test/mocha/reduce.js index a6c8a752..779dd99f 100644 --- a/test/mocha/reduce.js +++ b/test/mocha/reduce.js @@ -246,4 +246,52 @@ describe("test/reduce.js", function() { "// }", ].join("\n")); }); + it("Should reduce test case which differs only in Error.message", function() { + var code = [ + "var a=0;", + "try{", + "null[function(){}]", + "}catch(e){", + "for(var i in e.toString())a++", + "}", + "console.log(a);", + ].join(""); + var result = reduce_test(code, { + compress: false, + mangle: false, + output: { + beautify: true, + }, + }); + if (result.error) throw result.error; + assert.strictEqual(result.code.replace(/function \(/g, "function("), (semver.satisfies(process.version, "<=0.10") ? [ + "// Can't reproduce test failure", + "// minify options: {", + '// "compress": false,', + '// "mangle": false,', + '// "output": {', + '// "beautify": true', + "// }", + "// }", + ] : [ + [ + "try{", + "null[function(){}]", + "}catch(e){", + "console.log(e)", + "}", + ].join(""), + "// output: TypeError: Cannot read property 'function(){}' of null", + "// ", + "// minify: TypeError: Cannot read property 'function() {}' of null", + "// ", + "// options: {", + '// "compress": false,', + '// "mangle": false,', + '// "output": {', + '// "beautify": true', + "// }", + "// }", + ]).join("\n")); + }); }); -- cgit v1.2.3