OptionsNormalizer.spec.ts 3.4 KB

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