OptionsNormalizer.spec.ts 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. sourceMapMode: 'inline',
  30. unicodeArray: true,
  31. unicodeArrayThreshold: 0,
  32. wrapUnicodeArrayCalls: true
  33. });
  34. optionsPreset3 = Object.assign({}, DEFAULT_PRESET, {
  35. domainLock: ['//localhost:9000', 'https://google.ru/abc?cde=fgh'],
  36. unicodeArray: true,
  37. encodeUnicodeLiterals: true,
  38. wrapUnicodeArrayCalls: false
  39. });
  40. expectedOptionsPreset1 = Object.assign({}, DEFAULT_PRESET, {
  41. compact: true,
  42. rotateUnicodeArray: false,
  43. unicodeArray: false,
  44. unicodeArrayThreshold: 0,
  45. wrapUnicodeArrayCalls: false
  46. });
  47. expectedOptionsPreset2 = Object.assign({}, DEFAULT_PRESET, {
  48. rotateUnicodeArray: false,
  49. sourceMapBaseUrl: 'http://localhost:9000',
  50. sourceMapMode: 'separate',
  51. unicodeArray: false,
  52. unicodeArrayThreshold: 0,
  53. wrapUnicodeArrayCalls: false
  54. });
  55. expectedOptionsPreset3 = Object.assign({}, DEFAULT_PRESET, {
  56. domainLock: ['localhost', 'google.ru'],
  57. unicodeArray: true,
  58. encodeUnicodeLiterals: true,
  59. wrapUnicodeArrayCalls: true
  60. });
  61. options1 = new Options(optionsPreset1);
  62. options2 = new Options(optionsPreset2);
  63. options3 = new Options(optionsPreset3);
  64. });
  65. it('should normalize options preset', () => {
  66. assert.deepEqual(OptionsNormalizer.normalizeOptions(options1), expectedOptionsPreset1);
  67. assert.deepEqual(OptionsNormalizer.normalizeOptions(options2), expectedOptionsPreset2);
  68. assert.deepEqual(OptionsNormalizer.normalizeOptions(options3), expectedOptionsPreset3);
  69. });
  70. });
  71. });