Validation.spec.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { assert } from 'chai';
  2. import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade';
  3. import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
  4. import { SourceMapSourcesMode } from '../../../../src/enums/source-map/SourceMapSourcesMode';
  5. describe('`inputFileName` validation', () => {
  6. describe('IsInputFileName', () => {
  7. describe('Variant #1: positive validation', () => {
  8. describe('Variant #1: empty string when `sourceMapSourcesMode: \'sources-content\'', () => {
  9. let testFunc: () => string;
  10. beforeEach(() => {
  11. testFunc = () => JavaScriptObfuscator.obfuscate(
  12. '',
  13. {
  14. ...NO_ADDITIONAL_NODES_PRESET,
  15. inputFileName: '',
  16. sourceMapSourcesMode: SourceMapSourcesMode.SourcesContent
  17. }
  18. ).getObfuscatedCode();
  19. });
  20. it('should pass validation', () => {
  21. assert.doesNotThrow(testFunc);
  22. });
  23. });
  24. describe('Variant #2: string with input file name when `sourceMapSourcesMode: \'sources\'', () => {
  25. let testFunc: () => string;
  26. beforeEach(() => {
  27. testFunc = () => JavaScriptObfuscator.obfuscate(
  28. '',
  29. {
  30. ...NO_ADDITIONAL_NODES_PRESET,
  31. inputFileName: 'some-file.js',
  32. sourceMapSourcesMode: SourceMapSourcesMode.Sources
  33. }
  34. ).getObfuscatedCode();
  35. });
  36. it('should pass validation', () => {
  37. assert.doesNotThrow(testFunc);
  38. });
  39. });
  40. });
  41. describe('Variant #2: negative validation', () => {
  42. describe('Variant #1: empty string when `sourceMapSourcesMode: \'sources\'', () => {
  43. const expectedError: string = 'should not be empty';
  44. let testFunc: () => string;
  45. beforeEach(() => {
  46. testFunc = () => JavaScriptObfuscator.obfuscate(
  47. '',
  48. {
  49. ...NO_ADDITIONAL_NODES_PRESET,
  50. inputFileName: '',
  51. sourceMapSourcesMode: SourceMapSourcesMode.Sources
  52. }
  53. ).getObfuscatedCode();
  54. });
  55. it('should not pass validation', () => {
  56. assert.throws(testFunc, expectedError);
  57. });
  58. });
  59. });
  60. });
  61. });