Skip to content

Commit 9838ebc

Browse files
authored
Merge pull request #6 from cibernox/replace-this-registry
Replace `this.register` with `this.owner.register`
2 parents bb67fd8 + c2ce101 commit 9838ebc

3 files changed

Lines changed: 72 additions & 1 deletion

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { moduleFor, test } from 'ember-qunit';
2+
3+
moduleFor('service:foo', 'Unit | Service | Foo', {
4+
beforeEach() {
5+
this.register('service:thingy', thingy);
6+
this.registry.register('service:thingy', thingy);
7+
}
8+
});
9+
10+
test('it happens', function() {
11+
this.register('service:thingy', thingy);
12+
this.registry.register('service:thingy', thingy);
13+
});
14+
15+
moduleFor('service:bar', 'Unit | Service | Bar');
16+
17+
test('it happens again?', function() {
18+
this.register('service:thingy', thingy);
19+
this.registry.register('service:thingy', thingy);
20+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
3+
4+
module('Unit | Service | Foo', function(hooks) {
5+
setupTest(hooks);
6+
7+
hooks.beforeEach(function() {
8+
this.owner.register('service:thingy', thingy);
9+
this.owner.register('service:thingy', thingy);
10+
});
11+
12+
test('it happens', function() {
13+
this.owner.register('service:thingy', thingy);
14+
this.owner.register('service:thingy', thingy);
15+
});
16+
});
17+
18+
module('Unit | Service | Bar', function(hooks) {
19+
setupTest(hooks);
20+
21+
test('it happens again?', function() {
22+
this.owner.register('service:thingy', thingy);
23+
this.owner.register('service:thingy', thingy);
24+
});
25+
});

ember-qunit-codemod.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ function updateModuleForToNestedModule(j, root) {
242242
}
243243

244244
function updateLookupCalls(j, root) {
245-
return root
245+
root
246246
.find(j.MemberExpression, {
247247
object: {
248248
object: { type: 'ThisExpression' },
@@ -256,6 +256,31 @@ function updateLookupCalls(j, root) {
256256
});
257257
}
258258

259+
function updateRegisterCalls(j, root) {
260+
root
261+
.find(j.MemberExpression, {
262+
object: {
263+
object: { type: 'ThisExpression' },
264+
property: { name: 'registry' },
265+
},
266+
property: { name: 'register' },
267+
})
268+
.forEach(path => {
269+
let thisDotOwner = j.memberExpression(j.thisExpression(), j.identifier('owner'));
270+
path.replace(j.memberExpression(thisDotOwner, path.value.property));
271+
});
272+
273+
root
274+
.find(j.MemberExpression, {
275+
object: { type: 'ThisExpression' },
276+
property: { name: 'register' },
277+
})
278+
.forEach(path => {
279+
let thisDotOwner = j.memberExpression(j.thisExpression(), j.identifier('owner'));
280+
path.replace(j.memberExpression(thisDotOwner, path.value.property));
281+
});
282+
}
283+
259284
module.exports = function(file, api, options) {
260285
const j = api.jscodeshift;
261286

@@ -272,6 +297,7 @@ module.exports = function(file, api, options) {
272297
updateToNewEmberQUnitImports(j, root);
273298
updateModuleForToNestedModule(j, root);
274299
updateLookupCalls(j, root);
300+
updateRegisterCalls(j, root);
275301

276302
return root.toSource(printOptions);
277303
};

0 commit comments

Comments
 (0)