Skip to content

Commit

Permalink
Support refactoring of async calls. Refs #14
Browse files Browse the repository at this point in the history
Signed-off-by: Kaustav Das Modak <[email protected]>
  • Loading branch information
Kaustav Das Modak committed Feb 11, 2016
1 parent 25573c1 commit c070f7e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ var processNode = function (node, req) {
node.arguments[0].value = req.newStepValue.parameterizedStepValue;
node.arguments[0].raw = "\"" + req.newStepValue.parameterizedStepValue + "\"";
if (node.arguments[1] && node.arguments[1].type === "FunctionExpression") {
var asyncparams = node.arguments[1].params.slice(req.oldStepValue.parameters.length);
node.arguments[1].params = req.newStepValue.parameters.map(function (param) {
return {
type: "Identifier",
name: param
};
});
node.arguments[1].params = node.arguments[1].params.concat(asyncparams);
}
return node;
};
Expand Down
36 changes: 36 additions & 0 deletions test/refactor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,40 @@ describe( "Refactor", function () {

assert.strictEqual( contentOutput, "gauge('The word <word> has <number> vowels and ends with <end_letter>.', function (word, number, end_letter) {\n});");
});

it( "Should perform refactoring while retaining callbacks for async step implementation calls", function () {
contentInput = "gauge('The word <word> has <number> vowels.', function (word, number, done) {\n});";
request = {
refactorRequest: {
oldStepValue: {
stepValue: "The word {} has {} vowels.",
parameterizedStepValue: "The word <word> has <number> vowels.",
parameters: [ "word", "number" ]
},
newStepValue: {
stepValue: "This English word {} has {} vowels.",
parameterizedStepValue: "This English word <word> has <numbers> vowels.",
parameters: [ "word", "numbers" ]
},
paramPositions: [ {
oldPosition: -1,
newPosition: 1
}, {
oldPosition: 0,
newPosition: 0
} ]
}
};

info = {
fn: function ( word, number, done ) { word = "such"; number = "wow"; done = "phew."; },
stepText: "The word <word> has <number> vowels.",
generalisedText: "The word {} has {} vowels.",
filePath: "test/data/refactor-output.js"
};

response = refactor( request, response );

assert.strictEqual( contentOutput, "gauge('This English word <word> has <numbers> vowels.', function (word, numbers, done) {\n});");
});
});

0 comments on commit c070f7e

Please sign in to comment.