OptionsNormalizer.spec.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. expectedOptions1: IOptions,
  12. expectedOptions2: IOptions,
  13. optionsPreset1: IObfuscatorOptions,
  14. optionsPreset2: IObfuscatorOptions,
  15. expectedOptionsPreset1: IObfuscatorOptions,
  16. expectedOptionsPreset2: IObfuscatorOptions;
  17. beforeEach(() => {
  18. optionsPreset1 = Object.assign({}, DEFAULT_PRESET, {
  19. compact: false,
  20. rotateUnicodeArray: true,
  21. unicodeArray: false,
  22. unicodeArrayThreshold: 0.5,
  23. wrapUnicodeArrayCalls: true
  24. });
  25. optionsPreset2 = Object.assign({}, DEFAULT_PRESET, {
  26. rotateUnicodeArray: true,
  27. unicodeArray: true,
  28. unicodeArrayThreshold: 0,
  29. wrapUnicodeArrayCalls: true
  30. });
  31. expectedOptionsPreset1 = Object.assign({}, DEFAULT_PRESET, {
  32. compact: true,
  33. rotateUnicodeArray: false,
  34. unicodeArray: false,
  35. unicodeArrayThreshold: 0,
  36. wrapUnicodeArrayCalls: false
  37. });
  38. expectedOptionsPreset2 = Object.assign({}, DEFAULT_PRESET, {
  39. rotateUnicodeArray: false,
  40. unicodeArray: false,
  41. unicodeArrayThreshold: 0,
  42. wrapUnicodeArrayCalls: false
  43. });
  44. options1 = new Options(optionsPreset1);
  45. options2 = new Options(optionsPreset2);
  46. expectedOptions1 = new Options(expectedOptionsPreset1);
  47. expectedOptions2 = new Options(expectedOptionsPreset2);
  48. });
  49. it('should normalize options preset', () => {
  50. assert.deepEqual(OptionsNormalizer.normalizeOptions(options1), expectedOptions1);
  51. assert.deepEqual(OptionsNormalizer.normalizeOptions(options2), expectedOptions2);
  52. });
  53. });
  54. });