test fixes

This commit is contained in:
b-fuse 2018-03-31 03:15:02 -04:00
parent 0d994e3ec8
commit f12c78d6ec
3 changed files with 26 additions and 26 deletions

View File

@ -0,0 +1,2 @@
function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i]}return arr2}else{return Array.from(arr)}}var _require=require("bar"),foo=_require.foo;var _require2=require("world"),hello=_require2.hello;foo.x.apply(foo,_toConsumableArray(foo.y(hello.z)));
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImlucHV0Mi5qcyJdLCJuYW1lcyI6WyJyZXF1aXJlIiwiYXJyIl0sIm1hcHBpbmdzIjoiMEpBQWNBLEtBQVFDIiwic291cmNlc0NvbnRlbnQiOlsiY29uc3Qge2Zvb30gPSByZXF1aXJlKFwiYmFyXCIpO1xuY29uc3Qge2hlbGxvfSA9IHJlcXVpcmUoXCJ3b3JsZFwiKTtcblxuZm9vLngoLi4uZm9vLnkoaGVsbG8ueikpO1xuIl19

View File

@ -1,9 +0,0 @@
var fs = require("fs");
// Timeout to offset uglify loading in the test suite
var fileContents = fs.readFileSync("test/input/pr-3040/input.js");
process.stdout.write(fileContents, "utf8");
setTimeout(function() {
fs.writeFileSync("test/input/pr-3040/input.js.map", '{"version":3,"sources":["input2.js"],"names":[],"mappings":";;eAAc,QAAQ,KAAR,C;IAAP,G,YAAA,G;;gBACS,QAAQ,OAAR,C;IAAT,K,aAAA,K;;AAEP,IAAI,CAAJ,+BAAS,IAAI,CAAJ,CAAM,MAAM,CAAZ,CAAT","file":"input.js","sourcesContent":["const {foo} = require(\\"bar\\");\\nconst {hello} = require(\\"world\\");\\n\\nfoo.x(...foo.y(hello.z));\\n"]}');
}, 100);

View File

@ -1,9 +1,9 @@
var assert = require("assert"); var assert = require("assert");
var exec = require("child_process").exec; var exec = require("child_process").exec;
var readFileSync = require("fs").readFileSync; var fs = require("fs");
function read(path) { function read(path) {
return readFileSync(path, "utf8"); return fs.readFileSync(path, "utf8");
} }
describe("bin/uglifyjs", function () { describe("bin/uglifyjs", function () {
@ -94,27 +94,34 @@ describe("bin/uglifyjs", function () {
done(); done();
}); });
}); });
it("should not load the source map before it fully receives the JS source", function(done) { it("Should not load source map before finish reading from STDIN", function(done) {
var mapFile = "tmp/input.js.map";
try {
fs.mkdirSync("./tmp");
} catch (e) {
if (e.code != "EEXIST") throw e;
}
try {
fs.unlinkSync(mapFile);
} catch (e) {
if (e.code != "ENOENT") throw e;
}
var command = [ var command = [
'"' + process.argv[0] + '" test/input/pr-3040/pipe.js |', uglifyjscmd, uglifyjscmd,
"--source-map", "content=test/input/pr-3040/input.js.map", "--source-map", "content=" + mapFile,
"--source-map", "url=inline" "--source-map", "url=inline"
].join(" "); ].join(" ");
exec(command, function(err, stdout) { var child = exec(command, function(err, stdout) {
if (err) throw err; if (err) throw err;
// Revert input file to initial state for future test validity assert.strictEqual(stdout, read("test/input/pr-3040/expect.js"));
require("fs").writeFileSync("test/input/pr-3040/input.js.map", '{"version":3,"sources":["input2.js"],"names":["require","foo","hello","x","apply","_toConsumableArray","y","z"],"mappings":"kLAAcA,QAAQ,OAAfC,aAAAA,kBACSD,QAAQ,SAAjBE,gBAAAA,MAEPD,IAAIE,EAAJC,MAAAH,IAAAI,mBAASJ,IAAIK,EAAEJ,MAAMK","sourcesContent":["const {foo} = require(\\"bar\\");\\nconst {hello} = require(\\"world\\");\\n\\nfoo.x(...foo.y(hello.z));\\n"]}');
assert.strictEqual(stdout, [
'function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i]}return arr2}else{return Array.from(arr)}}var _require=require("bar"),foo=_require.foo;var _require2=require("world"),hello=_require2.hello;foo.x.apply(foo,_toConsumableArray(foo.y(hello.z)));\n',
"//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImlucHV0Mi5qcyJdLCJuYW1lcyI6WyJyZXF1aXJlIiwiZm9vIiwiaGVsbG8iLCJ4IiwiYXBwbHkiLCJfdG9Db2",
"5zdW1hYmxlQXJyYXkiLCJ5IiwieiJdLCJtYXBwaW5ncyI6ImtMQUFjQSxRQUFRLE9BQWZDLGFBQUFBLGtCQUNTRCxRQUFRLFNBQWpCRSxnQkFBQUEsTUFFUEQsSUFBSUUsRUFBSkMsTUFBQUgsSUFBQUksbUJBQVNKLElBQUlLLEVBQUVKLE1B",
"QU1LIiwic291cmNlc0NvbnRlbnQiOlsiY29uc3Qge2Zvb30gPSByZXF1aXJlKFwiYmFyXCIpO1xuY29uc3Qge2hlbGxvfSA9IHJlcXVpcmUoXCJ3b3JsZFwiKTtcblxuZm9vLngoLi4uZm9vLnkoaGVsbG8ueikpO1xuIl19\n"
].join(""));
done(); done();
}); });
setTimeout(function() {
fs.copyFileSync("test/input/pr-3040/input.js.map", mapFile);
child.stdin.end(read("test/input/pr-3040/input.js"));
}, 1000);
}); });
it("Should work with --keep-fnames (mangle only)", function (done) { it("Should work with --keep-fnames (mangle only)", function (done) {
var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m'; var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m';