[test] add sourceMap test against relative sources
This commit is contained in:
parent
c898a7997d
commit
fcb4f2f215
|
|
@ -3,32 +3,55 @@ var assert = require("assert");
|
||||||
var SourceMapConsumer = require("source-map").SourceMapConsumer;
|
var SourceMapConsumer = require("source-map").SourceMapConsumer;
|
||||||
|
|
||||||
describe("input sourcemaps", function() {
|
describe("input sourcemaps", function() {
|
||||||
var transpiled = '"use strict";\n\n' +
|
var transpilemap, map;
|
||||||
'var foo = function foo(x) {\n return "foo " + x;\n};\n' +
|
|
||||||
'console.log(foo("bar"));\n\n' +
|
|
||||||
'//# sourceMappingURL=bundle.js.map';
|
|
||||||
|
|
||||||
var transpilemap = {
|
function getMap() {
|
||||||
"version": 3,
|
return {
|
||||||
"sources": ["index.js"],
|
"version": 3,
|
||||||
"names": [],
|
"sources": ["index.js"],
|
||||||
"mappings": ";;AAAA,IAAI,MAAM,SAAN,GAAM;AAAA,SAAK,SAAS,CAAd;AAAA,CAAV;AACA,QAAQ,GAAR,CAAY,IAAI,KAAJ,CAAZ",
|
"names": [],
|
||||||
"file": "bundle.js",
|
"mappings": ";;AAAA,IAAI,MAAM,SAAN,GAAM;AAAA,SAAK,SAAS,CAAd;AAAA,CAAV;AACA,QAAQ,GAAR,CAAY,IAAI,KAAJ,CAAZ",
|
||||||
"sourcesContent": ["let foo = x => \"foo \" + x;\nconsole.log(foo(\"bar\"));"]
|
"file": "bundle.js",
|
||||||
};
|
"sourcesContent": ["let foo = x => \"foo \" + x;\nconsole.log(foo(\"bar\"));"]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
var result = Uglify.minify(transpiled, {
|
function prepareMap(sourceMap) {
|
||||||
fromString: true,
|
var transpiled = '"use strict";\n\n' +
|
||||||
inSourceMap: transpilemap,
|
'var foo = function foo(x) {\n return "foo " + x;\n};\n' +
|
||||||
outSourceMap: true
|
'console.log(foo("bar"));\n\n' +
|
||||||
|
'//# sourceMappingURL=bundle.js.map';
|
||||||
|
|
||||||
|
transpilemap = sourceMap || getMap();
|
||||||
|
|
||||||
|
var result = Uglify.minify(transpiled, {
|
||||||
|
fromString: true,
|
||||||
|
inSourceMap: transpilemap,
|
||||||
|
outSourceMap: true
|
||||||
|
});
|
||||||
|
|
||||||
|
map = new SourceMapConsumer(result.map);
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
prepareMap();
|
||||||
});
|
});
|
||||||
var map = new SourceMapConsumer(result.map);
|
|
||||||
|
|
||||||
it("Should copy over original sourcesContent", function() {
|
it("Should copy over original sourcesContent", function() {
|
||||||
assert.equal(map.sourceContentFor("index.js"), transpilemap.sourcesContent[0]);
|
assert.equal(map.sourceContentFor("index.js"), transpilemap.sourcesContent[0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Final sourcemap should not have invalid mappings from inputSourceMap (issue #882) ", function() {
|
it("Should copy sourcesContent if sources are relative", function () {
|
||||||
|
var relativeMap = getMap();
|
||||||
|
relativeMap.sources = ['./index.js'];
|
||||||
|
|
||||||
|
prepareMap(relativeMap);
|
||||||
|
assert.notEqual(map.sourcesContent, null);
|
||||||
|
assert.equal(map.sourcesContent.length, 1);
|
||||||
|
assert.equal(map.sourceContentFor("index.js"), transpilemap.sourcesContent[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Final sourcemap should not have invalid mappings from inputSourceMap (issue #882)", function() {
|
||||||
// The original source has only 2 lines, check that mappings don't have more lines
|
// The original source has only 2 lines, check that mappings don't have more lines
|
||||||
|
|
||||||
var msg = "Mapping should not have higher line number than the original file had";
|
var msg = "Mapping should not have higher line number than the original file had";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user