OptionsNormalizer.spec.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { IObfuscatorOptions } from "../../src/interfaces/IObfuscatorOptions";
  2. import { IOptions } from "../../src/interfaces/IOptions";
  3. import { DEFAULT_PRESET } from '../../src/preset-options/DefaultPreset';
  4. import { Options } from "../../src/options/Options";
  5. import { OptionsNormalizer } from '../../src/options/OptionsNormalizer';
  6. const assert: Chai.AssertStatic = require('chai').assert;
  7. describe('OptionsNormalizer', () => {
  8. describe('normalizeOptions (options: IObfuscatorOptions): IObfuscatorOptions', () => {
  9. let options1: IOptions,
  10. options2: IOptions,
  11. options3: IOptions,
  12. optionsPreset1: IObfuscatorOptions,
  13. optionsPreset2: IObfuscatorOptions,
  14. optionsPreset3: IObfuscatorOptions,
  15. expectedOptionsPreset1: IObfuscatorOptions,
  16. expectedOptionsPreset2: IObfuscatorOptions,
  17. expectedOptionsPreset3: IObfuscatorOptions;
  18. beforeEach(() => {
  19. optionsPreset1 = Object.assign({}, DEFAULT_PRESET, {
  20. compact: false,
  21. rotateUnicodeArray: true,
  22. unicodeArray: false,
  23. unicodeArrayThreshold: 0.5,
  24. wrapUnicodeArrayCalls: true
  25. });
  26. optionsPreset2 = Object.assign({}, DEFAULT_PRESET, {
  27. rotateUnicodeArray: true,
  28. sourceMapBaseUrl: 'http://localhost:9000',
  29. unicodeArray: true,
  30. unicodeArrayThreshold: 0,
  31. wrapUnicodeArrayCalls: true
  32. });
  33. optionsPreset3 = Object.assign({}, DEFAULT_PRESET, {
  34. domainLock: ['//localhost:9000', 'https://google.ru/abc?cde=fgh'],
  35. unicodeArray: true,
  36. encodeUnicodeLiterals: true,
  37. wrapUnicodeArrayCalls: false
  38. });
  39. expectedOptionsPreset1 = Object.assign({}, DEFAULT_PRESET, {
  40. compact: true,
  41. rotateUnicodeArray: false,
  42. unicodeArray: false,
  43. unicodeArrayThreshold: 0,
  44. wrapUnicodeArrayCalls: false
  45. });
  46. expectedOptionsPreset2 = Object.assign({}, DEFAULT_PRESET, {
  47. rotateUnicodeArray: false,
  48. sourceMapBaseUrl: 'http://localhost:9000/',
  49. unicodeArray: false,
  50. unicodeArrayThreshold: 0,
  51. wrapUnicodeArrayCalls: false
  52. });
  53. expectedOptionsPreset3 = Object.assign({}, DEFAULT_PRESET, {
  54. domainLock: ['localhost', 'google.ru'],
  55. unicodeArray: true,
  56. encodeUnicodeLiterals: true,
  57. wrapUnicodeArrayCalls: true
  58. });
  59. options1 = new Options(optionsPreset1);
  60. options2 = new Options(optionsPreset2);
  61. options3 = new Options(optionsPreset3);
  62. });
  63. it('should normalize options preset', () => {
  64. assert.deepEqual(OptionsNormalizer.normalizeOptions(options1), expectedOptionsPreset1);
  65. assert.deepEqual(OptionsNormalizer.normalizeOptions(options2), expectedOptionsPreset2);
  66. assert.deepEqual(OptionsNormalizer.normalizeOptions(options3), expectedOptionsPreset3);
  67. });
  68. });
  69. });