StringArrayNode.spec.ts 1.3 KB

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