Skip to content

Commit 8ee80a4

Browse files
author
Robert Jackson
committed
Modify wait rewriting to be more intelligent.
* Only update when `ember-test-helpers/wait` was imported * Only update the actual imported name to `settled` * Unconditionally update `wait` import when found (was previously only happening in non-test files?!?!).
1 parent a59f32f commit 8ee80a4

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

ember-qunit-codemod.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,6 @@ module.exports = function(file, api, options) {
119119
}
120120
});
121121

122-
root
123-
.find(j.ImportDeclaration, { source: { value: 'ember-test-helpers/wait' } })
124-
.forEach(p => {
125-
specifiers.add('settled');
126-
return p;
127-
})
128-
.remove();
129-
130122
if (specifiers.size > 0) {
131123
ensureImportWithSpecifiers({
132124
source: 'ember-test-helpers',
@@ -548,10 +540,27 @@ module.exports = function(file, api, options) {
548540
.forEach(replacement);
549541
}
550542

551-
function updateWaitCalls() {
552-
root.find(j.CallExpression, { callee: { name: 'wait' } }).forEach(p => {
553-
p.node.callee.name = 'settled';
543+
function updateWaitUsage() {
544+
let waitImport = root.find(j.ImportDeclaration, {
545+
source: { value: 'ember-test-helpers/wait' },
554546
});
547+
548+
if (waitImport.size() > 0) {
549+
let importedName;
550+
551+
ensureImportWithSpecifiers({
552+
source: 'ember-test-helpers',
553+
anchor: 'ember-qunit',
554+
specifiers: ['settled'],
555+
});
556+
557+
waitImport.find(j.ImportDefaultSpecifier).forEach(p => (importedName = p.node.local.name));
558+
waitImport.remove();
559+
560+
root.find(j.CallExpression, { callee: { name: importedName } }).forEach(p => {
561+
p.node.callee.name = 'settled';
562+
});
563+
}
555564
}
556565

557566
const printOptions = options.printOptions || { quote: 'single' };
@@ -567,8 +576,9 @@ module.exports = function(file, api, options) {
567576
updateInjectCalls();
568577
} else {
569578
updateEmberTestHelperImports();
570-
updateWaitCalls();
571579
}
572580

581+
updateWaitUsage();
582+
573583
return root.toSource(printOptions);
574584
};

0 commit comments

Comments
 (0)