IsAllowedForObfuscationTarget.spec.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { assert } from 'chai';
  2. import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
  3. import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
  4. import { ObfuscationTarget } from '../../../../../src/enums/ObfuscationTarget';
  5. describe('`sourceMapFileName` IsAllowedForObfuscationTarget validator', () => {
  6. describe('Variant #1: positive validation', () => {
  7. describe('Variant #1: obfuscation target: `browser`', () => {
  8. let testFunc: () => string;
  9. beforeEach(() => {
  10. testFunc = () => JavaScriptObfuscator.obfuscate(
  11. '',
  12. {
  13. ...NO_ADDITIONAL_NODES_PRESET,
  14. sourceMapFileName: 'foo',
  15. target: ObfuscationTarget.Browser
  16. }
  17. ).getObfuscatedCode();
  18. });
  19. it('should pass validation when obfuscation target is `browser`', () => {
  20. assert.doesNotThrow(testFunc);
  21. });
  22. });
  23. describe('Variant #2: obfuscation target: `node` and default value', () => {
  24. let testFunc: () => string;
  25. beforeEach(() => {
  26. testFunc = () => JavaScriptObfuscator.obfuscate(
  27. '',
  28. {
  29. ...NO_ADDITIONAL_NODES_PRESET,
  30. sourceMapFileName: '',
  31. target: ObfuscationTarget.Node
  32. }
  33. ).getObfuscatedCode();
  34. });
  35. it('should pass validation when obfuscation target is `node` and value is default', () => {
  36. assert.doesNotThrow(testFunc);
  37. });
  38. });
  39. });
  40. describe('Variant #2: negative validation', () => {
  41. const expectedError: string = 'This option allowed only for obfuscation targets';
  42. let testFunc: () => string;
  43. beforeEach(() => {
  44. testFunc = () => JavaScriptObfuscator.obfuscate(
  45. '',
  46. {
  47. ...NO_ADDITIONAL_NODES_PRESET,
  48. sourceMapFileName: 'foo',
  49. target: ObfuscationTarget.Node
  50. }
  51. ).getObfuscatedCode();
  52. });
  53. it('should not pass validation when obfuscation target is `node` and value is not default', () => {
  54. assert.throws(testFunc, expectedError);
  55. });
  56. });
  57. });