diff --git a/src/Obfuscator.ts b/src/Obfuscator.ts index 28d51142..f261b0db 100644 --- a/src/Obfuscator.ts +++ b/src/Obfuscator.ts @@ -53,7 +53,7 @@ export class Obfuscator implements IObfuscator { [NodeType.VariableDeclaration, [NodeTransformers.VariableDeclarationTransformer]], [NodeType.LabeledStatement, [NodeTransformers.LabeledStatementTransformer]], [NodeType.TemplateLiteral, [NodeTransformers.TemplateLiteralTransformer]], - [NodeType.Literal, [NodeTransformers.LiteralTransformer]] + [NodeType.Literal, [NodeTransformers.LiteralTransformer]] // should be latest in the chain of obfuscators ]); /** diff --git a/test/functional-tests/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.spec.ts b/test/functional-tests/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.spec.ts index bf5ffaee..aba386ba 100644 --- a/test/functional-tests/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.spec.ts +++ b/test/functional-tests/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.spec.ts @@ -4,6 +4,8 @@ import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResul import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes'; +import { readFileAsString } from '../../../helpers/readFileAsString'; + import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; describe('ConsoleOutputDisableExpressionNode', () => { @@ -11,7 +13,7 @@ describe('ConsoleOutputDisableExpressionNode', () => { it('should correctly append `ConsoleOutputDisableExpressionNode` custom node into the obfuscated code if `disableConsoleOutput` option is set', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, + readFileAsString(__dirname + '/fixtures/simple-input.js'), { ...NO_CUSTOM_NODES_PRESET, disableConsoleOutput: true @@ -23,7 +25,7 @@ describe('ConsoleOutputDisableExpressionNode', () => { it('should\'t append `ConsoleOutputDisableExpressionNode` custom node into the obfuscated code if `disableConsoleOutput` option is not set', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, + readFileAsString(__dirname + '/fixtures/simple-input.js'), { ...NO_CUSTOM_NODES_PRESET, disableConsoleOutput: false, diff --git a/test/functional-tests/custom-nodes/console-output-nodes/fixtures/simple-input.js b/test/functional-tests/custom-nodes/console-output-nodes/fixtures/simple-input.js new file mode 100644 index 00000000..7e66b5c5 --- /dev/null +++ b/test/functional-tests/custom-nodes/console-output-nodes/fixtures/simple-input.js @@ -0,0 +1 @@ +var test = 'test'; diff --git a/test/functional-tests/custom-nodes/domain-lock-nodes/DomainLockNode.spec.ts b/test/functional-tests/custom-nodes/domain-lock-nodes/DomainLockNode.spec.ts index 946316b1..e817ed39 100644 --- a/test/functional-tests/custom-nodes/domain-lock-nodes/DomainLockNode.spec.ts +++ b/test/functional-tests/custom-nodes/domain-lock-nodes/DomainLockNode.spec.ts @@ -4,12 +4,14 @@ import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResul import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes'; +import { readFileAsString } from '../../../helpers/readFileAsString'; + import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; describe('DomainLockNode', () => { it('should correctly append `DomainLockNode` custom node into the obfuscated code if `domainLock` option is set', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, + readFileAsString(__dirname + '/fixtures/simple-input.js'), { ...NO_CUSTOM_NODES_PRESET, domainLock: ['.example.com'] @@ -21,7 +23,7 @@ describe('DomainLockNode', () => { it('should\'t append `DomainLockNode` custom node into the obfuscated code if `domainLock` option is not set', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, + readFileAsString(__dirname + '/fixtures/simple-input.js'), { ...NO_CUSTOM_NODES_PRESET, domainLock: [] diff --git a/test/functional-tests/custom-nodes/domain-lock-nodes/fixtures/simple-input.js b/test/functional-tests/custom-nodes/domain-lock-nodes/fixtures/simple-input.js new file mode 100644 index 00000000..7e66b5c5 --- /dev/null +++ b/test/functional-tests/custom-nodes/domain-lock-nodes/fixtures/simple-input.js @@ -0,0 +1 @@ +var test = 'test'; diff --git a/test/functional-tests/custom-nodes/string-array-nodes/StringArrayCallsWrapper.spec.ts b/test/functional-tests/custom-nodes/string-array-nodes/StringArrayCallsWrapper.spec.ts index 8d349f0e..dd36bde8 100644 --- a/test/functional-tests/custom-nodes/string-array-nodes/StringArrayCallsWrapper.spec.ts +++ b/test/functional-tests/custom-nodes/string-array-nodes/StringArrayCallsWrapper.spec.ts @@ -4,12 +4,14 @@ import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResul import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes'; +import { readFileAsString } from '../../../helpers/readFileAsString'; + import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; describe('StringArrayCallsWrapper', () => { it('should correctly append `StringArrayCallsWrapper` custom node into the obfuscated code', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, + readFileAsString(__dirname + '/fixtures/simple-input.js'), { ...NO_CUSTOM_NODES_PRESET, stringArray: true, diff --git a/test/functional-tests/custom-nodes/string-array-nodes/StringArrayNode.spec.ts b/test/functional-tests/custom-nodes/string-array-nodes/StringArrayNode.spec.ts index 1914f291..fd7b1b2c 100644 --- a/test/functional-tests/custom-nodes/string-array-nodes/StringArrayNode.spec.ts +++ b/test/functional-tests/custom-nodes/string-array-nodes/StringArrayNode.spec.ts @@ -4,12 +4,14 @@ import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResul import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes'; +import { readFileAsString } from '../../../helpers/readFileAsString'; + import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; describe('StringArrayNode', () => { it('should correctly append `StringArrayNode` custom node into the obfuscated code if `stringArray` option is set', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, + readFileAsString(__dirname + '/fixtures/simple-input.js'), { ...NO_CUSTOM_NODES_PRESET, stringArray: true, @@ -22,7 +24,7 @@ describe('StringArrayNode', () => { it('should\'t append `StringArrayNode` custom node into the obfuscated code if `stringArray` option is not set', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, + readFileAsString(__dirname + '/fixtures/simple-input.js'), { ...NO_CUSTOM_NODES_PRESET, stringArray: false diff --git a/test/functional-tests/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.spec.ts b/test/functional-tests/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.spec.ts index 20ef9e6e..fcb5afec 100644 --- a/test/functional-tests/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.spec.ts +++ b/test/functional-tests/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.spec.ts @@ -4,12 +4,14 @@ import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResul import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes'; +import { readFileAsString } from '../../../helpers/readFileAsString'; + import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; describe('StringArrayRotateFunctionNode', () => { it('should correctly append `StringArrayRotateFunctionNode` custom node into the obfuscated code if `rotateStringArray` option is set', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, + readFileAsString(__dirname + '/fixtures/simple-input.js'), { ...NO_CUSTOM_NODES_PRESET, rotateStringArray: true, @@ -23,7 +25,7 @@ describe('StringArrayRotateFunctionNode', () => { it('should\'t append `StringArrayRotateFunctionNode` custom node into the obfuscated code if `rotateStringArray` option is not set', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, + readFileAsString(__dirname + '/fixtures/simple-input.js'), { ...NO_CUSTOM_NODES_PRESET, rotateStringArray: false, diff --git a/test/functional-tests/custom-nodes/string-array-nodes/fixtures/simple-input.js b/test/functional-tests/custom-nodes/string-array-nodes/fixtures/simple-input.js new file mode 100644 index 00000000..7e66b5c5 --- /dev/null +++ b/test/functional-tests/custom-nodes/string-array-nodes/fixtures/simple-input.js @@ -0,0 +1 @@ +var test = 'test'; diff --git a/test/functional-tests/JavaScriptObfuscatorCLI.spec.ts b/test/functional-tests/javascript-obfuscator-cli/JavaScriptObfuscatorCLI.spec.ts similarity index 98% rename from test/functional-tests/JavaScriptObfuscatorCLI.spec.ts rename to test/functional-tests/javascript-obfuscator-cli/JavaScriptObfuscatorCLI.spec.ts index 8f5a6610..a0b66f66 100644 --- a/test/functional-tests/JavaScriptObfuscatorCLI.spec.ts +++ b/test/functional-tests/javascript-obfuscator-cli/JavaScriptObfuscatorCLI.spec.ts @@ -4,9 +4,9 @@ import * as sinon from 'sinon'; import { assert } from 'chai'; -import { StdoutWriteMock } from '../mocks/StdoutWriteMock'; +import { StdoutWriteMock } from '../../mocks/StdoutWriteMock'; -import { JavaScriptObfuscator } from '../../src/JavaScriptObfuscator'; +import { JavaScriptObfuscator } from '../../../src/JavaScriptObfuscator'; describe('JavaScriptObfuscatorCLI', function (): void { let fixturesDirName: string = 'test/fixtures', diff --git a/test/functional-tests/JavaScriptObfuscatorInternal.spec.ts b/test/functional-tests/javascript-obfuscator-internal/JavaScriptObfuscatorInternal.spec.ts similarity index 79% rename from test/functional-tests/JavaScriptObfuscatorInternal.spec.ts rename to test/functional-tests/javascript-obfuscator-internal/JavaScriptObfuscatorInternal.spec.ts index 69b02200..51784a8d 100644 --- a/test/functional-tests/JavaScriptObfuscatorInternal.spec.ts +++ b/test/functional-tests/javascript-obfuscator-internal/JavaScriptObfuscatorInternal.spec.ts @@ -1,14 +1,14 @@ -import { ServiceIdentifiers } from '../../src/container/ServiceIdentifiers'; +import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers'; import { assert } from 'chai'; -import { IInversifyContainerFacade } from '../../src/interfaces/container/IInversifyContainerFacade'; -import { IJavaScriptObfuscator } from '../../src/interfaces/IJavaScriptObfsucator'; -import { IObfuscationResult } from '../../src/interfaces/IObfuscationResult'; +import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade'; +import { IJavaScriptObfuscator } from '../../../src/interfaces/IJavaScriptObfsucator'; +import { IObfuscationResult } from '../../../src/interfaces/IObfuscationResult'; -import { NO_CUSTOM_NODES_PRESET } from '../../src/options/presets/NoCustomNodes'; +import { NO_CUSTOM_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes'; -import { InversifyContainerFacade } from '../../src/container/InversifyContainerFacade'; +import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade'; describe('JavaScriptObfuscatorInternal', () => { describe(`setSourceMapUrl (url: string)`, () => { diff --git a/test/functional-tests/JavaScriptObfuscator.spec.ts b/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts similarity index 85% rename from test/functional-tests/JavaScriptObfuscator.spec.ts rename to test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts index 51ea0bce..27ee74b2 100644 --- a/test/functional-tests/JavaScriptObfuscator.spec.ts +++ b/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts @@ -2,14 +2,15 @@ import { assert } from 'chai'; import { Chance } from 'chance'; -import { IObfuscationResult } from '../../src/interfaces/IObfuscationResult'; +import { IObfuscationResult } from '../../../src/interfaces/IObfuscationResult'; -import { JavaScriptObfuscator } from '../../src/JavaScriptObfuscator'; +import { JavaScriptObfuscator } from '../../../src/JavaScriptObfuscator'; -import { NO_CUSTOM_NODES_PRESET } from '../../src/options/presets/NoCustomNodes'; +import { NO_CUSTOM_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes'; -import { readFileAsString } from '../helpers/readFileAsString'; -import { RandomGeneratorUtils } from '../../src/utils/RandomGeneratorUtils'; +import { readFileAsString } from '../../helpers/readFileAsString'; + +import { RandomGeneratorUtils } from '../../../src/utils/RandomGeneratorUtils'; describe('JavaScriptObfuscator', () => { describe('obfuscate (sourceCode: string, customOptions?: IObfuscatorOptions): IObfuscationResult', () => { @@ -20,7 +21,7 @@ describe('JavaScriptObfuscator', () => { describe('if `sourceMap` option is `false`', () => { it('should returns object with obfuscated code and empty source map', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 1;`, + readFileAsString(__dirname + '/fixtures/simple-input-1.js'), { ...NO_CUSTOM_NODES_PRESET } @@ -34,7 +35,7 @@ describe('JavaScriptObfuscator', () => { describe('if `sourceMap` option is `true`', () => { it('should returns object with obfuscated code and source map', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 1;`, + readFileAsString(__dirname + '/fixtures/simple-input-1.js'), { ...NO_CUSTOM_NODES_PRESET, sourceMap: true @@ -47,7 +48,7 @@ describe('JavaScriptObfuscator', () => { it('should returns object with obfuscated code with inline source map as Base64 string', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 1;`, + readFileAsString(__dirname + '/fixtures/simple-input-1.js'), { ...NO_CUSTOM_NODES_PRESET, sourceMap: true, @@ -65,7 +66,7 @@ describe('JavaScriptObfuscator', () => { it('should returns object with empty obfuscated code and source map with empty data if source code is empty', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - '', + readFileAsString(__dirname + '/fixtures/empty-input.js'), { sourceMap: true } @@ -81,7 +82,7 @@ describe('JavaScriptObfuscator', () => { it('should returns an empty string if source code is empty', () => { assert.isNotOk( JavaScriptObfuscator.obfuscate( - '' + readFileAsString(__dirname + '/fixtures/empty-input.js'), ).getObfuscatedCode() ); }); @@ -89,7 +90,7 @@ describe('JavaScriptObfuscator', () => { it('should returns an empty string if source code contains only comments', () => { assert.isNotOk( JavaScriptObfuscator.obfuscate( - '// comment' + readFileAsString(__dirname + '/fixtures/comments-only.js'), ).getObfuscatedCode() ); }); @@ -97,7 +98,7 @@ describe('JavaScriptObfuscator', () => { it('should obfuscate simple code with variable inside global scope', () => { assert.match( JavaScriptObfuscator.obfuscate( - `var test = 1;`, + readFileAsString(__dirname + '/fixtures/simple-input-1.js'), { ...NO_CUSTOM_NODES_PRESET } @@ -109,7 +110,7 @@ describe('JavaScriptObfuscator', () => { it('should obfuscate simple code with variable inside block-scope', () => { assert.match( JavaScriptObfuscator.obfuscate( - `(function () {var test = 1;})()`, + readFileAsString(__dirname + '/fixtures/block-scope.js'), { ...NO_CUSTOM_NODES_PRESET } @@ -122,7 +123,7 @@ describe('JavaScriptObfuscator', () => { let pattern1: RegExp = /^var _0x(\w){4} *= *\['(\\[x|u]\d+)+'\];/, pattern2: RegExp = /var *test *= *_0x(\w){4}\('0x0'\);$/, obfuscatedCode1: string = JavaScriptObfuscator.obfuscate( - `var test = 'abc';`, + readFileAsString(__dirname + '/fixtures/simple-input-2.js'), { ...NO_CUSTOM_NODES_PRESET, stringArray: true, @@ -130,7 +131,7 @@ describe('JavaScriptObfuscator', () => { } ).getObfuscatedCode(), obfuscatedCode2: string = JavaScriptObfuscator.obfuscate( - `var test = 'абц';`, + readFileAsString(__dirname + '/fixtures/simple-input-cyrillic.js'), { ...NO_CUSTOM_NODES_PRESET, stringArray: true, diff --git a/test/functional-tests/javascript-obfuscator/fixtures/block-scope.js b/test/functional-tests/javascript-obfuscator/fixtures/block-scope.js new file mode 100644 index 00000000..e43721fa --- /dev/null +++ b/test/functional-tests/javascript-obfuscator/fixtures/block-scope.js @@ -0,0 +1 @@ +(function () {var test = 1;})() \ No newline at end of file diff --git a/test/functional-tests/javascript-obfuscator/fixtures/comments-only.js b/test/functional-tests/javascript-obfuscator/fixtures/comments-only.js new file mode 100644 index 00000000..e2c01e9c --- /dev/null +++ b/test/functional-tests/javascript-obfuscator/fixtures/comments-only.js @@ -0,0 +1 @@ +// comment \ No newline at end of file diff --git a/test/functional-tests/javascript-obfuscator/fixtures/empty-input.js b/test/functional-tests/javascript-obfuscator/fixtures/empty-input.js new file mode 100644 index 00000000..e69de29b diff --git a/test/functional-tests/javascript-obfuscator/fixtures/simple-input-1.js b/test/functional-tests/javascript-obfuscator/fixtures/simple-input-1.js new file mode 100644 index 00000000..f99241b0 --- /dev/null +++ b/test/functional-tests/javascript-obfuscator/fixtures/simple-input-1.js @@ -0,0 +1 @@ +var test = 1; \ No newline at end of file diff --git a/test/functional-tests/javascript-obfuscator/fixtures/simple-input-2.js b/test/functional-tests/javascript-obfuscator/fixtures/simple-input-2.js new file mode 100644 index 00000000..3705f9b7 --- /dev/null +++ b/test/functional-tests/javascript-obfuscator/fixtures/simple-input-2.js @@ -0,0 +1 @@ +var test = 'abc'; \ No newline at end of file diff --git a/test/functional-tests/javascript-obfuscator/fixtures/simple-input-cyrillic.js b/test/functional-tests/javascript-obfuscator/fixtures/simple-input-cyrillic.js new file mode 100644 index 00000000..39675d2c --- /dev/null +++ b/test/functional-tests/javascript-obfuscator/fixtures/simple-input-cyrillic.js @@ -0,0 +1 @@ +var test = 'абц'; \ No newline at end of file diff --git a/test/functional-tests/node-transformers/control-flow-transformers/BlockStatementControlFlowTransformer.spec.ts b/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/BlockStatementControlFlowTransformer.spec.ts similarity index 84% rename from test/functional-tests/node-transformers/control-flow-transformers/BlockStatementControlFlowTransformer.spec.ts rename to test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/BlockStatementControlFlowTransformer.spec.ts index e99fd2a3..d8a3592a 100644 --- a/test/functional-tests/node-transformers/control-flow-transformers/BlockStatementControlFlowTransformer.spec.ts +++ b/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/BlockStatementControlFlowTransformer.spec.ts @@ -1,20 +1,18 @@ import { assert } from 'chai'; -import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult'; +import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult'; -import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes'; +import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; -import { readFileAsString } from '../../../helpers/readFileAsString'; +import { readFileAsString } from '../../../../helpers/readFileAsString'; -import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; +import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscator'; describe('BlockStatementControlFlowTransformer', () => { describe('transformNode (blockStatementNode: ESTree.BlockStatement): ESTree.Node', () => { describe('variant #1: 5 simple statements', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-1.js' - ), + readFileAsString(__dirname + '/fixtures/input-1.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -59,9 +57,7 @@ describe('BlockStatementControlFlowTransformer', () => { describe('variant #2: 5 simple statements inside while loop without break or continue statement', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-2.js' - ), + readFileAsString(__dirname + '/fixtures/input-2.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -106,9 +102,7 @@ describe('BlockStatementControlFlowTransformer', () => { describe('variant #3: less then 5 statements', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-one-statement.js' - ), + readFileAsString(__dirname + '/fixtures/one-statement.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -126,9 +120,7 @@ describe('BlockStatementControlFlowTransformer', () => { describe('variant #4: const declaration inside block statement', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-const-declaration.js' - ), + readFileAsString(__dirname + '/fixtures/const-declaration.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -146,9 +138,7 @@ describe('BlockStatementControlFlowTransformer', () => { describe('variant #5: let declaration inside block statement', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-let-declaration.js' - ), + readFileAsString(__dirname + '/fixtures/let-declaration.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -166,9 +156,7 @@ describe('BlockStatementControlFlowTransformer', () => { describe('variant #6: break statement inside block statement', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-break-statement.js' - ), + readFileAsString(__dirname + '/fixtures/break-statement.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -186,9 +174,7 @@ describe('BlockStatementControlFlowTransformer', () => { describe('variant #7: continue statement inside block statement', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-continue-statement.js' - ), + readFileAsString(__dirname + '/fixtures/continue-statement.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -206,9 +192,7 @@ describe('BlockStatementControlFlowTransformer', () => { describe('variant #8: function declaration inside block statement', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-function-declaration.js' - ), + readFileAsString(__dirname + '/fixtures/function-declaration.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -229,9 +213,7 @@ describe('BlockStatementControlFlowTransformer', () => { const controlFlowFlatteningThreshold: number = 0.5; const delta: number = 0.1; const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-1.js' - ).repeat(samples), + readFileAsString(__dirname + '/fixtures/input-1.js').repeat(samples), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, diff --git a/test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-break-statement.js b/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/break-statement.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-break-statement.js rename to test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/break-statement.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-const-declaration.js b/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/const-declaration.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-const-declaration.js rename to test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/const-declaration.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-continue-statement.js b/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/continue-statement.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-continue-statement.js rename to test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/continue-statement.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-function-declaration.js b/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/function-declaration.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-function-declaration.js rename to test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/function-declaration.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-1.js b/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/input-1.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-1.js rename to test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/input-1.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-2.js b/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/input-2.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-2.js rename to test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/input-2.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-let-declaration.js b/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/let-declaration.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-let-declaration.js rename to test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/let-declaration.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-one-statement.js b/test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/one-statement.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/block-statement-control-flow-transformer-one-statement.js rename to test/functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/fixtures/one-statement.js diff --git a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.spec.ts b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer/BinaryExpressionControlFlowReplacer.spec.ts similarity index 78% rename from test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.spec.ts rename to test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer/BinaryExpressionControlFlowReplacer.spec.ts index 6e083cde..b62abade 100644 --- a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.spec.ts +++ b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer/BinaryExpressionControlFlowReplacer.spec.ts @@ -1,20 +1,18 @@ import { assert } from 'chai'; -import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult'; +import { IObfuscationResult } from '../../../../../../src/interfaces/IObfuscationResult'; -import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; +import { NO_CUSTOM_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes'; -import { readFileAsString } from '../../../../helpers/readFileAsString'; +import { readFileAsString } from '../../../../../helpers/readFileAsString'; -import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscator'; +import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscator'; describe('BinaryExpressionControlFlowReplacer', () => { describe('replace (binaryExpressionNode: ESTree.BinaryExpression,parentNode: ESTree.Node,controlFlowStorage: IStorage )', () => { describe('variant #1 - single binary expression', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer-1.js' - ), + readFileAsString(__dirname + '/fixtures/input-1.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -31,9 +29,9 @@ describe('BinaryExpressionControlFlowReplacer', () => { describe('variant #2 - multiple binary expressions with threshold = 1', () => { it('should replace binary expression node by call to control flow storage node', function () { - this.timeout(4000); + this.timeout(15000); - const samplesCount: number = 200; + const samplesCount: number = 1000; const expectedValue: number = 0.5; const delta: number = 0.1; @@ -41,9 +39,7 @@ describe('BinaryExpressionControlFlowReplacer', () => { for (let i = 0; i < samplesCount; i++) { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer-2.js' - ), + readFileAsString(__dirname + '/fixtures/input-2.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, diff --git a/test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer-1.js b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer/fixtures/input-1.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer-1.js rename to test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer/fixtures/input-1.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer-2.js b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer/fixtures/input-2.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer-2.js rename to test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer/fixtures/input-2.js diff --git a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer.spec.ts b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/CallExpressionControlFlowReplacer.spec.ts similarity index 79% rename from test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer.spec.ts rename to test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/CallExpressionControlFlowReplacer.spec.ts index a4a1ab61..8f022fb1 100644 --- a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer.spec.ts +++ b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/CallExpressionControlFlowReplacer.spec.ts @@ -1,20 +1,18 @@ import { assert } from 'chai'; -import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult'; +import { IObfuscationResult } from '../../../../../../src/interfaces/IObfuscationResult'; -import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; +import { NO_CUSTOM_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes'; -import { readFileAsString } from '../../../../helpers/readFileAsString'; +import { readFileAsString } from '../../../../../helpers/readFileAsString'; -import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscator'; +import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscator'; describe('CallExpressionControlFlowReplacer', () => { describe('replace (callExpressionNode: ESTree.CallExpression,parentNode: ESTree.Node,controlFlowStorage: IStorage )', () => { describe('variant #1 - single call expression', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer-1.js' - ), + readFileAsString(__dirname + '/fixtures/input-1.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -31,9 +29,9 @@ describe('CallExpressionControlFlowReplacer', () => { describe('variant #2 - multiple call expressions with threshold = 1', () => { it('should replace call expression node by call to control flow storage node', function () { - this.timeout(4000); + this.timeout(15000); - const samplesCount: number = 200; + const samplesCount: number = 1000; const expectedValue: number = 0.5; const delta: number = 0.1; @@ -41,9 +39,7 @@ describe('CallExpressionControlFlowReplacer', () => { for (let i = 0; i < samplesCount; i++) { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer-2.js' - ), + readFileAsString(__dirname + '/fixtures/input-2.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -76,9 +72,7 @@ describe('CallExpressionControlFlowReplacer', () => { describe('variant #3 - callee - member expression', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer-3.js' - ), + readFileAsString(__dirname + '/fixtures/input-3.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, diff --git a/test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer-1.js b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/fixtures/input-1.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer-1.js rename to test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/fixtures/input-1.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer-2.js b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/fixtures/input-2.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer-2.js rename to test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/fixtures/input-2.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer-3.js b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/fixtures/input-3.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer-3.js rename to test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/fixtures/input-3.js diff --git a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/LogicalExpressionControlFlowReplacer.spec.ts b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer/LogicalExpressionControlFlowReplacer.spec.ts similarity index 78% rename from test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/LogicalExpressionControlFlowReplacer.spec.ts rename to test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer/LogicalExpressionControlFlowReplacer.spec.ts index 5683fee5..c200be9b 100644 --- a/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/LogicalExpressionControlFlowReplacer.spec.ts +++ b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer/LogicalExpressionControlFlowReplacer.spec.ts @@ -1,20 +1,18 @@ import { assert } from 'chai'; -import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult'; +import { IObfuscationResult } from '../../../../../../src/interfaces/IObfuscationResult'; -import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; +import { NO_CUSTOM_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes'; -import { readFileAsString } from '../../../../helpers/readFileAsString'; +import { readFileAsString } from '../../../../../helpers/readFileAsString'; -import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscator'; +import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscator'; describe('LogicalExpressionControlFlowReplacer', () => { describe('replace (logicalExpressionNode: ESTree.LogicalExpression,parentNode: ESTree.Node,controlFlowStorage: IStorage )', () => { describe('variant #1 - single logical expression', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer-1.js' - ), + readFileAsString(__dirname + '/fixtures/input-1.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -31,9 +29,9 @@ describe('LogicalExpressionControlFlowReplacer', () => { describe('variant #2 - multiple logical expressions with threshold = 1', () => { it('should replace logical expression node by call to control flow storage node', function () { - this.timeout(4000); + this.timeout(15000); - const samplesCount: number = 200; + const samplesCount: number = 1000; const expectedValue: number = 0.5; const delta: number = 0.1; @@ -41,9 +39,7 @@ describe('LogicalExpressionControlFlowReplacer', () => { for (let i = 0; i < samplesCount; i++) { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer-2.js' - ), + readFileAsString(__dirname + '/fixtures/input-2.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -76,9 +72,7 @@ describe('LogicalExpressionControlFlowReplacer', () => { describe('variant #3 - single logical expression with unary expression', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer-3.js' - ), + readFileAsString(__dirname + '/fixtures/input-3.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -95,9 +89,7 @@ describe('LogicalExpressionControlFlowReplacer', () => { describe('prohibited nodes variant #1', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer-prohibited-nodes-1.js' - ), + readFileAsString(__dirname + '/fixtures/prohibited-nodes.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, diff --git a/test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer-1.js b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer/fixtures/input-1.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer-1.js rename to test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer/fixtures/input-1.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer-2.js b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer/fixtures/input-2.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer-2.js rename to test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer/fixtures/input-2.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer-3.js b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer/fixtures/input-3.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer-3.js rename to test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer/fixtures/input-3.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer-prohibited-nodes-1.js b/test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer/fixtures/prohibited-nodes.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer-prohibited-nodes-1.js rename to test/functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer/fixtures/prohibited-nodes.js diff --git a/test/functional-tests/node-transformers/control-flow-transformers/FunctionControlFlowTransformer.spec.ts b/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/FunctionControlFlowTransformer.spec.ts similarity index 83% rename from test/functional-tests/node-transformers/control-flow-transformers/FunctionControlFlowTransformer.spec.ts rename to test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/FunctionControlFlowTransformer.spec.ts index 791c92ca..de1ae2bf 100644 --- a/test/functional-tests/node-transformers/control-flow-transformers/FunctionControlFlowTransformer.spec.ts +++ b/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/FunctionControlFlowTransformer.spec.ts @@ -1,12 +1,12 @@ import { assert } from 'chai'; -import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult'; +import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult'; -import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes'; +import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; -import { readFileAsString } from '../../../helpers/readFileAsString'; +import { readFileAsString } from '../../../../helpers/readFileAsString'; -import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; +import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscator'; describe('FunctionControlFlowTransformer', () => { const variableMatch: string = '_0x([a-z0-9]){4,6}'; @@ -28,9 +28,7 @@ describe('FunctionControlFlowTransformer', () => { describe('transformNode (functionNode: ESTree.Function): ESTree.Node', () => { describe('variant #1 - single `control flow storage` node with single item', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-1.js' - ), + readFileAsString(__dirname + '/fixtures/input-1.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -46,7 +44,7 @@ describe('FunctionControlFlowTransformer', () => { }); describe('variant #2 - two `control flow storage` nodes: root and inner', () => { - const samplesCount: number = 200; + const samplesCount: number = 1000; const delta: number = 0.1; const expectedValue: number = 0.5; const regExp1: RegExp = new RegExp( @@ -62,9 +60,7 @@ describe('FunctionControlFlowTransformer', () => { for (let i = 0; i < samplesCount; i++) { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-2.js' - ), + readFileAsString(__dirname + '/fixtures/input-2.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -89,9 +85,7 @@ describe('FunctionControlFlowTransformer', () => { describe('variant #3 - single `control flow storage` node with multiple items', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-multiple-items-1.js' - ), + readFileAsString(__dirname + '/fixtures/multiple-items.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -117,9 +111,7 @@ describe('FunctionControlFlowTransformer', () => { describe('variant #4 - no `control flow storage` node to the root block scope', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-root-block-scope-1.js' - ), + readFileAsString(__dirname + '/fixtures/root-block-scope-1.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -150,9 +142,7 @@ describe('FunctionControlFlowTransformer', () => { for (let i = 0; i < samplesCount; i++) { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-root-block-scope-2.js' - ), + readFileAsString(__dirname + '/fixtures/root-block-scope-2.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, @@ -172,9 +162,7 @@ describe('FunctionControlFlowTransformer', () => { describe('variant #6 - no single `control flow storage` node when threshold is 0', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-zero-threshold.js' - ), + readFileAsString(__dirname + '/fixtures/zero-threshold.js'), { ...NO_CUSTOM_NODES_PRESET, controlFlowFlattening: true, diff --git a/test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-1.js b/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/input-1.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-1.js rename to test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/input-1.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-2.js b/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/input-2.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-2.js rename to test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/input-2.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-multiple-items-1.js b/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/multiple-items.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-multiple-items-1.js rename to test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/multiple-items.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-root-block-scope-1.js b/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/root-block-scope-1.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-root-block-scope-1.js rename to test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/root-block-scope-1.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-root-block-scope-2.js b/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/root-block-scope-2.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-root-block-scope-2.js rename to test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/root-block-scope-2.js diff --git a/test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-zero-threshold.js b/test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/zero-threshold.js similarity index 100% rename from test/fixtures/node-transformers/control-flow-transformers/function-control-flow-transformer-zero-threshold.js rename to test/functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/fixtures/zero-threshold.js diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/CatchClauseTransformer.spec.ts b/test/functional-tests/node-transformers/obfuscation-transformers/catch-clause-transformer/CatchClauseTransformer.spec.ts similarity index 72% rename from test/functional-tests/node-transformers/obfuscation-transformers/CatchClauseTransformer.spec.ts rename to test/functional-tests/node-transformers/obfuscation-transformers/catch-clause-transformer/CatchClauseTransformer.spec.ts index b4b614c6..b058534d 100644 --- a/test/functional-tests/node-transformers/obfuscation-transformers/CatchClauseTransformer.spec.ts +++ b/test/functional-tests/node-transformers/obfuscation-transformers/catch-clause-transformer/CatchClauseTransformer.spec.ts @@ -1,19 +1,17 @@ import { assert } from 'chai'; -import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult'; +import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult'; -import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes'; +import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; -import { readFileAsString } from '../../../helpers/readFileAsString'; +import { readFileAsString } from '../../../../helpers/readFileAsString'; -import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; +import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscator'; describe('CatchClauseTransformer', () => { describe('changeControlFlow (catchClauseNode: ESTree.CatchClause): void', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/obfuscation-transformers/catch-clause-transformer.js' - ), + readFileAsString(__dirname + '/fixtures/input.js'), { ...NO_CUSTOM_NODES_PRESET } @@ -22,7 +20,7 @@ describe('CatchClauseTransformer', () => { const paramNameRegExp: RegExp = /catch *\((_0x([a-z0-9]){4,6})\) *\{/; const bodyParamNameRegExp: RegExp = /console\['\\x6c\\x6f\\x67'\]\((_0x([a-z0-9]){4,6})\);/; - it('should obfuscate catch clause node', () => { + it('should transform catch clause node', () => { assert.match(obfuscatedCode, paramNameRegExp); assert.match(obfuscatedCode, bodyParamNameRegExp); }); diff --git a/test/fixtures/node-transformers/obfuscation-transformers/catch-clause-transformer.js b/test/functional-tests/node-transformers/obfuscation-transformers/catch-clause-transformer/fixtures/input.js similarity index 100% rename from test/fixtures/node-transformers/obfuscation-transformers/catch-clause-transformer.js rename to test/functional-tests/node-transformers/obfuscation-transformers/catch-clause-transformer/fixtures/input.js diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/FunctionDeclarationTransformer.spec.ts b/test/functional-tests/node-transformers/obfuscation-transformers/function-declaration-transformer/FunctionDeclarationTransformer.spec.ts similarity index 67% rename from test/functional-tests/node-transformers/obfuscation-transformers/FunctionDeclarationTransformer.spec.ts rename to test/functional-tests/node-transformers/obfuscation-transformers/function-declaration-transformer/FunctionDeclarationTransformer.spec.ts index bae67887..3484cef2 100644 --- a/test/functional-tests/node-transformers/obfuscation-transformers/FunctionDeclarationTransformer.spec.ts +++ b/test/functional-tests/node-transformers/obfuscation-transformers/function-declaration-transformer/FunctionDeclarationTransformer.spec.ts @@ -1,35 +1,24 @@ import { assert } from 'chai'; -import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult'; +import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult'; -import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes'; +import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; -import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; +import { readFileAsString } from '../../../../helpers/readFileAsString'; + +import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscator'; describe('FunctionDeclarationTransformer', () => { - describe('obfuscation of `functionDeclaration` node names', () => { + describe('transformation of `functionDeclaration` node names', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - ` - function foo () { - function bar () { - } - - if (true) { - bar(); - } - } - - if (true) { - foo(); - } - `, + readFileAsString(__dirname + '/fixtures/input.js'), { ...NO_CUSTOM_NODES_PRESET } ); const obfuscatedCode: string = obfuscationResult.getObfuscatedCode(); - it('shouldn\'t obfuscate function name if `functionDeclaration` parent block scope is a `ProgramNode`', () => { + it('shouldn\'t transform function name if `functionDeclaration` parent block scope is a `ProgramNode`', () => { const functionNameIdentifierMatch: RegExpMatchArray|null = obfuscatedCode .match(/function *foo *\(\) *\{/); const functionCallIdentifierMatch: RegExpMatchArray|null = obfuscatedCode @@ -41,7 +30,7 @@ describe('FunctionDeclarationTransformer', () => { assert.equal(functionParamIdentifierName, functionBodyIdentifierName); }); - it('should obfuscate function name if `functionDeclaration` parent block scope is not a `ProgramNode`', () => { + it('should transform function name if `functionDeclaration` parent block scope is not a `ProgramNode`', () => { const functionNameIdentifierMatch: RegExpMatchArray|null = obfuscatedCode .match(/function *_0x[a-z0-9]{4,6} *\(\) *\{/); const functionCallIdentifierMatch: RegExpMatchArray|null = obfuscatedCode diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/function-declaration-transformer/fixtures/input.js b/test/functional-tests/node-transformers/obfuscation-transformers/function-declaration-transformer/fixtures/input.js new file mode 100644 index 00000000..dac26c65 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/function-declaration-transformer/fixtures/input.js @@ -0,0 +1,12 @@ +function foo () { + function bar () { + } + + if (true) { + bar(); + } +} + +if (true) { + foo(); +} diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/FunctionTransformer.spec.ts b/test/functional-tests/node-transformers/obfuscation-transformers/function-transformer/FunctionTransformer.spec.ts similarity index 55% rename from test/functional-tests/node-transformers/obfuscation-transformers/FunctionTransformer.spec.ts rename to test/functional-tests/node-transformers/obfuscation-transformers/function-transformer/FunctionTransformer.spec.ts index 532d6b24..6b7064bc 100644 --- a/test/functional-tests/node-transformers/obfuscation-transformers/FunctionTransformer.spec.ts +++ b/test/functional-tests/node-transformers/obfuscation-transformers/function-transformer/FunctionTransformer.spec.ts @@ -1,36 +1,24 @@ import { assert } from 'chai'; -import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult'; +import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult'; -import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes'; +import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; -import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; +import { readFileAsString } from '../../../../helpers/readFileAsString'; + +import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscator'; describe('FunctionTransformer', () => { - describe('identifiers obfuscation inside `FunctionDeclaration` and `FunctionExpression` node body', () => { + describe('identifiers transformation inside `FunctionDeclaration` and `FunctionExpression` node body', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - ` - (function () { - var test = function (test) { - console.log(test); - - if (true) { - var test = 5 - } - - variable = 6; - - return test; - } - })(); - `, + readFileAsString(__dirname + '/fixtures/input.js'), { ...NO_CUSTOM_NODES_PRESET } ); const obfuscatedCode: string = obfuscationResult.getObfuscatedCode(); - it('should correct obfuscate both function parameter identifier and function body identifier with same name', () => { + it('should correct transform both function parameter identifier and function body identifier with same name', () => { const functionParamIdentifierMatch: RegExpMatchArray|null = obfuscatedCode .match(/var _0x[a-z0-9]{4,6} *= *function *\((_0x[a-z0-9]{4,6})\) *\{/); const functionBodyIdentifierMatch: RegExpMatchArray|null = obfuscatedCode @@ -42,7 +30,7 @@ describe('FunctionTransformer', () => { assert.equal(functionParamIdentifierName, functionBodyIdentifierName); }); - it('shouldn\'t obfuscate other variables in function body', () => { + it('shouldn\'t transform other variables in function body', () => { assert.equal(/variable *= *0x6;/.test(obfuscatedCode), true); }); }); diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/function-transformer/fixtures/input.js b/test/functional-tests/node-transformers/obfuscation-transformers/function-transformer/fixtures/input.js new file mode 100644 index 00000000..aa74b4c4 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/function-transformer/fixtures/input.js @@ -0,0 +1,13 @@ +(function () { + var test = function (test) { + console.log(test); + + if (true) { + var test = 5 + } + + variable = 6; + + return test; + } +})(); diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/LabeledStatementTransformer.spec.ts b/test/functional-tests/node-transformers/obfuscation-transformers/labeled-statement-transformer/LabeledStatementTransformer.spec.ts similarity index 73% rename from test/functional-tests/node-transformers/obfuscation-transformers/LabeledStatementTransformer.spec.ts rename to test/functional-tests/node-transformers/obfuscation-transformers/labeled-statement-transformer/LabeledStatementTransformer.spec.ts index 8337634b..06c4ca64 100644 --- a/test/functional-tests/node-transformers/obfuscation-transformers/LabeledStatementTransformer.spec.ts +++ b/test/functional-tests/node-transformers/obfuscation-transformers/labeled-statement-transformer/LabeledStatementTransformer.spec.ts @@ -1,19 +1,17 @@ import { assert } from 'chai'; -import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult'; +import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult'; -import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes'; +import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; -import { readFileAsString } from '../../../helpers/readFileAsString'; +import { readFileAsString } from '../../../../helpers/readFileAsString'; -import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; +import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscator'; describe('LabeledStatementTransformer', () => { describe('changeControlFlow (labeledStatementNode: ESTree.LabeledStatement): void', () => { const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - readFileAsString( - './test/fixtures/node-transformers/obfuscation-transformers/labeled-statement-transformer.js' - ), + readFileAsString(__dirname + '/fixtures/input.js'), { ...NO_CUSTOM_NODES_PRESET } @@ -23,15 +21,15 @@ describe('LabeledStatementTransformer', () => { const continueStatementRegExp: RegExp = /continue *(_0x([a-z0-9]){4,6});/; const breakStatementRegExp: RegExp = /break *(_0x([a-z0-9]){4,6});/; - it('should obfuscate `labeledStatement` identifier', () => { + it('should transform `labeledStatement` identifier', () => { assert.match(obfuscatedCode, labeledStatementRegExp); }); - it('should obfuscate `continueStatement` identifier', () => { + it('should transform `continueStatement` identifier', () => { assert.match(obfuscatedCode, continueStatementRegExp); }); - it('should obfuscate `breakStatement` identifier', () => { + it('should transform `breakStatement` identifier', () => { assert.match(obfuscatedCode, breakStatementRegExp); }); diff --git a/test/fixtures/node-transformers/obfuscation-transformers/labeled-statement-transformer.js b/test/functional-tests/node-transformers/obfuscation-transformers/labeled-statement-transformer/fixtures/input.js similarity index 100% rename from test/fixtures/node-transformers/obfuscation-transformers/labeled-statement-transformer.js rename to test/functional-tests/node-transformers/obfuscation-transformers/labeled-statement-transformer/fixtures/input.js diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/LiteralTransformer.spec.ts b/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/LiteralTransformer.spec.ts similarity index 83% rename from test/functional-tests/node-transformers/obfuscation-transformers/LiteralTransformer.spec.ts rename to test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/LiteralTransformer.spec.ts index 8ddbcfc8..06034920 100644 --- a/test/functional-tests/node-transformers/obfuscation-transformers/LiteralTransformer.spec.ts +++ b/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/LiteralTransformer.spec.ts @@ -1,18 +1,18 @@ import { assert } from 'chai'; -import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult'; +import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult'; -import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes'; +import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; -import { readFileAsString } from '../../../helpers/readFileAsString'; +import { readFileAsString } from '../../../../helpers/readFileAsString'; -import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; +import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscator'; describe('LiteralTransformer', () => { - describe('obfuscation of literal node with string value', () => { + describe('transformation of literal node with string value', () => { it('should replace literal node value with unicode escape sequence', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, + readFileAsString(__dirname + '/fixtures/simple-input.js'), { ...NO_CUSTOM_NODES_PRESET } @@ -23,7 +23,7 @@ describe('LiteralTransformer', () => { it('should replace literal node value with unicode escape sequence from string array', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, + readFileAsString(__dirname + '/fixtures/simple-input.js'), { ...NO_CUSTOM_NODES_PRESET, stringArray: true, @@ -40,11 +40,7 @@ describe('LiteralTransformer', () => { it('should create only one item in string array for same literal node values', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - ` - var test = 'test'; - var test = 'test'; - object.test(); - `, + readFileAsString(__dirname + '/fixtures/same-literal-values.js'), { ...NO_CUSTOM_NODES_PRESET, stringArray: true, @@ -61,7 +57,7 @@ describe('LiteralTransformer', () => { it('should replace literal node value with raw value from string array if `unicodeEscapeSequence` is disabled', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, + readFileAsString(__dirname + '/fixtures/simple-input.js'), { ...NO_CUSTOM_NODES_PRESET, stringArray: true, @@ -79,7 +75,7 @@ describe('LiteralTransformer', () => { it('should replace literal node value with raw value from string array if `unicodeEscapeSequence` and `stringArray` are disabled', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, + readFileAsString(__dirname + '/fixtures/simple-input.js'), { ...NO_CUSTOM_NODES_PRESET, unicodeEscapeSequence: false @@ -94,7 +90,7 @@ describe('LiteralTransformer', () => { it('should\'t throw an error when string contains non-latin and non-digit characters and `unicodeEscapeSequence` is disabled', () => { assert.doesNotThrow(() => JavaScriptObfuscator.obfuscate( - readFileAsString('./test/fixtures/node-transformers/obfuscation-transformers/literal-transformer-unicode-sequence.js'), + readFileAsString(__dirname + '/fixtures/error-when-non-latin.js'), { ...NO_CUSTOM_NODES_PRESET, stringArray: true, @@ -106,7 +102,7 @@ describe('LiteralTransformer', () => { it('shouldn\'t replace short literal node value with value from string array', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'te';`, + readFileAsString(__dirname + '/fixtures/short-literal-value.js'), { ...NO_CUSTOM_NODES_PRESET, stringArray: true, @@ -119,7 +115,7 @@ describe('LiteralTransformer', () => { it('should replace literal node value with value from string array encoded using base64', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, + readFileAsString(__dirname + '/fixtures/simple-input.js'), { ...NO_CUSTOM_NODES_PRESET, stringArray: true, @@ -137,7 +133,7 @@ describe('LiteralTransformer', () => { it('should replace literal node value with value from string array encoded using rc4', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, + readFileAsString(__dirname + '/fixtures/simple-input.js'), { ...NO_CUSTOM_NODES_PRESET, stringArray: true, @@ -157,7 +153,7 @@ describe('LiteralTransformer', () => { const stringArrayThreshold: number = 0.5; const delta: number = 0.1; const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';\n`.repeat(samples), + `${readFileAsString(__dirname + '/fixtures/simple-input.js')}\n`.repeat(samples), { ...NO_CUSTOM_NODES_PRESET, stringArray: true, @@ -175,9 +171,9 @@ describe('LiteralTransformer', () => { }); }); - it('should obfuscate literal node with boolean value', () => { + it('should transform literal node with boolean value', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = true;`, + readFileAsString(__dirname + '/fixtures/boolean-value.js'), { ...NO_CUSTOM_NODES_PRESET, stringArray: true, @@ -188,9 +184,9 @@ describe('LiteralTransformer', () => { assert.match(obfuscationResult.getObfuscatedCode(), /^var *test *= *!!\[\];$/); }); - it('should obfuscate literal node with number value', () => { + it('should transform literal node with number value', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 0;`, + readFileAsString(__dirname + '/fixtures/number-value.js'), { ...NO_CUSTOM_NODES_PRESET, stringArray: true, diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/boolean-value.js b/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/boolean-value.js new file mode 100644 index 00000000..7a4b5f6a --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/boolean-value.js @@ -0,0 +1 @@ +var test = true; diff --git a/test/fixtures/node-transformers/obfuscation-transformers/literal-transformer-unicode-sequence.js b/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/error-when-non-latin.js similarity index 100% rename from test/fixtures/node-transformers/obfuscation-transformers/literal-transformer-unicode-sequence.js rename to test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/error-when-non-latin.js diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/number-value.js b/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/number-value.js new file mode 100644 index 00000000..78afc588 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/number-value.js @@ -0,0 +1 @@ +var test = 0; diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/same-literal-values.js b/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/same-literal-values.js new file mode 100644 index 00000000..764b2cac --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/same-literal-values.js @@ -0,0 +1,3 @@ +var test = 'test'; +var test = 'test'; +object.test(); \ No newline at end of file diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/short-literal-value.js b/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/short-literal-value.js new file mode 100644 index 00000000..7abc01ad --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/short-literal-value.js @@ -0,0 +1 @@ +var test = 'te'; diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/simple-input.js b/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/simple-input.js new file mode 100644 index 00000000..7e66b5c5 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/literal-transformer/fixtures/simple-input.js @@ -0,0 +1 @@ +var test = 'test'; diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/MemberExpressionTransformer.spec.ts b/test/functional-tests/node-transformers/obfuscation-transformers/member-expression-transformer/MemberExpressionTransformer.spec.ts similarity index 72% rename from test/functional-tests/node-transformers/obfuscation-transformers/MemberExpressionTransformer.spec.ts rename to test/functional-tests/node-transformers/obfuscation-transformers/member-expression-transformer/MemberExpressionTransformer.spec.ts index e17dab20..dd8fcb7f 100644 --- a/test/functional-tests/node-transformers/obfuscation-transformers/MemberExpressionTransformer.spec.ts +++ b/test/functional-tests/node-transformers/obfuscation-transformers/member-expression-transformer/MemberExpressionTransformer.spec.ts @@ -1,16 +1,18 @@ import { assert } from 'chai'; -import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult'; +import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult'; -import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes'; +import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; -import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; +import { readFileAsString } from '../../../../helpers/readFileAsString'; + +import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscator'; describe('MemberExpressionTransformer', () => { - describe('obfuscation of member expression node with dot notation', () => { + describe('transformation of member expression node with dot notation', () => { it('should replace member expression dot notation call by square brackets call with unicode literal value', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = console.log;`, + readFileAsString(__dirname + '/fixtures/dot-notation-call.js'), { ...NO_CUSTOM_NODES_PRESET } @@ -21,7 +23,7 @@ describe('MemberExpressionTransformer', () => { it('should replace member expression dot notation call by square brackets call to unicode array', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = console.log;`, + readFileAsString(__dirname + '/fixtures/dot-notation-call.js'), { ...NO_CUSTOM_NODES_PRESET, stringArray: true, @@ -34,10 +36,10 @@ describe('MemberExpressionTransformer', () => { }); }); - describe('obfuscation of member expression node without dot notation', () => { + describe('transformation of member expression node without dot notation', () => { it('should replace member expression square brackets call by square brackets call to unicode array', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = console['log'];`, + readFileAsString(__dirname + '/fixtures/square-brackets-call.js'), { ...NO_CUSTOM_NODES_PRESET, stringArray: true, @@ -51,10 +53,7 @@ describe('MemberExpressionTransformer', () => { it('should ignore square brackets call with identifier value', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - ` - var identifier = 'log'; - var test = console[identifier]; - `, + readFileAsString(__dirname + '/fixtures/square-brackets-with-identifier-call.js'), { ...NO_CUSTOM_NODES_PRESET } diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/member-expression-transformer/fixtures/dot-notation-call.js b/test/functional-tests/node-transformers/obfuscation-transformers/member-expression-transformer/fixtures/dot-notation-call.js new file mode 100644 index 00000000..99164519 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/member-expression-transformer/fixtures/dot-notation-call.js @@ -0,0 +1 @@ +var test = console.log; diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/member-expression-transformer/fixtures/square-brackets-call.js b/test/functional-tests/node-transformers/obfuscation-transformers/member-expression-transformer/fixtures/square-brackets-call.js new file mode 100644 index 00000000..97271a2b --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/member-expression-transformer/fixtures/square-brackets-call.js @@ -0,0 +1 @@ +var test = console['log']; diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/member-expression-transformer/fixtures/square-brackets-with-identifier-call.js b/test/functional-tests/node-transformers/obfuscation-transformers/member-expression-transformer/fixtures/square-brackets-with-identifier-call.js new file mode 100644 index 00000000..cdfdcc0d --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/member-expression-transformer/fixtures/square-brackets-with-identifier-call.js @@ -0,0 +1,2 @@ +var identifier = 'log'; +var test = console[identifier]; diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/MethodDefinitionTransformer.spec.ts b/test/functional-tests/node-transformers/obfuscation-transformers/method-definition-transformer/MethodDefinitionTransformer.spec.ts similarity index 74% rename from test/functional-tests/node-transformers/obfuscation-transformers/MethodDefinitionTransformer.spec.ts rename to test/functional-tests/node-transformers/obfuscation-transformers/method-definition-transformer/MethodDefinitionTransformer.spec.ts index bb082644..36e28ed8 100644 --- a/test/functional-tests/node-transformers/obfuscation-transformers/MethodDefinitionTransformer.spec.ts +++ b/test/functional-tests/node-transformers/obfuscation-transformers/method-definition-transformer/MethodDefinitionTransformer.spec.ts @@ -1,18 +1,15 @@ import { assert } from 'chai'; -import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult'; +import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult'; -import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes'; +import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; -import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; +import { readFileAsString } from '../../../../helpers/readFileAsString'; + +import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscator'; describe('MethodDefinitionTransformer', () => { - let code: string = ` - class Foo { - constructor () {} - bar () {} - } - `; + let code: string = readFileAsString(__dirname + '/fixtures/input.js'); it('should replace method definition node `key` property with unicode value', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( @@ -39,7 +36,7 @@ describe('MethodDefinitionTransformer', () => { assert.match(obfuscationResult.getObfuscatedCode(), /\[_0x([a-z0-9]){4}\('0x0'\)\]\(\)\{\}/); }); - it('should not obfuscate method definition node with `constructor` key', () => { + it('should not transform method definition node with `constructor` key', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( code, { diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/method-definition-transformer/fixtures/input.js b/test/functional-tests/node-transformers/obfuscation-transformers/method-definition-transformer/fixtures/input.js new file mode 100644 index 00000000..f3022a60 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/method-definition-transformer/fixtures/input.js @@ -0,0 +1,4 @@ +class Foo { + constructor () {} + bar () {} +} diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/ObjectExpressionTransformer.spec.ts b/test/functional-tests/node-transformers/obfuscation-transformers/object-expression-transformer/ObjectExpressionTransformer.spec.ts similarity index 53% rename from test/functional-tests/node-transformers/obfuscation-transformers/ObjectExpressionTransformer.spec.ts rename to test/functional-tests/node-transformers/obfuscation-transformers/object-expression-transformer/ObjectExpressionTransformer.spec.ts index 7ec5e893..7a76a684 100644 --- a/test/functional-tests/node-transformers/obfuscation-transformers/ObjectExpressionTransformer.spec.ts +++ b/test/functional-tests/node-transformers/obfuscation-transformers/object-expression-transformer/ObjectExpressionTransformer.spec.ts @@ -1,15 +1,17 @@ import { assert } from 'chai'; -import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult'; +import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult'; -import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes'; +import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; -import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; +import { readFileAsString } from '../../../../helpers/readFileAsString'; + +import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscator'; describe('ObjectExpressionTransformer', () => { it('should replace object expression node `key` property with literal value by unicode value', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = { 'foo': 0 };`, + readFileAsString(__dirname + '/fixtures/property-with-literal-value.js'), { ...NO_CUSTOM_NODES_PRESET } @@ -20,7 +22,7 @@ describe('ObjectExpressionTransformer', () => { it('should replace object expression node `key` property with identifier value by unicode value', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = { foo: 0 };`, + readFileAsString(__dirname + '/fixtures/property-with-identifier-value.js'), { ...NO_CUSTOM_NODES_PRESET } @@ -31,33 +33,7 @@ describe('ObjectExpressionTransformer', () => { it('should correct convert shorthand ES6 object expression to non-shorthand object expression', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - ` - (function () { - let a = 0; - let b = 0; - var test = {a, b}; - })(); - `, - { - ...NO_CUSTOM_NODES_PRESET - } - ); - - assert.match( - obfuscationResult.getObfuscatedCode(), - /var *_0x[a-z0-9]{4,6} *= *\{'\\x61': *_0x[a-z0-9]{4,6}\, *'\\x62': *_0x[a-z0-9]{4,6}\};/ - ); - }); - - it('should correct convert shorthand ES6 object expression to non-shorthand object expression', () => { - let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - ` - (function () { - let a = 0; - let b = 0; - var test = {a, b}; - })(); - `, + readFileAsString(__dirname + '/fixtures/shorthand-object-expression.js'), { ...NO_CUSTOM_NODES_PRESET } diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/object-expression-transformer/fixtures/property-with-identifier-value.js b/test/functional-tests/node-transformers/obfuscation-transformers/object-expression-transformer/fixtures/property-with-identifier-value.js new file mode 100644 index 00000000..ade76264 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/object-expression-transformer/fixtures/property-with-identifier-value.js @@ -0,0 +1 @@ +var test = { foo: 0 }; diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/object-expression-transformer/fixtures/property-with-literal-value.js b/test/functional-tests/node-transformers/obfuscation-transformers/object-expression-transformer/fixtures/property-with-literal-value.js new file mode 100644 index 00000000..6d6f291f --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/object-expression-transformer/fixtures/property-with-literal-value.js @@ -0,0 +1 @@ +var test = { 'foo': 0 }; diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/object-expression-transformer/fixtures/shorthand-object-expression.js b/test/functional-tests/node-transformers/obfuscation-transformers/object-expression-transformer/fixtures/shorthand-object-expression.js new file mode 100644 index 00000000..e8fdbe24 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/object-expression-transformer/fixtures/shorthand-object-expression.js @@ -0,0 +1,5 @@ +(function () { + let a = 0; + let b = 0; + var test = {a, b}; +})(); \ No newline at end of file diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/template-literal-transformer/TemplateLiteralTransformer.spec.ts b/test/functional-tests/node-transformers/obfuscation-transformers/template-literal-transformer/TemplateLiteralTransformer.spec.ts new file mode 100644 index 00000000..27b33d90 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/template-literal-transformer/TemplateLiteralTransformer.spec.ts @@ -0,0 +1,67 @@ +import { assert } from 'chai'; + +import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult'; + +import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; + +import { readFileAsString } from '../../../../helpers/readFileAsString'; + +import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscator'; + +describe('TemplateLiteralTransformer', () => { + describe('variant #1: simple template literal', () => { + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( + readFileAsString(__dirname + '/fixtures/simple-input.js'), + { + ...NO_CUSTOM_NODES_PRESET, + unicodeEscapeSequence: false + } + ); + + it('should transform es6 template literal to es5', () => { + assert.match(obfuscationResult.getObfuscatedCode(), /^var *test *= *'abc\\x20' *\+ *foo;$/); + }); + }); + + describe('variant #1: simple template literal with expression only', () => { + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( + readFileAsString(__dirname + '/fixtures/expression-only.js'), + { + ...NO_CUSTOM_NODES_PRESET, + unicodeEscapeSequence: false + } + ); + + it('should transform es6 template literal to es5 and add empty literal node before expression node', () => { + assert.match(obfuscationResult.getObfuscatedCode(), /^var *test *= *'' *\+ *foo;$/); + }); + }); + + describe('variant #3: literal node inside expression', () => { + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( + readFileAsString(__dirname + '/fixtures/literal-inside-expression.js'), + { + ...NO_CUSTOM_NODES_PRESET, + unicodeEscapeSequence: false + } + ); + + it('should transform es6 template literal to es5', () => { + assert.match(obfuscationResult.getObfuscatedCode(), /^var *test *= *'abc';$/); + }); + }); + + describe('variant #4: multiple expressions', () => { + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( + readFileAsString(__dirname + '/fixtures/multiple-expressions.js'), + { + ...NO_CUSTOM_NODES_PRESET, + unicodeEscapeSequence: false + } + ); + + it('should transform es6 template literal to es5', () => { + assert.match(obfuscationResult.getObfuscatedCode(), /^var *test *= *0x1 *\+ *0x1 *\+ *'\\x20abc\\x20' *\+ *\(0x1 *\+ *0x1\);$/); + }); + }); +}); diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/template-literal-transformer/fixtures/expression-only.js b/test/functional-tests/node-transformers/obfuscation-transformers/template-literal-transformer/fixtures/expression-only.js new file mode 100644 index 00000000..585ad0f9 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/template-literal-transformer/fixtures/expression-only.js @@ -0,0 +1 @@ +var test = `${foo}`; diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/template-literal-transformer/fixtures/literal-inside-expression.js b/test/functional-tests/node-transformers/obfuscation-transformers/template-literal-transformer/fixtures/literal-inside-expression.js new file mode 100644 index 00000000..aeb06222 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/template-literal-transformer/fixtures/literal-inside-expression.js @@ -0,0 +1 @@ +var test = `${'abc'}`; diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/template-literal-transformer/fixtures/multiple-expressions.js b/test/functional-tests/node-transformers/obfuscation-transformers/template-literal-transformer/fixtures/multiple-expressions.js new file mode 100644 index 00000000..420c157f --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/template-literal-transformer/fixtures/multiple-expressions.js @@ -0,0 +1 @@ +var test = `${1 + 1} abc ${1 + 1}`; diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/template-literal-transformer/fixtures/simple-input.js b/test/functional-tests/node-transformers/obfuscation-transformers/template-literal-transformer/fixtures/simple-input.js new file mode 100644 index 00000000..6d1a2ef0 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/template-literal-transformer/fixtures/simple-input.js @@ -0,0 +1 @@ +var test = `abc ${foo}`; diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/VariableDeclarationTransformer.spec.ts b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/VariableDeclarationTransformer.spec.ts similarity index 64% rename from test/functional-tests/node-transformers/obfuscation-transformers/VariableDeclarationTransformer.spec.ts rename to test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/VariableDeclarationTransformer.spec.ts index d4433715..68dd8e19 100644 --- a/test/functional-tests/node-transformers/obfuscation-transformers/VariableDeclarationTransformer.spec.ts +++ b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/VariableDeclarationTransformer.spec.ts @@ -1,20 +1,17 @@ import { assert } from 'chai'; -import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult'; +import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult'; -import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes'; +import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; -import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; +import { readFileAsString } from '../../../../helpers/readFileAsString'; + +import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscator'; describe('VariableDeclarationTransformer', () => { - it('should obfuscate `variableDeclaration` node', () => { + it('should transform `variableDeclaration` node', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - ` - function foo () { - var test = 'abc'; - console.log(test); - } - `, + readFileAsString(__dirname + '/fixtures/simple-declaration.js'), { ...NO_CUSTOM_NODES_PRESET } @@ -24,15 +21,9 @@ describe('VariableDeclarationTransformer', () => { assert.match(obfuscationResult.getObfuscatedCode(), /console\['\\x6c\\x6f\\x67'\]\(_0x([a-z0-9]){4,6}\);/); }); - it('should not obfuscate `variableDeclaration` node if parent block scope node is `Program` node', () => { + it('should not transform `variableDeclaration` node if parent block scope node is `Program` node', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - ` - if (true) { - var test = 10; - } - - console.log(test); - `, + readFileAsString(__dirname + '/fixtures/parent-block-scope-is-program-node.js'), { ...NO_CUSTOM_NODES_PRESET } @@ -42,17 +33,9 @@ describe('VariableDeclarationTransformer', () => { assert.match(obfuscationResult.getObfuscatedCode(), /console\['\\x6c\\x6f\\x67'\]\(test\);/); }); - it('should obfuscate variable call (`identifier` node) outside of block scope of node in which this variable was declared with `var` kind', () => { + it('should transform variable call (`identifier` node) outside of block scope of node in which this variable was declared with `var` kind', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - ` - (function () { - if (true) { - var test = 10; - } - - console.log(test); - })(); - `, + readFileAsString(__dirname + '/fixtures/var-kind.js'), { ...NO_CUSTOM_NODES_PRESET } @@ -61,17 +44,9 @@ describe('VariableDeclarationTransformer', () => { assert.match(obfuscationResult.getObfuscatedCode(), /console\['\\x6c\\x6f\\x67'\]\(_0x([a-z0-9]){4,6}\);/); }); - it('should not obfuscate variable call (`identifier` node) outside of block scope of node in which this variable was declared with `let` kind', () => { + it('should not transform variable call (`identifier` node) outside of block scope of node in which this variable was declared with `let` kind', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - ` - (function () { - if (true) { - let test = 10; - } - - console.log(test); - })(); - `, + readFileAsString(__dirname + '/fixtures/let-kind.js'), { ...NO_CUSTOM_NODES_PRESET } @@ -85,31 +60,18 @@ describe('VariableDeclarationTransformer', () => { beforeEach(() => { obfuscationResult = JavaScriptObfuscator.obfuscate( - ` - function foo () { - function bar () { - console.log(abc.item); - } - - console.log(abc); - - var abc = {}; - - abc.item = 15; - bar(); - } - `, + readFileAsString(__dirname + '/fixtures/variable-call-before-variable-declaration-1.js'), { ...NO_CUSTOM_NODES_PRESET } ); }); - it('should obfuscate variable call (`identifier` node) before variable declaration if this call is inside function body', () => { + it('should transform variable call (`identifier` node) before variable declaration if this call is inside function body', () => { assert.match(obfuscationResult.getObfuscatedCode(), /console\['\\x6c\\x6f\\x67'\]\(_0x([a-z0-9]){4,6}\['\\x69\\x74\\x65\\x6d'\]\);/); }); - it('should not obfuscate variable call (`identifier` node) before variable declaration', () => { + it('should not transform variable call (`identifier` node) before variable declaration', () => { assert.match(obfuscationResult.getObfuscatedCode(), /console\['\\x6c\\x6f\\x67'\]\(_0x([a-z0-9]){4,6}\);/); }); }); @@ -124,27 +86,14 @@ describe('VariableDeclarationTransformer', () => { beforeEach(() => { obfuscationResult = JavaScriptObfuscator.obfuscate( - ` - (function () { - function foo (t, e) { - return function () { - function baz (t) { - console.log(t); - } - - return {t: t}; - var t; - }(); - } - })(); - `, + readFileAsString(__dirname + '/fixtures/variable-call-before-variable-declaration-2.js'), { ...NO_CUSTOM_NODES_PRESET } ); }); - it('should correct obfuscate variables inside function body', () => { + it('should correct transform variables inside function body', () => { const obfuscatedCode: string = obfuscationResult.getObfuscatedCode(); const functionParamIdentifierMatch: RegExpMatchArray|null = obfuscatedCode .match(/function *_0x[a-z0-9]{4,6} *\((_0x[a-z0-9]{4,6})\,(_0x[a-z0-9]{4,6})\) *\{/); @@ -177,17 +126,7 @@ describe('VariableDeclarationTransformer', () => { describe('wrong replacement', () => { it('shouldn\'t replace property node identifier', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - ` - function foo () { - var test = 'abc'; - - var object = { - test: 'cde' - }; - - console.log(test); - } - `, + readFileAsString(__dirname + '/fixtures/property-identifier.js'), { ...NO_CUSTOM_NODES_PRESET } @@ -198,18 +137,7 @@ describe('VariableDeclarationTransformer', () => { it('shouldn\'t replace computed member expression identifier', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - ` - function foo () { - var test = 'abc'; - - var object = { - 'test': 'cde' - }; - - console.log(test); - console.log(object.test); - } - `, + readFileAsString(__dirname + '/fixtures/member-expression-identifier.js'), { ...NO_CUSTOM_NODES_PRESET } diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/let-kind.js b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/let-kind.js new file mode 100644 index 00000000..51f38ac7 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/let-kind.js @@ -0,0 +1,7 @@ +(function () { + if (true) { + let test = 10; + } + + console.log(test); +})(); \ No newline at end of file diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/member-expression-identifier.js b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/member-expression-identifier.js new file mode 100644 index 00000000..32f24a38 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/member-expression-identifier.js @@ -0,0 +1,10 @@ +function foo () { + var test = 'abc'; + + var object = { + 'test': 'cde' + }; + + console.log(test); + console.log(object.test); +} \ No newline at end of file diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/parent-block-scope-is-program-node.js b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/parent-block-scope-is-program-node.js new file mode 100644 index 00000000..c1157389 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/parent-block-scope-is-program-node.js @@ -0,0 +1,5 @@ +if (true) { + var test = 10; +} + +console.log(test); diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/property-identifier.js b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/property-identifier.js new file mode 100644 index 00000000..b2298696 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/property-identifier.js @@ -0,0 +1,9 @@ +function foo () { + var test = 'abc'; + + var object = { + test: 'cde' + }; + + console.log(test); +} \ No newline at end of file diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/simple-declaration.js b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/simple-declaration.js new file mode 100644 index 00000000..5a15e220 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/simple-declaration.js @@ -0,0 +1,4 @@ +function foo () { + var test = 'abc'; + console.log(test); +} diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/var-kind.js b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/var-kind.js new file mode 100644 index 00000000..d7f370aa --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/var-kind.js @@ -0,0 +1,7 @@ +(function () { + if (true) { + var test = 10; + } + + console.log(test); +})(); \ No newline at end of file diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/variable-call-before-variable-declaration-1.js b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/variable-call-before-variable-declaration-1.js new file mode 100644 index 00000000..4ece3323 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/variable-call-before-variable-declaration-1.js @@ -0,0 +1,12 @@ +function foo () { + function bar () { + console.log(abc.item); + } + + console.log(abc); + + var abc = {}; + + abc.item = 15; + bar(); +} \ No newline at end of file diff --git a/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/variable-call-before-variable-declaration-2.js b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/variable-call-before-variable-declaration-2.js new file mode 100644 index 00000000..898581e3 --- /dev/null +++ b/test/functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/fixtures/variable-call-before-variable-declaration-2.js @@ -0,0 +1,12 @@ +(function () { + function foo (t, e) { + return function () { + function baz (t) { + console.log(t); + } + + return {t: t}; + var t; + }(); + } +})(); \ No newline at end of file diff --git a/test/functional-tests/stack-trace-analyzer/StackTraceAnalyzer.spec.ts b/test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/StackTraceAnalyzer.spec.ts similarity index 89% rename from test/functional-tests/stack-trace-analyzer/StackTraceAnalyzer.spec.ts rename to test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/StackTraceAnalyzer.spec.ts index 2a1c6e11..e6341608 100644 --- a/test/functional-tests/stack-trace-analyzer/StackTraceAnalyzer.spec.ts +++ b/test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/StackTraceAnalyzer.spec.ts @@ -1,22 +1,22 @@ -import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers'; +import { ServiceIdentifiers } from '../../../../src/container/ServiceIdentifiers'; import * as estraverse from 'estraverse'; import * as ESTree from 'estree'; import { assert } from 'chai'; -import { TNodeWithBlockStatement } from '../../../src/types/node/TNodeWithBlockStatement'; +import { TNodeWithBlockStatement } from '../../../../src/types/node/TNodeWithBlockStatement'; -import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade'; -import { IStackTraceAnalyzer } from '../../../src/interfaces/stack-trace-analyzer/IStackTraceAnalyzer'; -import { IStackTraceData } from '../../../src/interfaces/stack-trace-analyzer/IStackTraceData'; +import { IInversifyContainerFacade } from '../../../../src/interfaces/container/IInversifyContainerFacade'; +import { IStackTraceAnalyzer } from '../../../../src/interfaces/stack-trace-analyzer/IStackTraceAnalyzer'; +import { IStackTraceData } from '../../../../src/interfaces/stack-trace-analyzer/IStackTraceData'; -import { readFileAsString } from '../../helpers/readFileAsString'; +import { readFileAsString } from '../../../helpers/readFileAsString'; -import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade'; -import { Node } from '../../../src/node/Node'; -import { Nodes } from '../../../src/node/Nodes'; -import { NodeUtils } from '../../../src/node/NodeUtils'; +import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade'; +import { Node } from '../../../../src/node/Node'; +import { Nodes } from '../../../../src/node/Nodes'; +import { NodeUtils } from '../../../../src/node/NodeUtils'; /** * @param astTree @@ -159,7 +159,7 @@ describe('StackTraceAnalyzer', () => { it('should returns correct IStackTraceData - variant #1: basic-1', () => { astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/stack-trace-analyzer/basic-1.js') + readFileAsString(__dirname + '/fixtures/basic-1.js') ) ); @@ -206,7 +206,7 @@ describe('StackTraceAnalyzer', () => { it('should returns correct IStackTraceData - variant #2: basic-2', () => { astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/stack-trace-analyzer/basic-2.js') + readFileAsString(__dirname + '/fixtures/basic-2.js') ) ); @@ -242,7 +242,7 @@ describe('StackTraceAnalyzer', () => { it('should returns correct IStackTraceData - variant #3: deep conditions nesting', () => { astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/stack-trace-analyzer/deep-conditions-nesting.js') + readFileAsString(__dirname + '/fixtures/deep-conditions-nesting.js') ) ); @@ -278,7 +278,7 @@ describe('StackTraceAnalyzer', () => { it('should returns correct IStackTraceData - variant #4: call before declaration', () => { astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/stack-trace-analyzer/call-before-declaration.js') + readFileAsString(__dirname + '/fixtures/call-before-declaration.js') ) ); @@ -298,7 +298,7 @@ describe('StackTraceAnalyzer', () => { it('should returns correct IStackTraceData - variant #5: call expression of object member #1', () => { astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/stack-trace-analyzer/call-expression-of-object-member-1.js') + readFileAsString(__dirname + '/fixtures/call-expression-of-object-member-1.js') ) ); @@ -354,7 +354,7 @@ describe('StackTraceAnalyzer', () => { it('should returns correct IStackTraceData - variant #5: call expression of object member #2', () => { astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/stack-trace-analyzer/call-expression-of-object-member-2.js') + readFileAsString(__dirname + '/fixtures/call-expression-of-object-member-2.js') ) ); @@ -379,7 +379,7 @@ describe('StackTraceAnalyzer', () => { it('should returns correct IStackTraceData - variant #6: no call expressions', () => { astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/stack-trace-analyzer/no-call-expressions.js') + readFileAsString(__dirname + '/fixtures/no-call-expressions.js') ) ); @@ -393,7 +393,7 @@ describe('StackTraceAnalyzer', () => { it('should returns correct IStackTraceData - variant #7: only call expression', () => { astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/stack-trace-analyzer/only-call-expression.js') + readFileAsString(__dirname + '/fixtures/only-call-expression.js') ) ); @@ -407,7 +407,7 @@ describe('StackTraceAnalyzer', () => { it('should returns correct IStackTraceData - variant #8: self-invoking functions', () => { astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/stack-trace-analyzer/self-invoking-functions.js') + readFileAsString(__dirname + '/fixtures/self-invoking-functions.js') ) ); @@ -439,7 +439,7 @@ describe('StackTraceAnalyzer', () => { it('should returns correct IStackTraceData - variant #9: no recursion', () => { astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/stack-trace-analyzer/no-recursion.js') + readFileAsString(__dirname + '/fixtures/no-recursion.js') ) ); diff --git a/test/fixtures/stack-trace-analyzer/basic-1.js b/test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/basic-1.js similarity index 100% rename from test/fixtures/stack-trace-analyzer/basic-1.js rename to test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/basic-1.js diff --git a/test/fixtures/stack-trace-analyzer/basic-2.js b/test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/basic-2.js similarity index 100% rename from test/fixtures/stack-trace-analyzer/basic-2.js rename to test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/basic-2.js diff --git a/test/fixtures/stack-trace-analyzer/call-before-declaration.js b/test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/call-before-declaration.js similarity index 100% rename from test/fixtures/stack-trace-analyzer/call-before-declaration.js rename to test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/call-before-declaration.js diff --git a/test/fixtures/stack-trace-analyzer/call-expression-of-object-member-1.js b/test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/call-expression-of-object-member-1.js similarity index 100% rename from test/fixtures/stack-trace-analyzer/call-expression-of-object-member-1.js rename to test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/call-expression-of-object-member-1.js diff --git a/test/fixtures/stack-trace-analyzer/call-expression-of-object-member-2.js b/test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/call-expression-of-object-member-2.js similarity index 100% rename from test/fixtures/stack-trace-analyzer/call-expression-of-object-member-2.js rename to test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/call-expression-of-object-member-2.js diff --git a/test/fixtures/stack-trace-analyzer/deep-conditions-nesting.js b/test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/deep-conditions-nesting.js similarity index 100% rename from test/fixtures/stack-trace-analyzer/deep-conditions-nesting.js rename to test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/deep-conditions-nesting.js diff --git a/test/fixtures/stack-trace-analyzer/no-call-expressions.js b/test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/no-call-expressions.js similarity index 100% rename from test/fixtures/stack-trace-analyzer/no-call-expressions.js rename to test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/no-call-expressions.js diff --git a/test/fixtures/stack-trace-analyzer/no-recursion.js b/test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/no-recursion.js similarity index 100% rename from test/fixtures/stack-trace-analyzer/no-recursion.js rename to test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/no-recursion.js diff --git a/test/fixtures/stack-trace-analyzer/only-call-expression.js b/test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/only-call-expression.js similarity index 100% rename from test/fixtures/stack-trace-analyzer/only-call-expression.js rename to test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/only-call-expression.js diff --git a/test/fixtures/stack-trace-analyzer/self-invoking-functions.js b/test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/self-invoking-functions.js similarity index 100% rename from test/fixtures/stack-trace-analyzer/self-invoking-functions.js rename to test/functional-tests/stack-trace-analyzer/stack-trace-analyzer/fixtures/self-invoking-functions.js diff --git a/test/index.spec.ts b/test/index.spec.ts index 1e62b9bf..d857a69f 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -7,44 +7,45 @@ BabelPolyfill.append(); /** * Unit tests */ -import './unit-tests/ObfuscationResult.spec'; -import './unit-tests/options/OptionsNormalizer.spec'; -import './unit-tests/SourceMapCorrector.spec'; -import './unit-tests/cli/CLIUtils.spec'; -import './unit-tests/decorators/Initializable.spec'; -import './unit-tests/node/NodeAppender.spec'; -import './unit-tests/node/NodeUtils.spec'; -import './unit-tests/stack-trace-analyzer/StackTraceAnalyzer.spec'; -import './unit-tests/utils/CryptUtils.spec'; -import './unit-tests/utils/RandomGeneratorUtils.spec'; -import './unit-tests/utils/Utils.spec'; +import './unit-tests/cli/cli-utils/CLIUtils.spec'; +import './unit-tests/decorators/initializable/Initializable.spec'; +import './unit-tests/node/node-appender/NodeAppender.spec'; +import './unit-tests/node/node-utils/NodeUtils.spec'; +import './unit-tests/obfuscation-result/ObfuscationResult.spec'; +import './unit-tests/options/options-normalizer/OptionsNormalizer.spec'; +import './unit-tests/source-map-corrector/SourceMapCorrector.spec'; +import './unit-tests/stack-trace-analyzer/stack-trace-analyzer/StackTraceAnalyzer.spec'; +import './unit-tests/utils/crypt-utils/CryptUtils.spec'; +import './unit-tests/utils/random-generator-utils/RandomGeneratorUtils.spec'; +import './unit-tests/utils/utils/Utils.spec'; /** * Functional tests */ -import './functional-tests/JavaScriptObfuscator.spec'; -import './functional-tests/JavaScriptObfuscatorCLI.spec'; -import './functional-tests/JavaScriptObfuscatorInternal.spec'; +import './functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec'; +import './functional-tests/javascript-obfuscator-cli/JavaScriptObfuscatorCLI.spec'; +import './functional-tests/javascript-obfuscator-internal/JavaScriptObfuscatorInternal.spec'; import './functional-tests/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.spec'; import './functional-tests/custom-nodes/domain-lock-nodes/DomainLockNode.spec'; import './functional-tests/custom-nodes/string-array-nodes/StringArrayCallsWrapper.spec'; import './functional-tests/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.spec'; import './functional-tests/custom-nodes/string-array-nodes/StringArrayNode.spec'; -import './functional-tests/node-transformers/control-flow-transformers/BlockStatementControlFlowTransformer.spec'; -import './functional-tests/node-transformers/control-flow-transformers/FunctionControlFlowTransformer.spec'; -import './functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.spec'; -import './functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/CallExpressionControlFlowReplacer.spec'; -import './functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/LogicalExpressionControlFlowReplacer.spec'; -import './functional-tests/node-transformers/obfuscation-transformers/CatchClauseTransformer.spec'; -import './functional-tests/node-transformers/obfuscation-transformers/FunctionDeclarationTransformer.spec'; -import './functional-tests/node-transformers/obfuscation-transformers/FunctionTransformer.spec'; -import './functional-tests/node-transformers/obfuscation-transformers/LabeledStatementTransformer.spec'; -import './functional-tests/node-transformers/obfuscation-transformers/LiteralTransformer.spec'; -import './functional-tests/node-transformers/obfuscation-transformers/MemberExpressionTransformer.spec'; -import './functional-tests/node-transformers/obfuscation-transformers/MethodDefinitionTransformer.spec'; -import './functional-tests/node-transformers/obfuscation-transformers/ObjectExpressionTransformer.spec'; -import './functional-tests/node-transformers/obfuscation-transformers/VariableDeclarationTransformer.spec'; -import './functional-tests/stack-trace-analyzer/StackTraceAnalyzer.spec'; +import './functional-tests/node-transformers/control-flow-transformers/block-statement-control-flow-transformer/BlockStatementControlFlowTransformer.spec'; +import './functional-tests/node-transformers/control-flow-transformers/function-control-flow-transformer/FunctionControlFlowTransformer.spec'; +import './functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/binary-expression-control-flow-replacer/BinaryExpressionControlFlowReplacer.spec'; +import './functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/call-expression-control-flow-replacer/CallExpressionControlFlowReplacer.spec'; +import './functional-tests/node-transformers/control-flow-transformers/control-flow-replacers/logical-expression-control-flow-replacer/LogicalExpressionControlFlowReplacer.spec'; +import './functional-tests/node-transformers/obfuscation-transformers/catch-clause-transformer/CatchClauseTransformer.spec'; +import './functional-tests/node-transformers/obfuscation-transformers/function-declaration-transformer/FunctionDeclarationTransformer.spec'; +import './functional-tests/node-transformers/obfuscation-transformers/function-transformer/FunctionTransformer.spec'; +import './functional-tests/node-transformers/obfuscation-transformers/labeled-statement-transformer/LabeledStatementTransformer.spec'; +import './functional-tests/node-transformers/obfuscation-transformers/literal-transformer/LiteralTransformer.spec'; +import './functional-tests/node-transformers/obfuscation-transformers/member-expression-transformer/MemberExpressionTransformer.spec'; +import './functional-tests/node-transformers/obfuscation-transformers/method-definition-transformer/MethodDefinitionTransformer.spec'; +import './functional-tests/node-transformers/obfuscation-transformers/object-expression-transformer/ObjectExpressionTransformer.spec'; +import './functional-tests/node-transformers/obfuscation-transformers/template-literal-transformer/TemplateLiteralTransformer.spec'; +import './functional-tests/node-transformers/obfuscation-transformers/variable-declaration-transformer/VariableDeclarationTransformer.spec'; +import './functional-tests/stack-trace-analyzer/stack-trace-analyzer/StackTraceAnalyzer.spec'; import './functional-tests/templates/custom-nodes/domain-lock-nodes/DomainLockNodeTemplate.spec'; import './functional-tests/templates/custom-nodes/string-array-nodes/StringArrayCallsWrapperNodeTemplate.spec'; diff --git a/test/runtime-tests/JavaScriptObfuscatorRuntime.spec.ts b/test/runtime-tests/JavaScriptObfuscatorRuntime.spec.ts index 5f97283d..5f7d7db4 100644 --- a/test/runtime-tests/JavaScriptObfuscatorRuntime.spec.ts +++ b/test/runtime-tests/JavaScriptObfuscatorRuntime.spec.ts @@ -1,14 +1,14 @@ import { assert } from 'chai'; -import { readFileAsString } from '../helpers/readFileAsString'; - import { IObfuscationResult } from '../../src/interfaces/IObfuscationResult'; +import { readFileAsString } from '../helpers/readFileAsString'; + import { JavaScriptObfuscator } from '../../src/JavaScriptObfuscator'; describe('JavaScriptObfuscator runtime eval', () => { it('should obfuscate code without any runtime errors after obfuscation: variant #1 sha256', () => { - const code: string = readFileAsString('./test/fixtures/runtime/sha256.js'); + const code: string = readFileAsString(__dirname + '/fixtures/sha256.js'); const obfuscationResult1: IObfuscationResult = JavaScriptObfuscator.obfuscate( code, diff --git a/test/fixtures/runtime/sha256.js b/test/runtime-tests/fixtures/sha256.js similarity index 100% rename from test/fixtures/runtime/sha256.js rename to test/runtime-tests/fixtures/sha256.js diff --git a/test/unit-tests/cli/CLIUtils.spec.ts b/test/unit-tests/cli/cli-utils/CLIUtils.spec.ts similarity index 98% rename from test/unit-tests/cli/CLIUtils.spec.ts rename to test/unit-tests/cli/cli-utils/CLIUtils.spec.ts index dfcbad7f..d8a40a0a 100644 --- a/test/unit-tests/cli/CLIUtils.spec.ts +++ b/test/unit-tests/cli/cli-utils/CLIUtils.spec.ts @@ -3,7 +3,7 @@ import * as mkdirp from 'mkdirp'; import { assert } from 'chai'; -import { CLIUtils } from '../../../src/cli/CLIUtils'; +import { CLIUtils } from '../../../../src/cli/CLIUtils'; describe('CLIUtils', () => { const fileContent: string = 'test', diff --git a/test/unit-tests/decorators/Initializable.spec.ts b/test/unit-tests/decorators/initializable/Initializable.spec.ts similarity index 94% rename from test/unit-tests/decorators/Initializable.spec.ts rename to test/unit-tests/decorators/initializable/Initializable.spec.ts index 6da0f46d..7f3a8c43 100644 --- a/test/unit-tests/decorators/Initializable.spec.ts +++ b/test/unit-tests/decorators/initializable/Initializable.spec.ts @@ -1,7 +1,7 @@ import { assert } from 'chai'; -import { initializable } from '../../../src/decorators/Initializable'; -import { IInitializable } from '../../../src/interfaces/IInitializable'; +import { initializable } from '../../../../src/decorators/Initializable'; +import { IInitializable } from '../../../../src/interfaces/IInitializable'; describe('@initializable', () => { describe('initializable (initializeMethodKey: string): any', () => { diff --git a/test/unit-tests/node/NodeAppender.spec.ts b/test/unit-tests/node/node-appender/NodeAppender.spec.ts similarity index 70% rename from test/unit-tests/node/NodeAppender.spec.ts rename to test/unit-tests/node/node-appender/NodeAppender.spec.ts index 5f2946e3..817fe87b 100644 --- a/test/unit-tests/node/NodeAppender.spec.ts +++ b/test/unit-tests/node/node-appender/NodeAppender.spec.ts @@ -1,21 +1,21 @@ -import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers'; +import { ServiceIdentifiers } from '../../../../src/container/ServiceIdentifiers'; import * as ESTree from 'estree'; import { assert } from 'chai'; -import { TStatement } from '../../../src/types/node/TStatement'; +import { TStatement } from '../../../../src/types/node/TStatement'; -import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade'; -import { IStackTraceAnalyzer } from '../../../src/interfaces/stack-trace-analyzer/IStackTraceAnalyzer'; -import { IStackTraceData } from '../../../src/interfaces/stack-trace-analyzer/IStackTraceData'; +import { IInversifyContainerFacade } from '../../../../src/interfaces/container/IInversifyContainerFacade'; +import { IStackTraceAnalyzer } from '../../../../src/interfaces/stack-trace-analyzer/IStackTraceAnalyzer'; +import { IStackTraceData } from '../../../../src/interfaces/stack-trace-analyzer/IStackTraceData'; -import { readFileAsString } from '../../helpers/readFileAsString'; +import { readFileAsString } from '../../../helpers/readFileAsString'; -import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade'; -import { NodeAppender } from '../../../src/node/NodeAppender'; -import { Nodes } from '../../../src/node/Nodes'; -import { NodeUtils } from '../../../src/node/NodeUtils'; +import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade'; +import { NodeAppender } from '../../../../src/node/NodeAppender'; +import { Nodes } from '../../../../src/node/Nodes'; +import { NodeUtils } from '../../../../src/node/NodeUtils'; describe('NodeAppender', () => { describe('appendNode (blockScopeNode: TNodeWithBlockStatement[], nodeBodyStatements: TStatement[]): void', () => { @@ -24,19 +24,19 @@ describe('NodeAppender', () => { node: TStatement[]; beforeEach(() => { - node = NodeUtils.convertCodeToStructure(` - var test = 1; - `); + node = NodeUtils.convertCodeToStructure( + readFileAsString(__dirname + '/fixtures/simple-input.js') + ); astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/node-appender/append-node.js') + readFileAsString(__dirname + '/fixtures/append-node.js') ) ); expectedAstTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/node-appender/append-node-expected.js') + readFileAsString(__dirname + '/fixtures/append-node-expected.js') ) ); @@ -62,21 +62,21 @@ describe('NodeAppender', () => { stackTraceData: IStackTraceData[]; beforeEach(() => { - node = NodeUtils.convertCodeToStructure(` - var test = 1; - `); + node = NodeUtils.convertCodeToStructure( + readFileAsString(__dirname + '/fixtures/simple-input.js') + ); }); it('should append node into first and deepest function call in calls trace - variant #1', () => { astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-1.js') + readFileAsString(__dirname + '/fixtures/append-node-to-optimal-block-scope/variant-1.js') ) ); expectedAstTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-1-expected.js') + readFileAsString(__dirname + '/fixtures/append-node-to-optimal-block-scope/variant-1-expected.js') ) ); @@ -89,13 +89,13 @@ describe('NodeAppender', () => { it('should append node into first and deepest function call in calls trace - variant #2', () => { astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-2.js') + readFileAsString(__dirname + '/fixtures/append-node-to-optimal-block-scope/variant-2.js') ) ); expectedAstTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-2-expected.js') + readFileAsString(__dirname + '/fixtures/append-node-to-optimal-block-scope/variant-2-expected.js') ) ); @@ -111,7 +111,7 @@ describe('NodeAppender', () => { beforeEach(() => { astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index.js') + readFileAsString(__dirname + '/fixtures/append-node-to-optimal-block-scope/by-index.js') ) ); @@ -120,7 +120,7 @@ describe('NodeAppender', () => { it('should append node into deepest function call by specified index in calls trace - variant #1', () => { expectedAstTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-1-expected.js') + readFileAsString(__dirname + '/fixtures/append-node-to-optimal-block-scope/by-index-variant-1-expected.js') ) ); @@ -134,7 +134,7 @@ describe('NodeAppender', () => { it('should append node into deepest function call by specified index in calls trace - variant #2', () => { expectedAstTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-2-expected.js') + readFileAsString(__dirname + '/fixtures/append-node-to-optimal-block-scope/by-index-variant-2-expected.js') ) ); @@ -148,12 +148,12 @@ describe('NodeAppender', () => { it('should append node into deepest function call by specified index in calls trace - variant #3', () => { astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-3.js') + readFileAsString(__dirname + '/fixtures/append-node-to-optimal-block-scope/by-index-variant-3.js') ) ); expectedAstTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-3-expected.js') + readFileAsString(__dirname + '/fixtures/append-node-to-optimal-block-scope/by-index-variant-3-expected.js') ) ); @@ -189,19 +189,19 @@ describe('NodeAppender', () => { node: TStatement[]; beforeEach(() => { - node = NodeUtils.convertCodeToStructure(` - var test = 1; - `); + node = NodeUtils.convertCodeToStructure( + readFileAsString(__dirname + '/fixtures/simple-input.js') + ); astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/node-appender/insert-node-at-index.js') + readFileAsString(__dirname + '/fixtures/insert-node-at-index.js') ) ); expectedAstTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/node-appender/insert-node-at-index-expected.js') + readFileAsString(__dirname + '/fixtures/insert-node-at-index-expected.js') ) ); @@ -222,19 +222,19 @@ describe('NodeAppender', () => { node: TStatement[]; beforeEach(() => { - node = NodeUtils.convertCodeToStructure(` - var test = 1; - `); + node = NodeUtils.convertCodeToStructure( + readFileAsString(__dirname + '/fixtures/simple-input.js') + ); astTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/node-appender/prepend-node.js') + readFileAsString(__dirname + '/fixtures/prepend-node.js') ) ); expectedAstTree = Nodes.getProgramNode( NodeUtils.convertCodeToStructure( - readFileAsString('./test/fixtures/node-appender/prepend-node-expected.js') + readFileAsString(__dirname + '/fixtures/prepend-node-expected.js') ) ); diff --git a/test/fixtures/node-appender/append-node-expected.js b/test/unit-tests/node/node-appender/fixtures/append-node-expected.js similarity index 100% rename from test/fixtures/node-appender/append-node-expected.js rename to test/unit-tests/node/node-appender/fixtures/append-node-expected.js diff --git a/test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-1-expected.js b/test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/by-index-variant-1-expected.js similarity index 100% rename from test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-1-expected.js rename to test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/by-index-variant-1-expected.js diff --git a/test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-2-expected.js b/test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/by-index-variant-2-expected.js similarity index 100% rename from test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-2-expected.js rename to test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/by-index-variant-2-expected.js diff --git a/test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-3-expected.js b/test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/by-index-variant-3-expected.js similarity index 100% rename from test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-3-expected.js rename to test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/by-index-variant-3-expected.js diff --git a/test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-3.js b/test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/by-index-variant-3.js similarity index 100% rename from test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-3.js rename to test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/by-index-variant-3.js diff --git a/test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index.js b/test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/by-index.js similarity index 100% rename from test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index.js rename to test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/by-index.js diff --git a/test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-1-expected.js b/test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/variant-1-expected.js similarity index 100% rename from test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-1-expected.js rename to test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/variant-1-expected.js diff --git a/test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-1.js b/test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/variant-1.js similarity index 100% rename from test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-1.js rename to test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/variant-1.js diff --git a/test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-2-expected.js b/test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/variant-2-expected.js similarity index 100% rename from test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-2-expected.js rename to test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/variant-2-expected.js diff --git a/test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-2.js b/test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/variant-2.js similarity index 100% rename from test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-2.js rename to test/unit-tests/node/node-appender/fixtures/append-node-to-optimal-block-scope/variant-2.js diff --git a/test/fixtures/node-appender/append-node.js b/test/unit-tests/node/node-appender/fixtures/append-node.js similarity index 100% rename from test/fixtures/node-appender/append-node.js rename to test/unit-tests/node/node-appender/fixtures/append-node.js diff --git a/test/fixtures/node-appender/insert-node-at-index-expected.js b/test/unit-tests/node/node-appender/fixtures/insert-node-at-index-expected.js similarity index 100% rename from test/fixtures/node-appender/insert-node-at-index-expected.js rename to test/unit-tests/node/node-appender/fixtures/insert-node-at-index-expected.js diff --git a/test/fixtures/node-appender/insert-node-at-index.js b/test/unit-tests/node/node-appender/fixtures/insert-node-at-index.js similarity index 100% rename from test/fixtures/node-appender/insert-node-at-index.js rename to test/unit-tests/node/node-appender/fixtures/insert-node-at-index.js diff --git a/test/fixtures/node-appender/prepend-node-expected.js b/test/unit-tests/node/node-appender/fixtures/prepend-node-expected.js similarity index 100% rename from test/fixtures/node-appender/prepend-node-expected.js rename to test/unit-tests/node/node-appender/fixtures/prepend-node-expected.js diff --git a/test/fixtures/node-appender/prepend-node.js b/test/unit-tests/node/node-appender/fixtures/prepend-node.js similarity index 100% rename from test/fixtures/node-appender/prepend-node.js rename to test/unit-tests/node/node-appender/fixtures/prepend-node.js diff --git a/test/unit-tests/node/node-appender/fixtures/simple-input.js b/test/unit-tests/node/node-appender/fixtures/simple-input.js new file mode 100644 index 00000000..f99241b0 --- /dev/null +++ b/test/unit-tests/node/node-appender/fixtures/simple-input.js @@ -0,0 +1 @@ +var test = 1; \ No newline at end of file diff --git a/test/unit-tests/node/NodeUtils.spec.ts b/test/unit-tests/node/node-utils/NodeUtils.spec.ts similarity index 99% rename from test/unit-tests/node/NodeUtils.spec.ts rename to test/unit-tests/node/node-utils/NodeUtils.spec.ts index 5cad7a5c..e30b26a4 100644 --- a/test/unit-tests/node/NodeUtils.spec.ts +++ b/test/unit-tests/node/node-utils/NodeUtils.spec.ts @@ -2,8 +2,8 @@ import * as ESTree from 'estree'; import { assert } from 'chai'; -import { Nodes } from '../../../src/node/Nodes'; -import { NodeUtils } from '../../../src/node/NodeUtils'; +import { Nodes } from '../../../../src/node/Nodes'; +import { NodeUtils } from '../../../../src/node/NodeUtils'; describe('NodeUtils', () => { describe('addXVerbatimPropertyToLiterals (node: ESTree.Node): void', () => { diff --git a/test/unit-tests/ObfuscationResult.spec.ts b/test/unit-tests/obfuscation-result/ObfuscationResult.spec.ts similarity index 81% rename from test/unit-tests/ObfuscationResult.spec.ts rename to test/unit-tests/obfuscation-result/ObfuscationResult.spec.ts index 68c7f280..2e5f08f5 100644 --- a/test/unit-tests/ObfuscationResult.spec.ts +++ b/test/unit-tests/obfuscation-result/ObfuscationResult.spec.ts @@ -1,8 +1,8 @@ import { assert } from 'chai'; -import { IObfuscationResult } from '../../src/interfaces/IObfuscationResult'; +import { IObfuscationResult } from '../../../src/interfaces/IObfuscationResult'; -import { ObfuscationResult } from '../../src/ObfuscationResult'; +import { ObfuscationResult } from '../../../src/ObfuscationResult'; describe('ObfuscationResult', () => { describe('constructor (obfuscatedCode: string, sourceMap: string)', () => { diff --git a/test/unit-tests/options/OptionsNormalizer.spec.ts b/test/unit-tests/options/options-normalizer/OptionsNormalizer.spec.ts similarity index 93% rename from test/unit-tests/options/OptionsNormalizer.spec.ts rename to test/unit-tests/options/options-normalizer/OptionsNormalizer.spec.ts index 42db235f..d1605db4 100644 --- a/test/unit-tests/options/OptionsNormalizer.spec.ts +++ b/test/unit-tests/options/options-normalizer/OptionsNormalizer.spec.ts @@ -1,13 +1,13 @@ import { assert } from 'chai'; -import { TInputOptions } from '../../../src/types/options/TInputOptions'; +import { TInputOptions } from '../../../../src/types/options/TInputOptions'; -import { IOptions } from '../../../src/interfaces/options/IOptions'; +import { IOptions } from '../../../../src/interfaces/options/IOptions'; -import { DEFAULT_PRESET } from '../../../src/options/presets/Default'; +import { DEFAULT_PRESET } from '../../../../src/options/presets/Default'; -import { Options } from '../../../src/options/Options'; -import { OptionsNormalizer } from '../../../src/options/OptionsNormalizer'; +import { Options } from '../../../../src/options/Options'; +import { OptionsNormalizer } from '../../../../src/options/OptionsNormalizer'; /** * @param optionsPreset diff --git a/test/unit-tests/SourceMapCorrector.spec.ts b/test/unit-tests/source-map-corrector/SourceMapCorrector.spec.ts similarity index 84% rename from test/unit-tests/SourceMapCorrector.spec.ts rename to test/unit-tests/source-map-corrector/SourceMapCorrector.spec.ts index 5ea7caa1..1a90c402 100644 --- a/test/unit-tests/SourceMapCorrector.spec.ts +++ b/test/unit-tests/source-map-corrector/SourceMapCorrector.spec.ts @@ -1,16 +1,16 @@ -import { ServiceIdentifiers } from '../../src/container/ServiceIdentifiers'; +import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers'; import { assert } from 'chai'; -import { TSourceMapMode } from '../../src/types/TSourceMapMode'; +import { TSourceMapMode } from '../../../src/types/TSourceMapMode'; -import { IInversifyContainerFacade } from '../../src/interfaces/container/IInversifyContainerFacade'; -import { IObfuscationResult } from '../../src/interfaces/IObfuscationResult'; -import { ISourceMapCorrector } from '../../src/interfaces/ISourceMapCorrector'; +import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade'; +import { IObfuscationResult } from '../../../src/interfaces/IObfuscationResult'; +import { ISourceMapCorrector } from '../../../src/interfaces/ISourceMapCorrector'; -import { SourceMapMode } from '../../src/enums/SourceMapMode'; +import { SourceMapMode } from '../../../src/enums/SourceMapMode'; -import { InversifyContainerFacade } from '../../src/container/InversifyContainerFacade'; +import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade'; /** * @param obfuscatedCode diff --git a/test/unit-tests/stack-trace-analyzer/StackTraceAnalyzer.spec.ts b/test/unit-tests/stack-trace-analyzer/stack-trace-analyzer/StackTraceAnalyzer.spec.ts similarity index 89% rename from test/unit-tests/stack-trace-analyzer/StackTraceAnalyzer.spec.ts rename to test/unit-tests/stack-trace-analyzer/stack-trace-analyzer/StackTraceAnalyzer.spec.ts index 9ec19373..30a48144 100644 --- a/test/unit-tests/stack-trace-analyzer/StackTraceAnalyzer.spec.ts +++ b/test/unit-tests/stack-trace-analyzer/stack-trace-analyzer/StackTraceAnalyzer.spec.ts @@ -1,6 +1,6 @@ import { assert } from 'chai'; -import { StackTraceAnalyzer } from '../../../src/stack-trace-analyzer/StackTraceAnalyzer'; +import { StackTraceAnalyzer } from '../../../../src/stack-trace-analyzer/StackTraceAnalyzer'; describe('StackTraceAnalyzer', () => { describe('getLimitIndex (blockScopeBodyLength: number): number', () => { diff --git a/test/unit-tests/utils/CryptUtils.spec.ts b/test/unit-tests/utils/crypt-utils/CryptUtils.spec.ts similarity index 95% rename from test/unit-tests/utils/CryptUtils.spec.ts rename to test/unit-tests/utils/crypt-utils/CryptUtils.spec.ts index 6621ecae..4532cca4 100644 --- a/test/unit-tests/utils/CryptUtils.spec.ts +++ b/test/unit-tests/utils/crypt-utils/CryptUtils.spec.ts @@ -1,6 +1,6 @@ import { assert } from 'chai'; -import { CryptUtils } from '../../../src/utils/CryptUtils'; +import { CryptUtils } from '../../../../src/utils/CryptUtils'; describe('CryptUtils', () => { describe('btoa (string: string): string', () => { diff --git a/test/unit-tests/utils/RandomGeneratorUtils.spec.ts b/test/unit-tests/utils/random-generator-utils/RandomGeneratorUtils.spec.ts similarity index 84% rename from test/unit-tests/utils/RandomGeneratorUtils.spec.ts rename to test/unit-tests/utils/random-generator-utils/RandomGeneratorUtils.spec.ts index 319ff86a..33eb882a 100644 --- a/test/unit-tests/utils/RandomGeneratorUtils.spec.ts +++ b/test/unit-tests/utils/random-generator-utils/RandomGeneratorUtils.spec.ts @@ -1,6 +1,6 @@ import { assert } from 'chai'; -import { RandomGeneratorUtils } from '../../../src/utils/RandomGeneratorUtils'; +import { RandomGeneratorUtils } from '../../../../src/utils/RandomGeneratorUtils'; describe('RandomGeneratorUtils', () => { describe('getRandomVariableName (length: number = 6): string', () => { diff --git a/test/unit-tests/utils/Utils.spec.ts b/test/unit-tests/utils/utils/Utils.spec.ts similarity index 97% rename from test/unit-tests/utils/Utils.spec.ts rename to test/unit-tests/utils/utils/Utils.spec.ts index 990fe83f..1a0aa8d6 100644 --- a/test/unit-tests/utils/Utils.spec.ts +++ b/test/unit-tests/utils/utils/Utils.spec.ts @@ -1,8 +1,8 @@ import { assert } from 'chai'; -import { Utils } from '../../../src/utils/Utils'; +import { Utils } from '../../../../src/utils/Utils'; -import { JSFuck } from '../../../src/enums/JSFuck'; +import { JSFuck } from '../../../../src/enums/JSFuck'; describe('Utils', () => { describe('arrayRotate (array: T[], times: number): T[]', () => {