Explorar o código

custom nodes update and NodeAppender tests code moved to fixtures

sanex3339 %!s(int64=8) %!d(string=hai) anos
pai
achega
9b6d49e111
Modificáronse 30 ficheiros con 624 adicións e 578 borrados
  1. 28 9
      dist/index.js
  2. 7 0
      src/custom-nodes/AbstractCustomNode.ts
  3. 2 1
      src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts
  4. 11 0
      src/custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode.ts
  5. 2 1
      src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts
  6. 5 0
      src/interfaces/custom-nodes/ICustomNode.d.ts
  7. 1 1
      src/node-groups/ConsoleOutputNodesGroup.ts
  8. 21 13
      src/node-groups/SelfDefendingNodesGroup.ts
  9. 8 7
      src/node-groups/UnicodeArrayNodesGroup.ts
  10. 2 14
      src/templates/custom-nodes/console-output-nodes/console-output-disable-expression-node/ConsoleOutputDisableExpressionTemplate.ts
  11. 2 20
      src/templates/custom-nodes/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate.ts
  12. 2 1
      test/dev/dev.ts
  13. 4 0
      test/fixtures/node-appender/append-node-expected.js
  14. 28 0
      test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-1-expected.js
  15. 28 0
      test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-2-expected.js
  16. 27 0
      test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-3-expected.js
  17. 27 0
      test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-3.js
  18. 28 0
      test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index.js
  19. 27 0
      test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-1-expected.js
  20. 28 0
      test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-1.js
  21. 28 0
      test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-2-expected.js
  22. 28 0
      test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-2.js
  23. 3 0
      test/fixtures/node-appender/append-node.js
  24. 13 0
      test/fixtures/node-appender/insert-node-at-index-expected.js
  25. 11 0
      test/fixtures/node-appender/insert-node-at-index.js
  26. 5 0
      test/fixtures/node-appender/prepend-node-expected.js
  27. 3 0
      test/fixtures/node-appender/prepend-node.js
  28. 1 1
      test/index.spec.ts
  29. 244 0
      test/unit-tests/NodeAppender.spec.ts
  30. 0 510
      test/unit-tests/custom-nodes/NodeAppender.spec.ts

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 28 - 9
dist/index.js


+ 7 - 0
src/custom-nodes/AbstractCustomNode.ts

@@ -43,6 +43,13 @@ export abstract class AbstractCustomNode implements ICustomNode {
         return this.getNodeStructure();
     }
 
+    /**
+     * @param appendState
+     */
+    public setAppendState (appendState: AppendState): void {
+        this.appendState = appendState;
+    }
+
     /**
      * @returns {TStatement[]}
      */

+ 2 - 1
src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts

@@ -86,7 +86,8 @@ export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode {
     protected getNodeStructure (): TStatement[] {
         return NodeUtils.convertCodeToStructure(
             ConsoleOutputDisableExpressionTemplate().formatUnicorn({
-                consoleLogDisableFunctionName: Utils.getRandomVariableName()
+                consoleLogDisableFunctionName: Utils.getRandomVariableName(),
+                singleNodeCallControllerFunctionName: this.callsControllerFunctionName
             })
         );
     }

+ 11 - 0
src/custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode.ts

@@ -10,7 +10,10 @@ import { AppendState } from '../../enums/AppendState';
 
 import { SingleNodeCallControllerTemplate } from '../../templates/custom-nodes/SingleNodeCallControllerTemplate';
 
+import { NO_CUSTOM_NODES_PRESET } from '../../preset-options/NoCustomNodesPreset';
+
 import { AbstractCustomNode } from '../AbstractCustomNode';
+import { JavaScriptObfuscator } from '../../JavaScriptObfuscator';
 import { NodeAppender } from '../../NodeAppender';
 import { NodeUtils } from '../../NodeUtils';
 
@@ -74,6 +77,14 @@ export class NodeCallsControllerFunctionNode extends AbstractCustomNode {
      * @returns {TStatement[]}
      */
     protected getNodeStructure (): TStatement[] {
+        if (this.appendState === AppendState.AfterObfuscation) {
+            return NodeUtils.convertCodeToStructure(
+                JavaScriptObfuscator.obfuscate(SingleNodeCallControllerTemplate().formatUnicorn({
+                    singleNodeCallControllerFunctionName: this.callsControllerFunctionName
+                }), NO_CUSTOM_NODES_PRESET).getObfuscatedCode()
+            );
+        }
+
         return NodeUtils.convertCodeToStructure(
             SingleNodeCallControllerTemplate().formatUnicorn({
                 singleNodeCallControllerFunctionName: this.callsControllerFunctionName

+ 2 - 1
src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts

@@ -75,7 +75,8 @@ export class SelfDefendingUnicodeNode extends AbstractCustomNode {
         return NodeUtils.convertCodeToStructure(
             JavaScriptObfuscator.obfuscate(
                 SelfDefendingTemplate().formatUnicorn({
-                    selfDefendingFunctionName: Utils.getRandomVariableName()
+                    selfDefendingFunctionName: Utils.getRandomVariableName(),
+                    singleNodeCallControllerFunctionName: this.callsControllerFunctionName
                 }),
                 NO_CUSTOM_NODES_PRESET
             ).getObfuscatedCode()

+ 5 - 0
src/interfaces/custom-nodes/ICustomNode.d.ts

@@ -19,4 +19,9 @@ export interface ICustomNode {
      * @returns ESTree.Node[]
      */
     getNode (): TStatement[];
+
+    /**
+     * @param appendState
+     */
+    setAppendState (appendState: AppendState): void;
 }

+ 1 - 1
src/node-groups/ConsoleOutputNodesGroup.ts

@@ -18,7 +18,7 @@ export class ConsoleOutputNodesGroup extends AbstractNodesGroup {
             return;
         }
 
-        const callsControllerFunctionName: string = 'domainLockCallsControllerFunction';
+        const callsControllerFunctionName: string = 'consoleOutputNodeCallsControllerFunction';
         const randomStackTraceIndex: number = NodeAppender.getRandomStackTraceIndex(this.stackTraceData.length);
 
         this.nodes.set(

+ 21 - 13
src/node-groups/SelfDefendingNodesGroup.ts

@@ -1,6 +1,9 @@
+import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode';
 import { IOptions } from '../interfaces/IOptions';
 import { IStackTraceData } from '../interfaces/stack-trace-analyzer/IStackTraceData';
 
+import { AppendState } from '../enums/AppendState';
+
 import { AbstractNodesGroup } from './AbstractNodesGroup';
 import { NodeAppender } from '../NodeAppender';
 import { NodeCallsControllerFunctionNode } from '../custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode';
@@ -18,26 +21,31 @@ export class SelfDefendingNodesGroup extends AbstractNodesGroup {
             return;
         }
 
-        const callsControllerFunctionName: string = 'domainLockCallsControllerFunction';
+        const callsControllerFunctionName: string = 'selfDefendingNodeCallsControllerFunction';
         const randomStackTraceIndex: number = NodeAppender.getRandomStackTraceIndex(this.stackTraceData.length);
+        const selfDefendingUnicodeNode: ICustomNode = new SelfDefendingUnicodeNode(
+            this.stackTraceData,
+            callsControllerFunctionName,
+            randomStackTraceIndex,
+            this.options
+        );
+        const nodeCallsControllerFunctionNode: ICustomNode = new NodeCallsControllerFunctionNode(
+            this.stackTraceData,
+            callsControllerFunctionName,
+            randomStackTraceIndex,
+            this.options
+        );
+
+        selfDefendingUnicodeNode.setAppendState(AppendState.AfterObfuscation);
+        nodeCallsControllerFunctionNode.setAppendState(AppendState.AfterObfuscation);
 
         this.nodes.set(
             'selfDefendingUnicodeNode',
-            new SelfDefendingUnicodeNode(
-                this.stackTraceData,
-                callsControllerFunctionName,
-                randomStackTraceIndex,
-                this.options
-            )
+            selfDefendingUnicodeNode
         );
         this.nodes.set(
             'SelfDefendingNodeCallsControllerFunctionNode',
-            new NodeCallsControllerFunctionNode(
-                this.stackTraceData,
-                callsControllerFunctionName,
-                randomStackTraceIndex,
-                this.options
-            )
+            nodeCallsControllerFunctionNode
         );
     }
 }

+ 8 - 7
src/node-groups/UnicodeArrayNodesGroup.ts

@@ -1,3 +1,4 @@
+import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode';
 import { IOptions } from '../interfaces/IOptions';
 import { IStackTraceData } from '../interfaces/stack-trace-analyzer/IStackTraceData';
 
@@ -44,13 +45,13 @@ export class UnicodeArrayNodesGroup extends AbstractNodesGroup {
             this.unicodeArrayRotateValue = 0;
         }
 
-        let unicodeArray: UnicodeArray = new UnicodeArray(),
-            unicodeArrayNode: UnicodeArrayNode = new UnicodeArrayNode(
-                unicodeArray,
-                this.unicodeArrayName,
-                this.unicodeArrayRotateValue,
-                this.options
-            );
+        const unicodeArray: UnicodeArray = new UnicodeArray();
+        const unicodeArrayNode: ICustomNode = new UnicodeArrayNode(
+            unicodeArray,
+            this.unicodeArrayName,
+            this.unicodeArrayRotateValue,
+            this.options
+        );
 
         this.nodes.set('unicodeArrayNode', unicodeArrayNode);
         this.nodes.set(

+ 2 - 14
src/templates/custom-nodes/console-output-nodes/console-output-disable-expression-node/ConsoleOutputDisableExpressionTemplate.ts

@@ -3,19 +3,7 @@
  */
 export function ConsoleOutputDisableExpressionTemplate (): string {
     return `
-        var {consoleLogDisableFunctionName} = function () {
-            var getGlobal = function () {
-                if (typeof self !== 'undefined') { return self; }
-                if (typeof window !== 'undefined') { return window; }
-                if (typeof global !== 'undefined') { return global; }
-            };
-            
-            if (getGlobal().fetchPolyfillDisabledFlag) {
-                return;
-            }
-                                                          
-            getGlobal().fetchPolyfillDisabledFlag = true;
-            
+        var {consoleLogDisableFunctionName} = {singleNodeCallControllerFunctionName}(this, function () { 
             var _ = '(\u0004\u0006\u0003\u0005[]' + '["filter"]["\u0007tructor"]' + '("return this")()' + '.' + '\u0003;\u0006\u0002\u0005\u0004};' + '_\u0003.log\u0001.in' + 'fo\u0001.' + 'war' + 'n\u0001.er' + 'r' + 'or\u0001})();' + '\u0001\u0005_\u0002;' + '_\u0003\u0002function' + '\u0003\u0007ole\u0004\u0002 ()' + '{\u0005 = \u0006var ' + '_\u0007cons', 
                 Y, 
                 $;
@@ -26,7 +14,7 @@ export function ConsoleOutputDisableExpressionTemplate (): string {
             }
             
             []["filter"]["constructor"](_)();
-        };
+        });
         
         {consoleLogDisableFunctionName}();
     `;

+ 2 - 20
src/templates/custom-nodes/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate.ts

@@ -8,25 +8,7 @@ import { Utils } from '../../../../Utils';
  */
 export function SelfDefendingTemplate (): string {
     return `
-        function {selfDefendingFunctionName} () {
-            var getGlobal = function () {
-                if (typeof self !== 'undefined') { return self; }
-                if (typeof window !== 'undefined') { return window; }
-                if (typeof global !== 'undefined') { return global; }
-            };
-        
-            if (
-                getGlobal().argvProcess && 
-                getGlobal().argvProcess.appTimeoutStateCounter++ && 
-                getGlobal().argvProcess.appTimeoutStateCounter !== 50
-            ) {
-                return false;
-            }
-            
-            getGlobal().argvProcess = {
-                appTimeoutStateCounter: 50
-            };
-              
+        var {selfDefendingFunctionName} = {singleNodeCallControllerFunctionName}(this, function () {
             var func1 = function(){return 'dev';},
                 func2 = function () {
                     return 'window';
@@ -69,7 +51,7 @@ export function SelfDefendingTemplate (): string {
             } else {
                 recursiveFunc1('indеxOf');
             }
-        }
+        })
         
         {selfDefendingFunctionName}();
     `;

+ 2 - 1
test/dev/dev.ts

@@ -71,7 +71,8 @@ if (!(<any>global)._babelPolyfill) {
         {
             disableConsoleOutput: false,
             unicodeArrayEncoding: 'rc4',
-            domainLock: ['google.ru']
+            domainLock: ['google.ru'],
+            selfDefending: true
         }
     ).getObfuscatedCode();
 

+ 4 - 0
test/fixtures/node-appender/append-node-expected.js

@@ -0,0 +1,4 @@
+var func = function () {
+    return true;
+};
+var test = 1;

+ 28 - 0
test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-1-expected.js

@@ -0,0 +1,28 @@
+function foo () {
+    var test = 1;
+}
+
+function bar () {
+    function inner1 () {
+
+    }
+
+    function inner2 () {
+        var inner3 = function () {
+
+        };
+
+        inner3();
+    }
+
+    inner2();
+    inner1();
+}
+
+function baz () {
+
+}
+
+bar();
+baz();
+foo();

+ 28 - 0
test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-2-expected.js

@@ -0,0 +1,28 @@
+function foo () {
+
+}
+
+function bar () {
+    function inner1 () {
+
+    }
+
+    function inner2 () {
+        var inner3 = function () {
+
+        };
+
+        inner3();
+    }
+
+    inner2();
+    inner1();
+}
+
+function baz () {
+    var test = 1;
+}
+
+bar();
+baz();
+foo();

+ 27 - 0
test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-3-expected.js

@@ -0,0 +1,27 @@
+var start = new Date();
+var log = console.log;
+
+console.log = function () {};
+
+(function () {
+    function bar () {
+        function inner1 () {
+
+        }
+
+        function inner2 () {
+            var inner3 = function () {
+                var test = 1;
+            }
+
+            inner3();
+        }
+
+        inner2();
+        inner1();
+    }
+
+    bar();
+})();
+console.log = log;
+console.log(new Date() - start);

+ 27 - 0
test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-3.js

@@ -0,0 +1,27 @@
+var start = new Date();
+var log = console.log;
+
+console.log = function () {};
+
+(function () {
+    function bar () {
+        function inner1 () {
+
+        }
+
+        function inner2 () {
+            var inner3 = function () {
+
+            }
+
+            inner3();
+        }
+
+        inner2();
+        inner1();
+    }
+
+    bar();
+})();
+console.log = log;
+console.log(new Date() - start);

+ 28 - 0
test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index.js

@@ -0,0 +1,28 @@
+function foo () {
+
+}
+
+function bar () {
+    function inner1 () {
+
+    }
+
+    function inner2 () {
+        var inner3 = function () {
+
+        };
+
+        inner3();
+    }
+
+    inner2();
+    inner1();
+}
+
+function baz () {
+
+}
+
+bar();
+baz();
+foo();

+ 27 - 0
test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-1-expected.js

@@ -0,0 +1,27 @@
+function foo () {
+
+}
+
+function bar () {
+    function inner1 () {
+
+    }
+
+    function inner2 () {
+        var inner3 = function () {
+        };
+
+        inner3();
+    }
+
+    inner2();
+    inner1();
+}
+
+function baz () {
+    var test = 1;
+}
+
+baz();
+foo();
+bar();

+ 28 - 0
test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-1.js

@@ -0,0 +1,28 @@
+function foo () {
+
+}
+
+function bar () {
+    function inner1 () {
+
+    }
+
+    function inner2 () {
+        var inner3 = function () {
+
+        };
+
+        inner3();
+    }
+
+    inner2();
+    inner1();
+}
+
+function baz () {
+
+}
+
+baz();
+foo();
+bar();

+ 28 - 0
test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-2-expected.js

@@ -0,0 +1,28 @@
+function foo () {
+
+}
+
+function bar () {
+    function inner1 () {
+
+    }
+
+    function inner2 () {
+        var inner3 = function () {
+            var test = 1;
+        };
+
+        inner3();
+    }
+
+    inner2();
+    inner1();
+}
+
+function baz () {
+
+}
+
+bar();
+baz();
+foo();

+ 28 - 0
test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-2.js

@@ -0,0 +1,28 @@
+function foo () {
+
+}
+
+function bar () {
+    function inner1 () {
+
+    }
+
+    function inner2 () {
+        var inner3 = function () {
+
+        };
+
+        inner3();
+    }
+
+    inner2();
+    inner1();
+}
+
+function baz () {
+
+}
+
+bar();
+baz();
+foo();

+ 3 - 0
test/fixtures/node-appender/append-node.js

@@ -0,0 +1,3 @@
+var func = function () {
+    return true;
+};

+ 13 - 0
test/fixtures/node-appender/insert-node-at-index-expected.js

@@ -0,0 +1,13 @@
+var func1 = function () {
+    return true;
+};
+
+var func2 = function () {
+    return false;
+};
+
+var test = 1;
+
+var func3 = function () {
+    return 'string';
+};

+ 11 - 0
test/fixtures/node-appender/insert-node-at-index.js

@@ -0,0 +1,11 @@
+var func1 = function () {
+    return true;
+};
+
+var func2 = function () {
+    return false;
+};
+
+var func3 = function () {
+    return 'string';
+};

+ 5 - 0
test/fixtures/node-appender/prepend-node-expected.js

@@ -0,0 +1,5 @@
+var test = 1;
+
+var func = function () {
+    return true;
+};

+ 3 - 0
test/fixtures/node-appender/prepend-node.js

@@ -0,0 +1,3 @@
+var func = function () {
+    return true;
+};

+ 1 - 1
test/index.spec.ts

@@ -7,13 +7,13 @@ BabelPolyfill.append();
 /**
  * Unit tests
  */
+import './unit-tests/NodeAppender.spec';
 import './unit-tests/NodeUtils.spec';
 import './unit-tests/ObfuscationResult.spec';
 import './unit-tests/OptionsNormalizer.spec';
 import './unit-tests/SourceMapCorrector.spec';
 import './unit-tests/Utils.spec';
 import './unit-tests/cli/CLIUtils.spec';
-import './unit-tests/custom-nodes/NodeAppender.spec';
 import './unit-tests/node-obfuscators/CatchClauseObfuscator.spec';
 import './unit-tests/node-obfuscators/FunctionDeclarationObfuscator.spec';
 import './unit-tests/node-obfuscators/FunctionObfuscator.spec';

+ 244 - 0
test/unit-tests/NodeAppender.spec.ts

@@ -0,0 +1,244 @@
+import * as chai from 'chai';
+import * as ESTree from 'estree';
+
+import { TStatement } from '../../src/types/TStatement';
+
+import { IStackTraceData } from '../../src/interfaces/stack-trace-analyzer/IStackTraceData';
+
+import { readFileAsString } from '../helpers/readFileAsString';
+
+import { NodeAppender } from '../../src/NodeAppender';
+import { NodeMocks } from '../mocks/NodeMocks';
+import { NodeUtils } from '../../src/NodeUtils';
+import { StackTraceAnalyzer } from '../../src/stack-trace-analyzer/StackTraceAnalyzer';
+
+const assert: any = chai.assert;
+
+describe('NodeAppender', () => {
+    describe('appendNode (blockScopeNode: TNodeWithBlockStatement[], nodeBodyStatements: TStatement[]): void', () => {
+        let astTree: ESTree.Program,
+            expectedAstTree: ESTree.Program,
+            node: TStatement[];
+
+        beforeEach(() => {
+            node = NodeUtils.convertCodeToStructure(`
+                var test = 1;
+            `);
+
+            astTree = NodeMocks.getProgramNode(
+                NodeUtils.convertCodeToStructure(
+                    readFileAsString('./test/fixtures/node-appender/append-node.js')
+                )
+            );
+
+            expectedAstTree = NodeMocks.getProgramNode(
+                NodeUtils.convertCodeToStructure(
+                    readFileAsString('./test/fixtures/node-appender/append-node-expected.js')
+                )
+            );
+
+            NodeUtils.parentize(astTree);
+            NodeUtils.parentize(expectedAstTree);
+
+            NodeAppender.appendNode(astTree, node);
+        });
+
+        it('should append given node to a `BlockStatement` node body', () => {
+            assert.deepEqual(astTree, expectedAstTree);
+        });
+    });
+
+    describe('appendNodeToOptimalBlockScope (blockScopeStackTraceData: IStackTraceData[], blockScopeNode: TNodeWithBlockStatement, nodeBodyStatements: TStatement[], index: number = 0): void', () => {
+        let astTree: ESTree.Program,
+            expectedAstTree: ESTree.Program,
+            node: TStatement[],
+            stackTraceData: IStackTraceData[];
+
+        beforeEach(() => {
+            node = NodeUtils.convertCodeToStructure(`
+                var test = 1;
+            `);
+        });
+
+        it('should append node into first and deepest function call in calls trace - variant #1', () => {
+            astTree = NodeMocks.getProgramNode(
+                NodeUtils.convertCodeToStructure(
+                    readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-1.js')
+                )
+            );
+
+            expectedAstTree = NodeMocks.getProgramNode(
+                NodeUtils.convertCodeToStructure(
+                    readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-1-expected.js')
+                )
+            );
+
+            stackTraceData = new StackTraceAnalyzer(astTree.body).analyze();
+            NodeAppender.appendNodeToOptimalBlockScope(stackTraceData, astTree, node);
+
+            assert.deepEqual(astTree, expectedAstTree);
+        });
+
+        it('should append node into first and deepest function call in calls trace - variant #2', () => {
+            astTree = NodeMocks.getProgramNode(
+                NodeUtils.convertCodeToStructure(
+                    readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-2.js')
+                )
+            );
+
+            expectedAstTree = NodeMocks.getProgramNode(
+                NodeUtils.convertCodeToStructure(
+                    readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/variant-2-expected.js')
+                )
+            );
+
+            stackTraceData = new StackTraceAnalyzer(astTree.body).analyze();
+            NodeAppender.appendNodeToOptimalBlockScope(stackTraceData, astTree, node);
+
+            assert.deepEqual(astTree, expectedAstTree);
+        });
+
+        describe('append by specific index', () => {
+            let astTree: ESTree.Program;
+
+            beforeEach(() => {
+                astTree = NodeMocks.getProgramNode(
+                    NodeUtils.convertCodeToStructure(
+                        readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index.js')
+
+                    )
+                );
+            });
+
+            it('should append node into deepest function call by specified index in calls trace - variant #1', () => {
+                expectedAstTree = NodeMocks.getProgramNode(
+                    NodeUtils.convertCodeToStructure(
+                        readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-1-expected.js')
+
+                    )
+                );
+
+                stackTraceData = new StackTraceAnalyzer(astTree.body).analyze();
+                NodeAppender.appendNodeToOptimalBlockScope(stackTraceData, astTree, node, 2);
+
+                assert.deepEqual(astTree, expectedAstTree);
+            });
+
+            it('should append node into deepest function call by specified index in calls trace - variant #2', () => {
+                expectedAstTree = NodeMocks.getProgramNode(
+                    NodeUtils.convertCodeToStructure(
+                        readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-2-expected.js')
+
+                    )
+                );
+
+                stackTraceData = new StackTraceAnalyzer(astTree.body).analyze();
+                NodeAppender.appendNodeToOptimalBlockScope(stackTraceData, astTree, node, 1);
+
+                assert.deepEqual(astTree, expectedAstTree);
+            });
+
+            it('should append node into deepest function call by specified index in calls trace - variant #3', () => {
+                astTree = NodeMocks.getProgramNode(
+                    NodeUtils.convertCodeToStructure(
+                        readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-3.js')
+                    )
+                );
+                expectedAstTree = NodeMocks.getProgramNode(
+                    NodeUtils.convertCodeToStructure(
+                        readFileAsString('./test/fixtures/node-appender/append-node-to-optimal-block-scope/by-index-variant-3-expected.js')
+                    )
+                );
+
+                stackTraceData = new StackTraceAnalyzer(astTree.body).analyze();
+                NodeAppender.appendNodeToOptimalBlockScope(
+                    stackTraceData,
+                    astTree,
+                    node,
+                    NodeAppender.getRandomStackTraceIndex(stackTraceData.length)
+                );
+
+                assert.deepEqual(astTree, expectedAstTree);
+            });
+        });
+    });
+
+    describe('getRandomStackTraceIndex (stackTraceRootLength: number): number', () => {
+        it('should returns random index between 0 and stack trace data root length', () => {
+            let index: number;
+
+            for (let i: number = 0; i < 100; i++) {
+                index = NodeAppender.getRandomStackTraceIndex(100);
+
+                assert.isAtLeast(index, 0);
+                assert.isAtMost(index, 100);
+            }
+        });
+    });
+
+    describe('insertNodeAtIndex (blockScopeNode: TNodeWithBlockStatement[], nodeBodyStatements: TStatement[], index: number): void', () => {
+        let astTree: ESTree.Program,
+            expectedAstTree: ESTree.Program,
+            node: TStatement[];
+
+        beforeEach(() => {
+            node = NodeUtils.convertCodeToStructure(`
+                var test = 1;
+            `);
+
+            astTree = NodeMocks.getProgramNode(
+                NodeUtils.convertCodeToStructure(
+                    readFileAsString('./test/fixtures/node-appender/insert-node-at-index.js')
+                )
+            );
+
+            expectedAstTree = NodeMocks.getProgramNode(
+                NodeUtils.convertCodeToStructure(
+                    readFileAsString('./test/fixtures/node-appender/insert-node-at-index-expected.js')
+                )
+            );
+
+            NodeUtils.parentize(astTree);
+            NodeUtils.parentize(expectedAstTree);
+
+            NodeAppender.insertNodeAtIndex(astTree, node, 2);
+        });
+
+        it('should insert given node in `BlockStatement` node body at index', () => {
+            assert.deepEqual(astTree, expectedAstTree);
+        });
+    });
+
+    describe('prependNode (blockScopeNode: TNodeWithBlockStatement[], nodeBodyStatements: TStatement[]): void', () => {
+        let astTree: ESTree.Program,
+            expectedAstTree: ESTree.Program,
+            node: TStatement[];
+
+        beforeEach(() => {
+            node = NodeUtils.convertCodeToStructure(`
+                var test = 1;
+            `);
+
+            astTree = NodeMocks.getProgramNode(
+                NodeUtils.convertCodeToStructure(
+                    readFileAsString('./test/fixtures/node-appender/prepend-node.js')
+                )
+            );
+
+            expectedAstTree = NodeMocks.getProgramNode(
+                NodeUtils.convertCodeToStructure(
+                    readFileAsString('./test/fixtures/node-appender/prepend-node-expected.js')
+                )
+            );
+
+            NodeUtils.parentize(astTree);
+            NodeUtils.parentize(expectedAstTree);
+
+            NodeAppender.prependNode(astTree, node);
+        });
+
+        it('should prepend given node to a `BlockStatement` node body', () => {
+            assert.deepEqual(astTree, expectedAstTree);
+        });
+    });
+});

+ 0 - 510
test/unit-tests/custom-nodes/NodeAppender.spec.ts

@@ -1,510 +0,0 @@
-import * as chai from 'chai';
-import * as ESTree from 'estree';
-
-import { TStatement } from '../../../src/types/TStatement';
-
-import { IStackTraceData } from '../../../src/interfaces/stack-trace-analyzer/IStackTraceData';
-
-import { NodeAppender } from '../../../src/NodeAppender';
-import { NodeMocks } from '../../mocks/NodeMocks';
-import { NodeUtils } from '../../../src/NodeUtils';
-import { StackTraceAnalyzer } from '../../../src/stack-trace-analyzer/StackTraceAnalyzer';
-
-const assert: any = chai.assert;
-
-describe('NodeAppender', () => {
-    describe('appendNode (blockScopeNode: TNodeWithBlockStatement[], nodeBodyStatements: TStatement[]): void', () => {
-        let blockStatementNode: ESTree.BlockStatement,
-            expectedBlockStatementNode: ESTree.BlockStatement,
-            expectedExpressionStatementNode: ESTree.ExpressionStatement,
-            expressionStatementNode: ESTree.ExpressionStatement;
-
-        beforeEach(() => {
-            expressionStatementNode = NodeMocks.getExpressionStatementNode();
-            expectedExpressionStatementNode = NodeMocks.getExpressionStatementNode();
-
-            blockStatementNode = NodeMocks.getBlockStatementNode();
-
-            expectedExpressionStatementNode['parentNode'] = blockStatementNode;
-
-            expectedBlockStatementNode = NodeMocks.getBlockStatementNode([
-                expectedExpressionStatementNode
-            ]);
-
-            NodeAppender.appendNode(
-                blockStatementNode,
-                [expressionStatementNode]
-            );
-            NodeAppender.appendNode(
-                blockStatementNode,
-                <TStatement[]>[{}]
-            );
-        });
-
-        it('should append given node to a `BlockStatement` node body', () => {
-            assert.deepEqual(blockStatementNode, expectedBlockStatementNode);
-        });
-
-        it('should does not change `BlockStatement` node body if given node is not a valid Node', () => {
-            assert.deepEqual(blockStatementNode, expectedBlockStatementNode);
-        });
-    });
-
-    describe('appendNodeToOptimalBlockScope (blockScopeStackTraceData: IStackTraceData[], blockScopeNode: TNodeWithBlockStatement, nodeBodyStatements: TStatement[], index: number = 0): void', () => {
-        let astTree: ESTree.Program,
-            expectedAstTree: ESTree.Program,
-            node: TStatement[],
-            stackTraceData: IStackTraceData[];
-
-        beforeEach(() => {
-            node = NodeUtils.convertCodeToStructure(`
-                var test = 1;
-            `);
-        });
-
-        it('should append node into first and deepest function call in calls trace - variant #1', () => {
-            astTree = NodeMocks.getProgramNode(
-                <ESTree.Statement[]>NodeUtils.convertCodeToStructure(`
-                    function foo () {
-                    
-                    }
-                    
-                    function bar () {
-                        function inner1 () {
-                        
-                        }
-                    
-                        function inner2 () {
-                            var inner3 = function () {
-                                
-                            }
-                            
-                            inner3();
-                        }
-                        
-                        inner2();
-                        inner1();
-                    }
-                    
-                    function baz () {
-                    
-                    }
-                    
-                    baz();
-                    foo();
-                    bar();
-                `)
-            );
-
-            expectedAstTree = NodeMocks.getProgramNode(
-                <ESTree.Statement[]>NodeUtils.convertCodeToStructure(`
-                    function foo () {
-                    
-                    }
-                    
-                    function bar () {
-                        function inner1 () {
-                        
-                        }
-                    
-                        function inner2 () {
-                            var inner3 = function () {
-                            }
-                            
-                            inner3();
-                        }
-                        
-                        inner2();
-                        inner1();
-                    }
-                    
-                    function baz () {
-                        var test = 1;
-                    }
-                    
-                    baz();
-                    foo();
-                    bar();
-                `)
-            );
-
-            stackTraceData = new StackTraceAnalyzer(astTree.body).analyze();
-            NodeAppender.appendNodeToOptimalBlockScope(stackTraceData, astTree, node);
-
-            assert.deepEqual(astTree, expectedAstTree);
-        });
-
-        it('should append node into first and deepest function call in calls trace - variant #2', () => {
-            astTree = NodeMocks.getProgramNode(
-                <ESTree.Statement[]>NodeUtils.convertCodeToStructure(`
-                    function foo () {
-                    
-                    }
-                    
-                    function bar () {
-                        function inner1 () {
-                        
-                        }
-                    
-                        function inner2 () {
-                            var inner3 = function () {
-                                
-                            }
-                            
-                            inner3();
-                        }
-                        
-                        inner2();
-                        inner1();
-                    }
-                    
-                    function baz () {
-                    
-                    }
-                    
-                    bar();
-                    baz();
-                    foo();
-                `)
-            );
-
-            expectedAstTree = NodeMocks.getProgramNode(
-                <ESTree.Statement[]>NodeUtils.convertCodeToStructure(`
-                    function foo () {
-                    
-                    }
-                    
-                    function bar () {
-                        function inner1 () {
-                        
-                        }
-                    
-                        function inner2 () {
-                            var inner3 = function () {
-                                var test = 1;
-                            }
-                            
-                            inner3();
-                        }
-                        
-                        inner2();
-                        inner1();
-                    }
-                    
-                    function baz () {
-                    
-                    }
-                    
-                    bar();
-                    baz();
-                    foo();
-                `)
-            );
-
-            stackTraceData = new StackTraceAnalyzer(astTree.body).analyze();
-            NodeAppender.appendNodeToOptimalBlockScope(stackTraceData, astTree, node);
-
-            assert.deepEqual(astTree, expectedAstTree);
-        });
-
-        describe('append by specific index', () => {
-            let astTree: ESTree.Program;
-
-            beforeEach(() => {
-                astTree = NodeMocks.getProgramNode(
-                    <ESTree.Statement[]>NodeUtils.convertCodeToStructure(`
-                        function foo () {
-                        
-                        }
-                        
-                        function bar () {
-                            function inner1 () {
-                            
-                            }
-                        
-                            function inner2 () {
-                                var inner3 = function () {
-                                   
-                                }
-                                
-                                inner3();
-                            }
-                            
-                            inner2();
-                            inner1();
-                        }
-                        
-                        function baz () {
-                        
-                        }
-                        
-                        bar();
-                        baz();
-                        foo();
-                    `)
-                );
-            });
-
-            it('should append node into deepest function call by specified index in calls trace - variant #1', () => {
-                expectedAstTree = NodeMocks.getProgramNode(
-                    <ESTree.Statement[]>NodeUtils.convertCodeToStructure(`
-                        function foo () {
-                            var test = 1;
-                        }
-                        
-                        function bar () {
-                            function inner1 () {
-                            
-                            }
-                        
-                            function inner2 () {
-                                var inner3 = function () {
-                                    
-                                }
-                                
-                                inner3();
-                            }
-                            
-                            inner2();
-                            inner1();
-                        }
-                        
-                        function baz () {
-                        
-                        }
-                        
-                        bar();
-                        baz();
-                        foo();
-                    `)
-                );
-
-                stackTraceData = new StackTraceAnalyzer(astTree.body).analyze();
-                NodeAppender.appendNodeToOptimalBlockScope(stackTraceData, astTree, node, 2);
-
-                assert.deepEqual(astTree, expectedAstTree);
-            });
-
-            it('should append node into deepest function call by specified index in calls trace - variant #2', () => {
-                expectedAstTree = NodeMocks.getProgramNode(
-                    <ESTree.Statement[]>NodeUtils.convertCodeToStructure(`
-                        function foo () {
-                            
-                        }
-                        
-                        function bar () {
-                            function inner1 () {
-                            
-                            }
-                        
-                            function inner2 () {
-                                var inner3 = function () {
-                                    
-                                }
-                                
-                                inner3();
-                            }
-                            
-                            inner2();
-                            inner1();
-                        }
-                        
-                        function baz () {
-                            var test = 1;
-                        }
-                        
-                        bar();
-                        baz();
-                        foo();
-                    `)
-                );
-
-                stackTraceData = new StackTraceAnalyzer(astTree.body).analyze();
-                NodeAppender.appendNodeToOptimalBlockScope(stackTraceData, astTree, node, 1);
-
-                assert.deepEqual(astTree, expectedAstTree);
-            });
-
-            it('should append node into deepest function call by specified index in calls trace - variant #3', () => {
-                astTree = NodeMocks.getProgramNode(
-                    <ESTree.Statement[]>NodeUtils.convertCodeToStructure(`
-                        var start = new Date();
-                        var log = console.log;
-                        
-                        console.log = function () {};
-                    
-                        (function () {
-                            function bar () {
-                                function inner1 () {
-                                
-                                }
-                            
-                                function inner2 () {
-                                    var inner3 = function () {
-                                    
-                                    }
-                                    
-                                    inner3();
-                                }
-                                
-                                inner2();
-                                inner1();
-                            }
-                            
-                            bar();
-                        })();
-                        console.log = log;
-                        console.log(new Date() - start);
-                    `)
-                );
-                expectedAstTree = NodeMocks.getProgramNode(
-                    <ESTree.Statement[]>NodeUtils.convertCodeToStructure(`
-                        var start = new Date();
-                        var log = console.log;
-                        
-                        console.log = function () {};
-                    
-                        (function () {
-                            function bar () {
-                                function inner1 () {
-                                
-                                }
-                            
-                                function inner2 () {
-                                    var inner3 = function () {
-                                        var test = 1;
-                                    }
-                                    
-                                    inner3();
-                                }
-                                
-                                inner2();
-                                inner1();
-                            }
-                            
-                            bar();
-                        })();
-                        console.log = log;
-                        console.log(new Date() - start);
-                    `)
-                );
-
-                stackTraceData = new StackTraceAnalyzer(astTree.body).analyze();
-                NodeAppender.appendNodeToOptimalBlockScope(
-                    stackTraceData,
-                    astTree,
-                    node,
-                    NodeAppender.getRandomStackTraceIndex(stackTraceData.length)
-                );
-
-                assert.deepEqual(astTree, expectedAstTree);
-            });
-        });
-    });
-
-    describe('getRandomStackTraceIndex (stackTraceRootLength: number): number', () => {
-        it('should returns random index between 0 and stack trace data root length', () => {
-            let index: number;
-
-            for (let i: number = 0; i < 100; i++) {
-                index = NodeAppender.getRandomStackTraceIndex(100);
-
-                assert.isAtLeast(index, 0);
-                assert.isAtMost(index, 100);
-            }
-        });
-    });
-
-    describe('insertNodeAtIndex (blockScopeNode: TNodeWithBlockStatement[], nodeBodyStatements: TStatement[], index: number): void', () => {
-        let blockStatementNode: ESTree.BlockStatement,
-            expectedBlockStatementNode: ESTree.BlockStatement,
-            expressionStatementNode1: ESTree.ExpressionStatement,
-            expressionStatementNode2: ESTree.ExpressionStatement,
-            expressionStatementNode3: ESTree.ExpressionStatement,
-            expressionStatementNode4: ESTree.ExpressionStatement;
-
-        beforeEach(() => {
-            expressionStatementNode1 = NodeMocks.getExpressionStatementNode(NodeMocks.getLiteralNode(1));
-            expressionStatementNode2 = NodeMocks.getExpressionStatementNode(NodeMocks.getLiteralNode(2));
-            expressionStatementNode3 = NodeMocks.getExpressionStatementNode(NodeMocks.getLiteralNode(3));
-            expressionStatementNode4 = NodeMocks.getExpressionStatementNode(NodeMocks.getLiteralNode(2));
-
-            blockStatementNode = NodeMocks.getBlockStatementNode([
-                expressionStatementNode1,
-                expressionStatementNode3
-            ]);
-
-            expressionStatementNode1['parentNode'] = blockStatementNode;
-            expressionStatementNode2['parentNode'] = blockStatementNode;
-            expressionStatementNode3['parentNode'] = blockStatementNode;
-
-            expectedBlockStatementNode = NodeMocks.getBlockStatementNode([
-                expressionStatementNode1,
-                expressionStatementNode2,
-                expressionStatementNode3
-            ]);
-
-            NodeAppender.insertNodeAtIndex(
-                blockStatementNode,
-                [expressionStatementNode4],
-                1
-            );
-            NodeAppender.insertNodeAtIndex(
-                blockStatementNode,
-                <TStatement[]>[{}],
-                1
-            );
-        });
-
-        it('should insert given node in `BlockStatement` node body at index', () => {
-            assert.deepEqual(blockStatementNode, expectedBlockStatementNode);
-        });
-
-        it('should does not change `BlockStatement` node body if given node is not a valid Node', () => {
-            assert.deepEqual(blockStatementNode, expectedBlockStatementNode);
-        });
-    });
-
-    describe('prependNode (blockScopeNode: TNodeWithBlockStatement[], nodeBodyStatements: TStatement[]): void', () => {
-        let blockStatementNode: ESTree.BlockStatement,
-            expectedBlockStatementNode: ESTree.BlockStatement,
-            expressionStatementNode1: ESTree.ExpressionStatement,
-            expressionStatementNode2: ESTree.ExpressionStatement,
-            expressionStatementNode3: ESTree.ExpressionStatement;
-
-        beforeEach(() => {
-            expressionStatementNode1 = NodeMocks.getExpressionStatementNode(NodeMocks.getLiteralNode(1));
-            expressionStatementNode2 = NodeMocks.getExpressionStatementNode(NodeMocks.getLiteralNode(2));
-            expressionStatementNode3 = NodeMocks.getExpressionStatementNode(NodeMocks.getLiteralNode(2));
-
-            blockStatementNode = NodeMocks.getBlockStatementNode([
-                expressionStatementNode1
-            ]);
-
-            expressionStatementNode1['parentNode'] = blockStatementNode;
-            expressionStatementNode2['parentNode'] = blockStatementNode;
-
-            expectedBlockStatementNode = NodeMocks.getBlockStatementNode([
-                expressionStatementNode2,
-                expressionStatementNode1
-            ]);
-
-            NodeAppender.prependNode(
-                blockStatementNode,
-                [Object.assign({}, expressionStatementNode3)]
-            );
-            NodeAppender.prependNode(
-                blockStatementNode,
-                <TStatement[]>[{}]
-            )
-        });
-
-        it('should prepend given node to a `BlockStatement` node body', () => {
-            assert.deepEqual(blockStatementNode, expectedBlockStatementNode);
-        });
-
-        it('should does not change `BlockStatement` node body if given node is not a valid Node', () => {
-            assert.deepEqual(blockStatementNode, expectedBlockStatementNode);
-        });
-    });
-});

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio