add tests about sourceMapInline

This commit is contained in:
pengzhenqing 2016-10-10 14:53:31 +08:00
parent d7eaa95949
commit c7271e4157
3 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,7 @@
var bar = (function () {
function foo (bar) {
return bar;
}
return foo;
})();

View File

@ -49,4 +49,29 @@ describe("bin/uglifyjs", function () {
done();
});
});
it("Should append source map to output when using --source-map-inline", function (done) {
var command = uglifyjscmd + ' test/input/issue-1323/sample.js --source-map-inline';
exec(command, function (err, stdout) {
if (err) throw err;
assert.doesNotThrow(function (){
var validate_source_map = /\/\/# sourceMappingURL=data:.*base64,(.*)\s*$/;
var base64 = stdout.match(validate_source_map)[1];
var buf = new Buffer(base64, 'base64');
var map = JSON.parse(buf.toString());
done();
});
});
});
it("should not append source map to output when not using --source-map-inline", function (done) {
var command = uglifyjscmd + ' test/input/issue-1323/sample.js';
exec(command, function (err, stdout) {
var validate_source_map = /\/\/# sourceMappingURL=data:.*base64,(.*)\s*$/;
assert.strictEqual(false, validate_source_map.test(stdout));
done();
});
});
});

View File

@ -75,4 +75,31 @@ describe("minify", function() {
'let foo = x => "foo " + x;\nconsole.log(foo("bar"));');
});
});
describe("sourceMapInline", function() {
it("should append source map to output js when sourceMapInline is enabled", function() {
var result = Uglify.minify('var a = function(foo) { return foo; };', {
fromString: true,
sourceMapInline: true
});
var code = result.code;
assert.doesNotThrow(function() {
var validate_source_map = /\/\/# sourceMappingURL=data:.*base64,(.*)\s*$/;
var base64 = code.match(validate_source_map)[1];
var buf = new Buffer(base64, 'base64');
var map = JSON.parse(buf.toString());
})
});
it("should not append source map to output js when sourceMapInline is not enabled", function() {
var result = Uglify.minify('var a = function(foo) { return foo; };', {
fromString: true
});
var code = result.code;
var validate_source_map = /\/\/# sourceMappingURL=data:.*base64,(.*)\s*$/;
assert.strictEqual(false, validate_source_map.test(code));
});
});
});