mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
84 lines
3.5 KiB
TypeScript
84 lines
3.5 KiB
TypeScript
import { IObfuscatorOptions } from '../../src/interfaces/IObfuscatorOptions';
|
|
import { IOptions } from '../../src/interfaces/IOptions';
|
|
|
|
import { DEFAULT_PRESET } from '../../src/preset-options/DefaultPreset';
|
|
|
|
import { Options } from '../../src/options/Options';
|
|
import { OptionsNormalizer } from '../../src/options/OptionsNormalizer';
|
|
|
|
const assert: Chai.AssertStatic = require('chai').assert;
|
|
|
|
describe('OptionsNormalizer', () => {
|
|
describe('normalizeOptions (options: IObfuscatorOptions): IObfuscatorOptions', () => {
|
|
let options1: IOptions,
|
|
options2: IOptions,
|
|
options3: IOptions,
|
|
optionsPreset1: IObfuscatorOptions,
|
|
optionsPreset2: IObfuscatorOptions,
|
|
optionsPreset3: IObfuscatorOptions,
|
|
expectedOptionsPreset1: IObfuscatorOptions,
|
|
expectedOptionsPreset2: IObfuscatorOptions,
|
|
expectedOptionsPreset3: IObfuscatorOptions;
|
|
|
|
beforeEach(() => {
|
|
optionsPreset1 = Object.assign({}, DEFAULT_PRESET, {
|
|
compact: false,
|
|
rotateUnicodeArray: true,
|
|
sourceMapBaseUrl: 'http://localhost:9000',
|
|
unicodeArray: false,
|
|
unicodeArrayThreshold: 0.5,
|
|
wrapUnicodeArrayCalls: true
|
|
});
|
|
optionsPreset2 = Object.assign({}, DEFAULT_PRESET, {
|
|
rotateUnicodeArray: true,
|
|
sourceMapBaseUrl: 'http://localhost:9000',
|
|
sourceMapFileName: '//outputSourceMapName',
|
|
unicodeArray: true,
|
|
unicodeArrayThreshold: 0,
|
|
wrapUnicodeArrayCalls: true
|
|
});
|
|
optionsPreset3 = Object.assign({}, DEFAULT_PRESET, {
|
|
domainLock: ['//localhost:9000', 'https://google.ru/abc?cde=fgh'],
|
|
sourceMapFileName: '/outputSourceMapName.map',
|
|
unicodeArray: true,
|
|
encodeUnicodeLiterals: true,
|
|
wrapUnicodeArrayCalls: false
|
|
});
|
|
|
|
expectedOptionsPreset1 = Object.assign({}, DEFAULT_PRESET, {
|
|
compact: true,
|
|
rotateUnicodeArray: false,
|
|
sourceMapBaseUrl: '',
|
|
unicodeArray: false,
|
|
unicodeArrayThreshold: 0,
|
|
wrapUnicodeArrayCalls: false
|
|
});
|
|
expectedOptionsPreset2 = Object.assign({}, DEFAULT_PRESET, {
|
|
rotateUnicodeArray: false,
|
|
sourceMapBaseUrl: 'http://localhost:9000/',
|
|
sourceMapFileName: 'outputSourceMapName.js.map',
|
|
unicodeArray: false,
|
|
unicodeArrayThreshold: 0,
|
|
wrapUnicodeArrayCalls: false
|
|
});
|
|
expectedOptionsPreset3 = Object.assign({}, DEFAULT_PRESET, {
|
|
domainLock: ['localhost', 'google.ru'],
|
|
sourceMapFileName: 'outputSourceMapName.js.map',
|
|
unicodeArray: true,
|
|
encodeUnicodeLiterals: true,
|
|
wrapUnicodeArrayCalls: true
|
|
});
|
|
|
|
options1 = new Options(optionsPreset1);
|
|
options2 = new Options(optionsPreset2);
|
|
options3 = new Options(optionsPreset3);
|
|
});
|
|
|
|
it('should normalize options preset', () => {
|
|
assert.deepEqual(OptionsNormalizer.normalizeOptions(options1), expectedOptionsPreset1);
|
|
assert.deepEqual(OptionsNormalizer.normalizeOptions(options2), expectedOptionsPreset2);
|
|
assert.deepEqual(OptionsNormalizer.normalizeOptions(options3), expectedOptionsPreset3);
|
|
});
|
|
});
|
|
});
|