StringArrayNode.spec.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { assert } from 'chai';
  2. import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult';
  3. import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
  4. import { readFileAsString } from '../../../helpers/readFileAsString';
  5. import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator';
  6. describe('StringArrayNode', () => {
  7. it('should correctly append `StringArrayNode` custom node into the obfuscated code if `stringArray` option is set', () => {
  8. let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
  9. readFileAsString(__dirname + '/fixtures/simple-input.js'),
  10. {
  11. ...NO_CUSTOM_NODES_PRESET,
  12. stringArray: true,
  13. stringArrayThreshold: 1
  14. }
  15. );
  16. assert.match(obfuscationResult.getObfuscatedCode(), /^var _0x([a-f0-9]){4} *= *\[/);
  17. });
  18. it('should\'t append `StringArrayNode` custom node into the obfuscated code if `stringArray` option is not set', () => {
  19. let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
  20. readFileAsString(__dirname + '/fixtures/simple-input.js'),
  21. {
  22. ...NO_CUSTOM_NODES_PRESET,
  23. stringArray: false
  24. }
  25. );
  26. assert.notMatch(obfuscationResult.getObfuscatedCode(), /^var _0x([a-f0-9]){4} *= *\[/);
  27. });
  28. });