Skip to content

Commit 3d71a6f

Browse files
authored
Merge pull request #51 from Turbo87/module-line-breaks
Prevent line breaks in module() invocation
2 parents 0b447c2 + 09e8f47 commit 3d71a6f

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { moduleFor, test } from 'ember-qunit';
2+
3+
moduleFor('service:foo', 'Unit | Service | Foo with a very long name that would cause line breaks');
4+
5+
test('it happens', function() {
6+
7+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
3+
4+
module('Unit | Service | Foo with a very long name that would cause line breaks', function(hooks) {
5+
setupTest(hooks);
6+
7+
test('it happens', function() {
8+
9+
});
10+
});

ember-qunit-codemod.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,35 @@ module.exports = function(file, api, options) {
234234
[j.identifier('hooks')],
235235
j.blockStatement([moduleSetupExpression].filter(Boolean))
236236
);
237-
let moduleInvocation = j.expressionStatement(
238-
j.callExpression(j.identifier('module'), [moduleName, callback])
239-
);
237+
238+
function buildModule(moduleName, callback) {
239+
// using j.callExpression() builds this:
240+
241+
// module(
242+
// 'some loooooooooooong name',
243+
// function(hooks) {
244+
// setupTest(hooks);
245+
// }
246+
// );
247+
248+
// but we want to enforce not having line breaks in the module() invocation
249+
// so we'll have to use a little hack to get this:
250+
251+
// module('some loooooooooooong name', function(hooks) {
252+
// setupTest(hooks);
253+
// });
254+
255+
let node = j(`module('moduleName', function(hooks) {})`)
256+
.find(j.CallExpression)
257+
.paths()[0].node;
258+
259+
node.arguments[0] = moduleName;
260+
node.arguments[1] = callback;
261+
262+
return node;
263+
}
264+
265+
let moduleInvocation = j.expressionStatement(buildModule(moduleName, callback));
240266

241267
if (options) {
242268
let customMethodBeforeEachBody, customMethodBeforeEachExpression;

0 commit comments

Comments
 (0)