sourceMapBaseUrl wip implementation

This commit is contained in:
sanex3339
2016-09-18 14:25:35 +03:00
parent 2dd6f91b7f
commit bc1d4ef609
9 changed files with 59 additions and 28 deletions
@@ -10,10 +10,9 @@ describe('JavaScriptObfuscatorInternal', () => {
describe(`setSourceMapUrl (url: string)`, () => {
let javaScriptObfuscator: JavaScriptObfuscatorInternal,
obfuscationResult: IObfuscationResult,
sourceMapUrl: string;
sourceMapUrl: string = 'test.map.js';
it('should link obfuscated code with source map', () => {
sourceMapUrl = 'test.map.js';
javaScriptObfuscator = new JavaScriptObfuscatorInternal(
`var test = 1;`,
Object.assign({}, NO_CUSTOM_NODES_PRESET, {
@@ -33,23 +32,25 @@ describe('JavaScriptObfuscatorInternal', () => {
assert.isOk(JSON.parse(obfuscationResult.getSourceMap()).mappings);
});
it('should properly add source map import to the obfuscated code if `sourceMapBaseUrl` is set', () => {
sourceMapUrl = 'http://localhost:9000/';
it('should properly add base url to source map import inside obfuscated code if `sourceMapBaseUrl` is set', () => {
let sourceMapBaseUrl: string = 'http://localhost:9000';
javaScriptObfuscator = new JavaScriptObfuscatorInternal(
`var test = 1;`,
Object.assign({}, NO_CUSTOM_NODES_PRESET, {
sourceMap: true,
sourceMapBaseUrl: sourceMapUrl
sourceMapBaseUrl: sourceMapBaseUrl
})
);
javaScriptObfuscator.obfuscate();
javaScriptObfuscator.setSourceMapUrl(sourceMapUrl);
obfuscationResult = javaScriptObfuscator.getObfuscationResult();
assert.match(
obfuscationResult.getObfuscatedCode(),
new RegExp(`sourceMappingURL=${sourceMapUrl}$`))
new RegExp(`sourceMappingURL=${sourceMapBaseUrl}/${sourceMapUrl}$`))
;
assert.isOk(JSON.parse(obfuscationResult.getSourceMap()).mappings);
});