Skip to content

Commit 712edcf

Browse files
authored
Merge pull request #43 from rwjblue/handle-all-options
Ensure all options to moduleFor* are handled.
2 parents 92afef0 + f9dde32 commit 712edcf

3 files changed

Lines changed: 54 additions & 5 deletions

File tree

__testfixtures__/ember-qunit-codemod/custom-functions-in-options.input.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,23 @@ test('can have two', function(assert) {
2424
let custom = this.customFunction();
2525
let other = this.otherThing();
2626
});
27+
28+
moduleFor('foo:bar', {
29+
m3: true,
30+
});
31+
32+
test('can access', function(assert) {
33+
let usesM3 = this.m3;
34+
});
35+
36+
moduleFor('foo:bar', {
37+
m3: true,
38+
39+
beforeEach() {
40+
doStuff();
41+
},
42+
});
43+
44+
test('separate `hooks.beforeEach` than lifecycle hooks', function(assert) {
45+
let usesM3 = this.m3;
46+
});

__testfixtures__/ember-qunit-codemod/custom-functions-in-options.output.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,31 @@ module('stuff:here', function(hooks) {
3333
let other = this.otherThing();
3434
});
3535
});
36+
37+
module('foo:bar', function(hooks) {
38+
setupTest(hooks);
39+
40+
hooks.beforeEach(function() {
41+
this.m3 = true;
42+
});
43+
44+
test('can access', function(assert) {
45+
let usesM3 = this.m3;
46+
});
47+
});
48+
49+
module('foo:bar', function(hooks) {
50+
setupTest(hooks);
51+
52+
hooks.beforeEach(function() {
53+
this.m3 = true;
54+
});
55+
56+
hooks.beforeEach(function() {
57+
doStuff();
58+
});
59+
60+
test('separate `hooks.beforeEach` than lifecycle hooks', function(assert) {
61+
let usesM3 = this.m3;
62+
});
63+
});

ember-qunit-codemod.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,6 @@ module.exports = function(file, api, options) {
195195
return POSSIBLE_MODULES.some(matcher => j.match(nodePath, matcher));
196196
}
197197

198-
function isMethod(nodePath) {
199-
return j.match(nodePath, { value: { type: 'FunctionExpression' } });
200-
}
201-
202198
const LIFE_CYCLE_METHODS = [
203199
{ key: { name: 'before' }, value: { type: 'FunctionExpression' } },
204200
{ key: { name: 'beforeEach' }, value: { type: 'FunctionExpression' } },
@@ -242,7 +238,12 @@ module.exports = function(file, api, options) {
242238
lifecycleStatement.comments = property.comments;
243239

244240
callback.body.body.push(lifecycleStatement);
245-
} else if (isMethod(property)) {
241+
} else {
242+
const IGNORED_PROPERTIES = ['integration', 'needs', 'unit'];
243+
if (IGNORED_PROPERTIES.includes(property.key.name)) {
244+
return;
245+
}
246+
246247
if (!customMethodBeforeEachBody) {
247248
customMethodBeforeEachBody = j.blockStatement([]);
248249
customMethodBeforeEachExpression = j.expressionStatement(

0 commit comments

Comments
 (0)