OptionsNormalizer.spec.ts 3.5 KB

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