Created
September 4, 2017 22:16
-
-
Save alex-popov-tech/4b9adff61bc5db901ef2cf73d601c19d to your computer and use it in GitHub Desktop.
Idea for nested steps functionality
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StepNode { | |
const stepName; | |
const func; | |
const that; | |
const args; | |
const nestedStepNode; | |
const getTail = function() { | |
tmp = this; | |
while (tmp.nestedStepNode != null) { | |
tmp = tmp.nestedStepNode; | |
} | |
return tmp; | |
} | |
} | |
let step = new StepNode(); | |
Allure.prototype.createStep = function(name, stepFunc, nested) { | |
let tmpStep = new StepNode(); | |
tmpStep.stepname = this._format(name, Array.prototype.slice.call(arguments, 0)), | |
status = 'passed', | |
result; | |
tmpStep.func = stepFunc; | |
tmpStep.that = this; | |
tmpStep.args = arguments; | |
tmpStep.nestedStepNode = null; | |
if (nested) { | |
step.getTail().nestedStepNode = nested; // find last node with nested === null and assign just created to it | |
} else { | |
this.performStepCreation(step); | |
step = tmpStep; | |
} | |
}; | |
Allure.prototype.performStepCreation = function (stepNode) { | |
if (stepNode.nestedStepNode) { | |
performStepCreation(stepNode.nestedStepNode) && performStepCreation(stepNode); | |
} else { | |
var stepName = that._format(name, Array.prototype.slice.call(arguments, 0)), | |
status = 'passed', | |
result; | |
that._allure.startStep(stepName); | |
try { | |
result = stepFunc.apply(this, arguments); | |
} | |
catch(error) { | |
status = 'broken'; | |
throw error; | |
} | |
finally { | |
if(that.isPromise(result)) { | |
result.then(function() { | |
that._allure.endStep('passed'); | |
}, function() { | |
that._allure.endStep('broken'); | |
}); | |
} else { | |
that._allure.endStep(status); | |
} | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment