|
@@ -0,0 +1,71 @@
|
|
|
+import { assert } from 'chai';
|
|
|
+
|
|
|
+import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
|
|
|
+
|
|
|
+import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
|
|
|
+
|
|
|
+import { ObfuscationTarget } from '../../../../../src/enums/ObfuscationTarget';
|
|
|
+import { SourceMapMode } from '../../../../../src/enums/source-map/SourceMapMode';
|
|
|
+
|
|
|
+describe('`sourceMapMode` IsAllowedForObfuscationTarget validator', () => {
|
|
|
+ describe('Variant #1: positive validation', () => {
|
|
|
+ describe('Variant #1: obfuscation target: `browser`', () => {
|
|
|
+ let testFunc: () => string;
|
|
|
+
|
|
|
+ beforeEach(() => {
|
|
|
+ testFunc = () => JavaScriptObfuscator.obfuscate(
|
|
|
+ '',
|
|
|
+ {
|
|
|
+ ...NO_ADDITIONAL_NODES_PRESET,
|
|
|
+ sourceMapMode: SourceMapMode.Inline,
|
|
|
+ target: ObfuscationTarget.Browser
|
|
|
+ }
|
|
|
+ ).getObfuscatedCode();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should pass validation when obfuscation target is `browser`', () => {
|
|
|
+ assert.doesNotThrow(testFunc);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('Variant #2: obfuscation target: `node` and default value', () => {
|
|
|
+ let testFunc: () => string;
|
|
|
+
|
|
|
+ beforeEach(() => {
|
|
|
+ testFunc = () => JavaScriptObfuscator.obfuscate(
|
|
|
+ '',
|
|
|
+ {
|
|
|
+ ...NO_ADDITIONAL_NODES_PRESET,
|
|
|
+ sourceMapMode: SourceMapMode.Separate,
|
|
|
+ target: ObfuscationTarget.Node
|
|
|
+ }
|
|
|
+ ).getObfuscatedCode();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should pass validation when obfuscation target is `node` and value is default', () => {
|
|
|
+ assert.doesNotThrow(testFunc);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('Variant #2: negative validation', () => {
|
|
|
+ const expectedError: string = 'This option allowed only for obfuscation targets';
|
|
|
+
|
|
|
+ let testFunc: () => string;
|
|
|
+
|
|
|
+ beforeEach(() => {
|
|
|
+ testFunc = () => JavaScriptObfuscator.obfuscate(
|
|
|
+ '',
|
|
|
+ {
|
|
|
+ ...NO_ADDITIONAL_NODES_PRESET,
|
|
|
+ sourceMapMode: SourceMapMode.Inline,
|
|
|
+ target: ObfuscationTarget.Node
|
|
|
+ }
|
|
|
+ ).getObfuscatedCode();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should not pass validation when obfuscation target is `node` and value is not default', () => {
|
|
|
+ assert.throws(testFunc, expectedError);
|
|
|
+ });
|
|
|
+ });
|
|
|
+});
|