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);
});
+1 -3
View File
@@ -31,7 +31,6 @@ describe('OptionsNormalizer', () => {
optionsPreset2 = Object.assign({}, DEFAULT_PRESET, {
rotateUnicodeArray: true,
sourceMapBaseUrl: 'http://localhost:9000',
sourceMapMode: 'inline',
unicodeArray: true,
unicodeArrayThreshold: 0,
wrapUnicodeArrayCalls: true
@@ -52,8 +51,7 @@ describe('OptionsNormalizer', () => {
});
expectedOptionsPreset2 = Object.assign({}, DEFAULT_PRESET, {
rotateUnicodeArray: false,
sourceMapBaseUrl: 'http://localhost:9000',
sourceMapMode: 'separate',
sourceMapBaseUrl: 'http://localhost:9000/',
unicodeArray: false,
unicodeArrayThreshold: 0,
wrapUnicodeArrayCalls: false
+6
View File
@@ -75,6 +75,12 @@ describe('Utils', () => {
});
});
describe('normalizeUrl (url: string): string', () => {
it('should normalize given url', () => {
assert.equal(Utils.normalizeUrl('http://localhost:9000'), 'http://localhost:9000/');
});
});
describe('stringToJSFuck (string: string): string', () => {
let expected: string = `${JSFuck.s} + ${JSFuck.t} + ${JSFuck.r} + ${JSFuck.i} + ${JSFuck.n} + ${JSFuck.g}`;