mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
sourceMapBaseUrl wip implementation
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user