OptionsNormalizer.spec.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. unicodeArray: true,
  29. unicodeArrayThreshold: 0,
  30. wrapUnicodeArrayCalls: true
  31. });
  32. optionsPreset3 = Object.assign({}, DEFAULT_PRESET, {
  33. unicodeArray: true,
  34. encodeUnicodeLiterals: true,
  35. wrapUnicodeArrayCalls: false
  36. });
  37. expectedOptionsPreset1 = Object.assign({}, DEFAULT_PRESET, {
  38. compact: true,
  39. rotateUnicodeArray: false,
  40. unicodeArray: false,
  41. unicodeArrayThreshold: 0,
  42. wrapUnicodeArrayCalls: false
  43. });
  44. expectedOptionsPreset2 = Object.assign({}, DEFAULT_PRESET, {
  45. rotateUnicodeArray: false,
  46. unicodeArray: false,
  47. unicodeArrayThreshold: 0,
  48. wrapUnicodeArrayCalls: false
  49. });
  50. expectedOptionsPreset3 = Object.assign({}, DEFAULT_PRESET, {
  51. unicodeArray: true,
  52. encodeUnicodeLiterals: true,
  53. wrapUnicodeArrayCalls: true
  54. });
  55. options1 = new Options(optionsPreset1);
  56. options2 = new Options(optionsPreset2);
  57. options3 = new Options(optionsPreset3);
  58. });
  59. it('should normalize options preset', () => {
  60. assert.deepEqual(OptionsNormalizer.normalizeOptions(options1), expectedOptionsPreset1);
  61. assert.deepEqual(OptionsNormalizer.normalizeOptions(options2), expectedOptionsPreset2);
  62. assert.deepEqual(OptionsNormalizer.normalizeOptions(options3), expectedOptionsPreset3);
  63. });
  64. });
  65. });