JavaScriptObfuscatorInternal.spec.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { IObfuscationResult } from "../../src/interfaces/IObfuscationResult";
  2. import { JavaScriptObfuscatorInternal } from "../../src/JavaScriptObfuscatorInternal";
  3. import { NO_CUSTOM_NODES_PRESET } from "../../src/preset-options/NoCustomNodesPreset";
  4. const assert: Chai.AssertStatic = require('chai').assert;
  5. describe('JavaScriptObfuscatorInternal', () => {
  6. describe(`setSourceMapUrl (url: string)`, () => {
  7. let javaScriptObfuscator: JavaScriptObfuscatorInternal,
  8. obfuscationResult: IObfuscationResult,
  9. sourceMapUrl: string = 'test.map.js';
  10. beforeEach(() => {
  11. javaScriptObfuscator = new JavaScriptObfuscatorInternal(
  12. `var test = 1;`,
  13. Object.assign({}, NO_CUSTOM_NODES_PRESET, {
  14. sourceMap: true
  15. })
  16. );
  17. javaScriptObfuscator.obfuscate();
  18. javaScriptObfuscator.setSourceMapUrl(sourceMapUrl);
  19. obfuscationResult = javaScriptObfuscator.getObfuscationResult();
  20. });
  21. it('should link obfuscated code with source map', () => {
  22. assert.match(
  23. obfuscationResult.getObfuscatedCode(),
  24. new RegExp(`sourceMappingURL=${sourceMapUrl}`))
  25. ;
  26. assert.isOk(JSON.parse(obfuscationResult.getSourceMap()).mappings);
  27. });
  28. });
  29. });