Skip to content

Commit a82b4ed

Browse files
author
Robert Jackson
committed
Rewrite this.render to await this.render.
1 parent aadfc70 commit a82b4ed

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

__testfixtures__/ember-qunit-codemod/module-for-component.output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module('Integration | Component | FooBar', function(hooks) {
66
setupRenderingTest(hooks);
77

88
test('it happens', async function() {
9-
this.render(hbs`derp`);
9+
await this.render(hbs`derp`);
1010
});
1111
});
1212

ember-qunit-codemod.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,34 @@ function updateModuleForToNestedModule(j, root) {
153153
return [moduleInvocation, callback.body.body, setupType];
154154
}
155155

156+
function processRenderingTest(expression) {
157+
let isTest = j.match(expression, { expression: { callee: { name: 'test' } } });
158+
if (!isTest) {
159+
return;
160+
}
161+
162+
// mark the test function as an async function
163+
expression.expression.arguments[1].async = true;
164+
165+
let renderUsage = j(expression).find(j.ExpressionStatement, {
166+
expression: {
167+
callee: {
168+
object: {
169+
type: 'ThisExpression',
170+
},
171+
property: {
172+
name: 'render',
173+
},
174+
},
175+
},
176+
});
177+
178+
renderUsage.forEach(p => {
179+
let expression = p.get('expression');
180+
expression.replace(j.awaitExpression(expression.node));
181+
});
182+
}
183+
156184
let programPath = root.get('program');
157185
let bodyPath = programPath.get('body');
158186

@@ -169,10 +197,7 @@ function updateModuleForToNestedModule(j, root) {
169197
currentModuleCallbackBody.push(expression);
170198

171199
if (currentTestType === 'setupRenderingTest') {
172-
let isTest = j.match(expression, { expression: { callee: { name: 'test' } } });
173-
if (isTest) {
174-
expression.expression.arguments[1].async = true;
175-
}
200+
processRenderingTest(expression);
176201
}
177202
} else {
178203
bodyReplacement.push(expression);

0 commit comments

Comments
 (0)