From ffa7e4f3de7f9677c36fab618895530539e96b2e Mon Sep 17 00:00:00 2001 From: Thiago Delgado Pinto Date: Sat, 16 Jun 2018 11:10:48 -0300 Subject: [PATCH] Fixes #20 --- dist/modules/app/TCGenController.js | 2 +- dist/modules/testscenario/TSGen.js | 18 +++++++++++++----- dist/modules/testscenario/TestScenario.js | 10 ++++++++++ modules/app/TCGenController.ts | 2 +- modules/testscenario/TSGen.ts | 21 ++++++++++++++++----- modules/testscenario/TestScenario.ts | 10 ++++++++++ 6 files changed, 51 insertions(+), 12 deletions(-) diff --git a/dist/modules/app/TCGenController.js b/dist/modules/app/TCGenController.js index babc9ace..a6c52ab5 100644 --- a/dist/modules/app/TCGenController.js +++ b/dist/modules/app/TCGenController.js @@ -53,7 +53,7 @@ class TCGenController { let newTestCaseDocuments = []; for (let [key, value] of vertices) { let doc = value; - if (!doc.feature || !doc.feature.scenarios) { + if (!doc || !doc.feature || !doc.feature.scenarios) { continue; } // console.log( 'doc is', doc.fileInfo.path); diff --git a/dist/modules/testscenario/TSGen.js b/dist/modules/testscenario/TSGen.js index d66af16b..e92d36ef 100644 --- a/dist/modules/testscenario/TSGen.js +++ b/dist/modules/testscenario/TSGen.js @@ -65,6 +65,7 @@ class TSGen { // console.log( 'States to replace', allStatesToReplace.map( s=> s.name ) ); if (allStatesToReplace.length > 0) { // Preconditions + State Calls for (let state of allStatesToReplace) { + // Already mapped? if (TypeChecking_1.isDefined(pairMap[state.name])) { continue; } @@ -114,6 +115,7 @@ class TSGen { for (let obj of testScenariosToCombineByState) { let ts = baseScenario.clone(); // console.log( "\nTS is\n", ts.steps.map( s => s.content ) ); + let stepsAdded = 0; for (let stateName in obj) { const pair = obj[stateName]; let [state, tsToReplaceStep] = pair.toArray(); @@ -128,14 +130,16 @@ class TSGen { // console.log( "\nPreTestCase\n", preTestCase.steps.map( s => s.content ) ); // Replace TestScenario steps with the new ones tsToUse.steps = preTestCase.steps; - tsToUse.stepAfterPreconditions = null; // Adjust the stepAfterPreconditions + tsToUse.stepAfterPreconditions = null; let oldIndex = tsToReplaceStep.steps.indexOf(tsToReplaceStep.stepAfterPreconditions); if (oldIndex >= 0) { tsToUse.stepAfterPreconditions = tsToUse.steps[oldIndex]; } // --- - this.replaceStepWithTestScenario(ts, state.stepIndex, tsToUse, isPrecondition); + // console.log( 'state to replace: ', ( state as State ).name ); + state.stepIndex += stepsAdded > 0 ? stepsAdded - 1 : 0; + stepsAdded += this.replaceStepWithTestScenario(ts, state, tsToUse, isPrecondition); } // console.log( "\nTS modified is\n", ts.steps.map( s => s.content ) ); testScenarios.push(ts); @@ -309,16 +313,20 @@ class TSGen { containsIgnoreTag(tags, ignoreKeywords) { return Tag_1.tagsWithAnyOfTheNames(tags, ignoreKeywords).length > 0; } - replaceStepWithTestScenario(ts, stepIndex, tsToReplaceStep, isPrecondition) { + replaceStepWithTestScenario(ts, state, tsToReplaceStep, isPrecondition) { let stepsToReplace = deepcopy(isPrecondition ? tsToReplaceStep.steps : tsToReplaceStep.stepsWithoutPreconditions()); // Set the flag "external" for (let step of stepsToReplace) { step.external = true; } // console.log( "\nBEFORE\n\n", ts.steps.map( s => s.content ).join( "\n" ) ); - // console.log( "\nSTEPS to replace index", stepIndex, "\n\n", stepsToReplace.map( s => s.content ).join( "\n" ) ); - ts.steps.splice(stepIndex, 1, ...stepsToReplace); + // console.log( "\nSTATE INDEX", state.stepIndex, "\n\nWILL REPLACE WITH\n\n", stepsToReplace.map( s => s.content ).join( "\n" ) ); + ts.steps.splice(state.stepIndex, 1, ...stepsToReplace); + const stepsAdded = stepsToReplace.length; + state.stepIndex += stepsAdded; + // console.log( "\nSTATE INDEX after", state.stepIndex ); // console.log( "\nAFTER\n\n", ts.steps.map( s => s.content ).join( "\n" ) ); + return stepsAdded; } } exports.TSGen = TSGen; diff --git a/dist/modules/testscenario/TestScenario.js b/dist/modules/testscenario/TestScenario.js index 4075a270..76cb0d62 100644 --- a/dist/modules/testscenario/TestScenario.js +++ b/dist/modules/testscenario/TestScenario.js @@ -1,5 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +// import * as deepcopy from 'deepcopy'; /** * Test Scenario * @@ -29,6 +30,15 @@ class TestScenario { ts.ignoreForTestCaseGeneration = this.ignoreForTestCaseGeneration; ts.stepAfterPreconditions = this.stepAfterPreconditions; return ts; + // let ts = new TestScenario(); + // ts.steps = []; + // for ( let step of this.steps ) { + // ts.steps.push( deepcopy( step ) as Step ); + // } + // ts.ignoreForTestCaseGeneration = this.ignoreForTestCaseGeneration; + // const stepIndex = this.steps.indexOf( this.stepAfterPreconditions ); + // ts.stepAfterPreconditions = stepIndex < 0 ? null : ts.steps[ stepIndex ]; + // return ts; } stepsWithoutPreconditions() { if (null === this.stepAfterPreconditions) { diff --git a/modules/app/TCGenController.ts b/modules/app/TCGenController.ts index b9f03d7f..66bf52e5 100644 --- a/modules/app/TCGenController.ts +++ b/modules/app/TCGenController.ts @@ -100,7 +100,7 @@ export class TCGenController { for ( let [ key, value ] of vertices ) { let doc: Document = value; - if ( ! doc.feature || ! doc.feature.scenarios ) { + if ( ! doc || ! doc.feature || ! doc.feature.scenarios ) { continue; } // console.log( 'doc is', doc.fileInfo.path); diff --git a/modules/testscenario/TSGen.ts b/modules/testscenario/TSGen.ts index ea982dda..eac68cdc 100644 --- a/modules/testscenario/TSGen.ts +++ b/modules/testscenario/TSGen.ts @@ -94,6 +94,7 @@ export class TSGen { for ( let state of allStatesToReplace ) { + // Already mapped? if ( isDefined( pairMap[ state.name ] ) ) { continue; } @@ -151,6 +152,7 @@ export class TSGen { let ts = baseScenario.clone(); // console.log( "\nTS is\n", ts.steps.map( s => s.content ) ); + let stepsAdded = 0; for ( let stateName in obj ) { const pair = obj[ stateName ]; let [ state, tsToReplaceStep ] = pair.toArray(); @@ -175,16 +177,18 @@ export class TSGen { // Replace TestScenario steps with the new ones tsToUse.steps = preTestCase.steps; - tsToUse.stepAfterPreconditions = null; // Adjust the stepAfterPreconditions + tsToUse.stepAfterPreconditions = null; let oldIndex = tsToReplaceStep.steps.indexOf( tsToReplaceStep.stepAfterPreconditions ); if ( oldIndex >= 0 ) { tsToUse.stepAfterPreconditions = tsToUse.steps[ oldIndex ]; } // --- - this.replaceStepWithTestScenario( ts, state.stepIndex, tsToUse, isPrecondition ); + // console.log( 'state to replace: ', ( state as State ).name ); + state.stepIndex += stepsAdded > 0 ? stepsAdded - 1 : 0; + stepsAdded += this.replaceStepWithTestScenario( ts, state, tsToUse, isPrecondition ); } // console.log( "\nTS modified is\n", ts.steps.map( s => s.content ) ); testScenarios.push( ts ); @@ -417,7 +421,7 @@ export class TSGen { replaceStepWithTestScenario( ts: TestScenario, - stepIndex: number, + state: State, tsToReplaceStep: TestScenario, isPrecondition: boolean ) { @@ -431,9 +435,16 @@ export class TSGen { } // console.log( "\nBEFORE\n\n", ts.steps.map( s => s.content ).join( "\n" ) ); - // console.log( "\nSTEPS to replace index", stepIndex, "\n\n", stepsToReplace.map( s => s.content ).join( "\n" ) ); - ts.steps.splice( stepIndex, 1, ... stepsToReplace ); + // console.log( "\nSTATE INDEX", state.stepIndex, "\n\nWILL REPLACE WITH\n\n", stepsToReplace.map( s => s.content ).join( "\n" ) ); + + ts.steps.splice( state.stepIndex, 1, ... stepsToReplace ); + const stepsAdded = stepsToReplace.length; + state.stepIndex += stepsAdded; + + // console.log( "\nSTATE INDEX after", state.stepIndex ); // console.log( "\nAFTER\n\n", ts.steps.map( s => s.content ).join( "\n" ) ); + + return stepsAdded; } } \ No newline at end of file diff --git a/modules/testscenario/TestScenario.ts b/modules/testscenario/TestScenario.ts index 2ffd5d87..7c9fc872 100644 --- a/modules/testscenario/TestScenario.ts +++ b/modules/testscenario/TestScenario.ts @@ -1,4 +1,5 @@ import { Step } from "../ast/Step"; +// import * as deepcopy from 'deepcopy'; /** * Test Scenario @@ -33,6 +34,15 @@ export class TestScenario { ts.ignoreForTestCaseGeneration = this.ignoreForTestCaseGeneration; ts.stepAfterPreconditions = this.stepAfterPreconditions; return ts; + // let ts = new TestScenario(); + // ts.steps = []; + // for ( let step of this.steps ) { + // ts.steps.push( deepcopy( step ) as Step ); + // } + // ts.ignoreForTestCaseGeneration = this.ignoreForTestCaseGeneration; + // const stepIndex = this.steps.indexOf( this.stepAfterPreconditions ); + // ts.stepAfterPreconditions = stepIndex < 0 ? null : ts.steps[ stepIndex ]; + // return ts; } stepsWithoutPreconditions(): Step[] {