-
Notifications
You must be signed in to change notification settings - Fork 6
/
fourteen-testing-api.js
executable file
·861 lines (748 loc) · 24.7 KB
/
fourteen-testing-api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
"use strict";
module.exports = function(file, api) {
const j = api.jscodeshift;
const root = j(file.source);
const SETUP_TYPE_METHODS = ["setupComponentTest", "setupModelTest"];
function isSetupTypeMethod(nodePath) {
return SETUP_TYPE_METHODS.some(name => {
let matcher = {
type: "ExpressionStatement",
expression: { callee: { name } }
};
return j.match(nodePath, matcher);
});
}
const GLOBAL_NODE_PATH_CACHE = new Map();
// returns startAppAssignment nodePath or false;
function findStartAppAssignment(nodePath) {
let startAppAssignment = GLOBAL_NODE_PATH_CACHE.has(nodePath);
if (startAppAssignment) { return GLOBAL_NODE_PATH_CACHE.get(nodePath) }
let assignments = j(nodePath).find(j.ExpressionStatement, { expression: { right: { callee: { name: 'startApp' } } } });
if (assignments.length >= 1) {
let foundAssignment = assignments.paths()[0];
GLOBAL_NODE_PATH_CACHE.set(nodePath, foundAssignment);
return foundAssignment;
} else {
return false;
}
}
// returns boolean for other unit tests with needs object argument
// the lengthy isSetupNeedsTest safely checks for
// patterns in ember-mocha test suites that called setupTest with 2 arguments
// 1st, the path of the object 2nd the configuration of what that test needed
// setupTest('controller:my-controller', {
// needs: [
// 'service:ajax',
// 'controller:application'
// ]
// });
function findOtherUnitTestSetup(nodePath) {
let hasSetup = j(nodePath).find(j.ExpressionStatement, { expression: { callee: { name: 'setupTest' } } } )
let isSetupNeeds = hasSetup
&& j.ExpressionStatement.check(nodePath)
&& nodePath.expression.arguments
&& nodePath.expression.arguments.length === 2
&& j.Literal.check(nodePath.expression.arguments[0])
&& (
/^(adapter|controller|route|service|serializer|transform):/.test(nodePath.expression.arguments[0].value)
)
return isSetupNeeds ;
}
function findDestroyAppCall(nodePath) {
let destroys = j(nodePath).find(j.ExpressionStatement, { expression: {callee: { name: 'destroyApp' } } } )
if (destroys.length >= 1) {
let foundDestroy = destroys.paths()[0];
j(foundDestroy).remove();
}
}
function processExpressionForApplicationTest(testExpression) {
// mark the test function as an async function
let testExpressionCollection = j(testExpression);
// collect all potential statements to be imported
let specifiers = new Set();
// First - remove andThen blocks
removeAndThens(testExpressionCollection);
// Second - Transform to await visit(), click, fillIn, touch, etc and adds `async` to scope
[
'visit',
'find',
'waitFor',
'fillIn',
'click',
'blur',
'focus',
'tap',
'triggerEvent',
'triggerKeyEvent',
].forEach(type => {
findApplicationTestHelperUsageOf(testExpressionCollection, type).forEach(p => {
specifiers.add(type);
let expression = p.get('expression');
let awaitExpression = j.awaitExpression(
j.callExpression(j.identifier(type), expression.node.arguments)
);
expression.replace(awaitExpression);
p.scope.node.async = true;
});
});
// Third - update call expressions that do not await
['currentURL', 'currentRouteName'].forEach(type => {
testExpressionCollection
.find(j.CallExpression, {
callee: {
type: 'Identifier',
name: type,
},
})
.forEach(() => specifiers.add(type));
});
}
function removeAndThens(testExpressionCollection) {
let replacements = testExpressionCollection
.find(j.CallExpression, {
callee: {
name: 'andThen',
},
})
.map(path => path.parent)
.replaceWith(p => {
let body = p.node.expression.arguments[0].body
return body.body;
});
if (replacements.length > 0) {
removeAndThens(testExpressionCollection);
}
}
function findApplicationTestHelperUsageOf(collection, property) {
return collection.find(j.ExpressionStatement, {
expression: {
callee: {
type: 'Identifier',
name: property,
},
},
});
}
const LIFE_CYCLE_METHODS = [
{ expression: { callee: { name: "before" } } },
{ expression: { callee: { name: "beforeEach" } } },
{ expression: { callee: { name: "afterEach" } } },
{ expression: { callee: { name: "context" } } },
{ expression: { callee: { name: "after" } } }
];
function isLifecycleHook(node) {
return LIFE_CYCLE_METHODS.some(matcher => j.match(node, matcher));
}
const MODULE_INFO_CACHE = new Map();
class ModuleInfo {
constructor(p) {
if (MODULE_INFO_CACHE.has(p)) {
return MODULE_INFO_CACHE.get(p);
}
this.isEmberMochaDescribe = false;
this.tests = [];
this.lifecycles = [];
this.body = p.node.expression.arguments[1].body;
let describeBody = p.node.expression.arguments[1].body.body;
describeBody.forEach(node => {
let isAcceptanceTest = findStartAppAssignment(node);
findDestroyAppCall(node);
let isOtherUnitTest = findOtherUnitTestSetup(node);
if (isSetupTypeMethod(node)) {
let calleeName = node.expression.callee.name;
let options = node.expression.arguments[1];
if(options) {
this.hasIntegrationFlag = options.properties.some(p => p.key.name === "integration");
}
if(calleeName === 'setupComponentTest') {
if (this.hasIntegrationFlag) {
this.setupType = "setupRenderingTest";
this.subjectContainerKey = null;
} else {
this.setupType = "setupTest";
this.subjectContainerKey = j.literal(`component:${node.expression.arguments[0].value}`);
}
} else if (calleeName === 'setupModelTest') {
this.setupType = 'setupTest';
this.modelName = node.expression.arguments[0].value;
}
this.setupTypeMethodInvocationNode = node.expression;
this.isEmberMochaDescribe = true;
} else if (isAcceptanceTest) {
this.hasIntegrationFlag = false;
this.setupType = 'setupApplicationTest';
this.subjectContainerKey = null;
this.isEmberMochaDescribe = true;
this.testVarDeclarationName = isAcceptanceTest.value.expression.left.name;
// Add setupApplicationTest to beginning of body
let exp = j.expressionStatement(
j.callExpression(j.identifier('setupApplicationTest'), [])
);
this.body.body = [exp, ...this.body.body];
// remove startApp invocation
j(isAcceptanceTest).remove();
} else if (isOtherUnitTest) {
this.setupType = 'setupTest';
this.setupTypeMethodInvocationNode = node.expression;
this.subjectContainerKey = j.literal(node.expression.arguments[0].value);
this.isEmberMochaDescribe = true;
}
let testPaths = j(node).find(j.ExpressionStatement, { expression: { callee: { name: 'it' } }}).paths();
if (testPaths.length > 0) {
testPaths.forEach(p => this.tests.push(p.value));
}
if (j.match(node, { expression: { callee: { name: "it" } } })) {
this.tests.push(node.expression);
}
if (isLifecycleHook(node)) {
this.lifecycles.push(node.expression);
}
});
if (this.isEmberMochaDescribe === false) {
let current = p.parentPath;
while(current) {
let matcher = { expression: { callee: { name: 'describe' } } };
if (j.match(current.node, matcher)) {
let parentMod = MODULE_INFO_CACHE.get(current);
if (parentMod && parentMod.isEmberMochaDescribe) {
this.isEmberMochaDescribe = true;
this.setupType = parentMod.setupType;
this.subjectContainerKey = parentMod.subjectContainerKey;
}
}
current = current.parentPath;
}
}
MODULE_INFO_CACHE.set(p, this);
}
update() {
this.updateSetupInvocation();
this.updateTests();
this.updateLifecycles();
this.updateRegisterCalls();
this.updateInjectCalls();
this.processSubject();
}
updateSetupInvocation() {
if (this.setupTypeMethodInvocationNode) {
this.setupTypeMethodInvocationNode.arguments = [];
this.setupTypeMethodInvocationNode.callee.name = this.setupType;
}
}
_updateExpressionForTest(expression) {
if (this.setupType === "setupRenderingTest") {
processExpressionForRenderingTest(expression);
} else if (this.setupType === 'setupApplicationTest') {
processExpressionForApplicationTest(expression)
}
}
updateTests() {
this.tests.forEach(e => this._updateExpressionForTest(e));
}
updateLifecycles() {
this.lifecycles.forEach(e => this._updateExpressionForTest(e));
}
updateRegisterCalls() {
[...this.lifecycles, ...this.tests].forEach(updateRegisterCalls);
}
updateInjectCalls() {
[...this.lifecycles, ...this.tests].forEach(updateInjectCalls);
}
processSubject() {
[...this.lifecycles, ...this.tests].forEach(e => processSubject(e, this));
}
}
function migrateAcceptanceTestImports() {
let imports = root.find(j.ImportDeclaration);
let foundStartApp = false;
imports
.find(j.ImportDefaultSpecifier, {
local: {
type: 'Identifier',
name: 'startApp',
},
})
.forEach(p => {
foundStartApp = true;
// add setupApplicationTest import
ensureImportWithSpecifiers({
source: 'ember-mocha',
anchor: 'mocha',
specifiers: ['setupApplicationTest'],
});
// ensure module import if acceptance test
ensureImportWithSpecifiers({
source: 'mocha',
specifiers: ['describe'],
});
// remove existing moduleForAcceptance import
j(p.parentPath.parentPath).remove();
});
// remove `destroyApp` import also
if (foundStartApp) {
imports.find(j.ImportDefaultSpecifier, {
local: {
type: 'Identifier',
name: 'destroyApp'
}
}).forEach(p => {
j(p.parentPath.parentPath).remove();
})
}
}
function updateRegisterCalls(e) {
j(e)
.find(j.MemberExpression, {
object: { type: "ThisExpression" },
property: { name: "register" }
})
.forEach(path => {
let thisDotOwner = j.memberExpression(j.thisExpression(), j.identifier("owner"));
path.replace(j.memberExpression(thisDotOwner, path.value.property));
});
}
function updateOnCalls(node) {
let ctx = j(node);
let usages = ctx.find(j.CallExpression, {
callee: {
type: "MemberExpression",
object: {
type: "ThisExpression"
},
property: {
name: "on"
}
}
});
usages.forEach(p => {
let actionName = p.node.arguments[0].value;
p.value.callee.property.name = "set";
ctx.find(j.TemplateElement).forEach(e => {
if (e.value.value.raw.indexOf(actionName) !== -1) {
let currentValue = e.value.value.raw;
let reg = new RegExp(`("|')${actionName}("|')`);
e.value.value.raw = currentValue.replace(reg, actionName);
}
});
});
}
function updateInjectCalls(node) {
let ctx = j(node);
ctx
.find(j.CallExpression, {
callee: {
type: "MemberExpression",
object: {
object: {
type: "ThisExpression"
},
property: {
name: "inject"
}
}
}
})
.forEach(p => {
let injectType = p.node.callee.property.name;
let injectedName = p.node.arguments[0].value;
let localName = injectedName;
if (p.node.arguments[1]) {
let options = p.node.arguments[1];
let as = options.properties.find(property => property.key.name === "as");
if (as) {
localName = as.value.value;
}
}
let property = j.identifier(localName);
// rudimentary attempt to confirm the property name is valid
// as `this.propertyName`
if (!localName.match(/^[a-zA-Z_][a-zA-Z0-9]+$/)) {
// if not, use `this['property-name']`
property = j.literal(localName);
}
let assignment = j.assignmentExpression(
"=",
j.memberExpression(j.thisExpression(), property),
j.callExpression(
j.memberExpression(
j.memberExpression(j.thisExpression(), j.identifier("owner")),
j.identifier("lookup")
),
[j.literal(`${injectType}:${injectedName}`)]
)
);
p.replace(assignment);
});
}
function processSubject(testExpression, moduleInfo) {
let subject = moduleInfo.subjectContainerKey;
let thisDotSubjectUsage = j(testExpression).find(j.CallExpression, {
callee: {
type: 'MemberExpression',
object: {
type: 'ThisExpression',
},
property: {
name: 'subject',
},
},
});
if (thisDotSubjectUsage.size() === 0) {
return;
}
thisDotSubjectUsage.forEach(p => {
let options = p.node.arguments[0];
let subjectType;
let subjectName;
if ('modelName' in moduleInfo) {
subjectType = 'model';
subjectName = moduleInfo.modelName;
} else {
let split = subject.value.split(':');
subjectType = split[0];
subjectName = split[1];
}
let isSingletonSubject = !['model', 'component', 'serializer'].includes(subjectType);
// if we don't have `options` and the type is a singleton type
// use `this.owner.lookup(subject)`
if (!options && isSingletonSubject) {
p.replace(
j.callExpression(
j.memberExpression(
j.memberExpression(j.thisExpression(), j.identifier('owner')),
j.identifier('lookup')
),
[subject]
)
);
} else if (subjectType === 'serializer') {
p.replace(
j.callExpression(
j.memberExpression(
j.callExpression(
j.memberExpression(
j.memberExpression(j.thisExpression(), j.identifier('owner')),
j.identifier('lookup')
),
[j.literal('service:store')]
),
j.identifier('serializerFor')
),
[j.literal(subjectName)].filter(Boolean)
)
);
} else if (subjectType === 'model') {
let createRecordArg = p.node.arguments[0] ?
p.node.arguments[0] : /* the argument provided to this.subject() */
j.objectExpression([]) /* empty object expression {} */;
p.replace(
j.callExpression(
j.memberExpression(
j.callExpression(
j.memberExpression(
j.memberExpression(j.thisExpression(), j.identifier('owner')),
j.identifier('lookup')
),
[j.literal('service:store')]
),
j.identifier('createRecord')
),
// creating an empty object expression {} as the 2nd argument here
// because setupModelTests shouldn't need store dependencies
[j.literal(subjectName), createRecordArg].filter(Boolean)
)
);
} else {
p.replace(
j.callExpression(
j.memberExpression(
j.callExpression(
j.memberExpression(
j.memberExpression(j.thisExpression(), j.identifier('owner')),
j.identifier('factoryFor')
),
[subject]
),
j.identifier('create')
),
[options].filter(Boolean)
)
);
}
});
}
function findTestHelperUsageOf(collection, property) {
return collection.find(j.ExpressionStatement, {
expression: {
callee: {
object: {
type: "ThisExpression"
},
property: {
name: property
}
}
}
});
}
function processExpressionForRenderingTest(testExpression) {
// mark the test function as an async function
let testExpressionCollection = j(testExpression);
let specifiers = new Set();
// Transform to await render() or await clearRender()
["render", "clearRender"].forEach(type => {
findTestHelperUsageOf(testExpressionCollection, type).forEach(p => {
specifiers.add(type);
let expression = p.get("expression");
let awaitExpression = j.awaitExpression(
j.callExpression(j.identifier(type), expression.node.arguments)
);
expression.replace(awaitExpression);
p.scope.node.async = true;
});
});
if (specifiers.size === 0) {
specifiers.add("render");
}
ensureImportWithSpecifiers({
source: "@ember/test-helpers",
anchor: "ember-mocha",
specifiers
});
// Migrate `this._element` -> `this.element`
testExpressionCollection
.find(j.MemberExpression, {
object: {
type: "ThisExpression"
},
property: {
name: "_element"
}
})
.forEach(p => {
let property = p.get("property");
property.node.name = "element";
});
}
function ensureImport(source, anchor, method) {
method = method || "insertAfter";
let desiredImport = root.find(j.ImportDeclaration, { source: { value: source } });
if (desiredImport.size() > 0) {
return desiredImport;
}
let newImport = j.importDeclaration([], j.literal(source));
let anchorImport = root.find(j.ImportDeclaration, { source: { value: anchor } });
let imports = root.find(j.ImportDeclaration);
if (anchorImport.size() > 0) {
anchorImport.at(anchorImport.size() - 1)[method](newImport);
} else if (imports.size() > 0) {
// if anchor is not present, always add at the end
imports.at(imports.size() - 1).insertAfter(newImport);
} else {
// if no imports are present, add as first statement
root.get().node.program.body.unshift(newImport);
}
return j(newImport);
}
function ensureImportWithSpecifiers(options) {
let source = options.source;
let specifiers = options.specifiers;
let anchor = options.anchor;
let positionMethod = options.positionMethod;
let importStatement = ensureImport(source, anchor, positionMethod);
let combinedSpecifiers = new Set(specifiers);
importStatement
.find(j.ImportSpecifier)
.forEach(i => combinedSpecifiers.add(i.node.imported.name))
.remove();
importStatement.get("specifiers").replace(
Array.from(combinedSpecifiers)
.sort()
.map(s => j.importSpecifier(j.identifier(s)))
);
}
function updateToNewEmberMochaImports() {
let mapping = {
setupComponentTest: "setupRenderingTest",
setupModelTest: "setupTest"
};
let emberMochaImports = root.find(j.ImportDeclaration, { source: { value: "ember-mocha" } });
if (emberMochaImports.size() === 0) {
return;
}
// Collect all imports from ember-mocha into local array
let emberMochaSpecifiers = new Set();
emberMochaImports
.find(j.ImportSpecifier)
.forEach(p => {
// Map them to the new imports
let importName = p.node.imported.name;
let mappedName = mapping[importName] || importName;
if (importName === "setupComponentTest") {
root
.find(j.ExpressionStatement, {
expression: {
callee: { name: "describe" }
}
})
.forEach(p => {
let mod = new ModuleInfo(p);
if(mod.setupType) {
emberMochaSpecifiers.add(mod.setupType);
}
});
} else {
emberMochaSpecifiers.add(mappedName);
}
})
// Remove all existing import specifiers
.remove();
emberMochaImports
.get("specifiers")
.replace(Array.from(emberMochaSpecifiers).map(s => j.importSpecifier(j.identifier(s))));
// If we have an empty import, remove the import declaration
if (emberMochaSpecifiers.size === 0) {
emberMochaImports.remove();
}
}
function processDescribeBlock() {
let describes = root.find(j.ExpressionStatement, {
expression: {
callee: { name: "describe" }
}
});
if (describes.length === 0) {
return;
}
describes.forEach(path => {
let moduleInfo = new ModuleInfo(path);
if (!moduleInfo.isEmberMochaDescribe) { return; }
moduleInfo.update();
updateOnCalls(path);
if (moduleInfo.setupType === 'setupApplicationTest') {
replaceApplicationTestVariableDeclarator(path, moduleInfo.testVarDeclarationName)
}
_relabelExistingRenders(path);
_removeUnusedLifecycleHooks(path)
})
}
function replaceApplicationTestVariableDeclarator(node, name) {
j(node)
.find(j.VariableDeclarator)
.forEach(path => {
if (path.node.id.name === name) {
j(path.parent).remove();
}
});
}
function _relabelExistingRenders(path) {
const hasExisting = j(path).find(j.VariableDeclarator, {
id: {
name: "render"
}
}).filter(p => {
return p.parentPath.parentPath.value.kind === "let";
});
const curHook = j(path);
// transforms render function expressions into async
["render"].forEach(type => {
curHook.find(j.AssignmentExpression, {
left: {
type: "Identifier",
name: "render"
},
right: {
type: "ArrowFunctionExpression"
}
})
.forEach(p => {
// mark the right hand expression as an async function
p.value.right.async = true;
});
curHook.find(j.CallExpression, {
callee: {
object: {
type: "ThisExpression"
},
property: {
name: type
}
}
}).forEach(p => {
let expression = p.get("expression");
p.replace(j.callExpression(j.identifier(type), expression.node.arguments));
});
});
const newAlias = "render2";
const finder = a => a.type === "VariableDeclarator" && a.id.name === "render";
j(path).find(j.VariableDeclaration, {
kind: "let"
})
.filter(p => {
return p.value.declarations.find(finder);
})
.forEach(p => {
try {
const { declarations } = p.value;
const relevant = declarations.find(finder);
relevant.id.name = newAlias;
} catch (err) { } // eslint-disable-line no-empty
});
if (hasExisting.size() === 1) {
j(path).find(j.AssignmentExpression, {
left: {
type: "Identifier",
name: "render"
},
right: {
type: "ArrowFunctionExpression"
}
}).forEach(p => {
p.node.left.name = newAlias;
});
// rename renders in it blocks
j(path).find(j.ExpressionStatement, {
expression: {
type: "CallExpression",
callee: {
name: "render"
}
}
})
.forEach(p => {
p.node.expression.callee.name = newAlias;
let expression = p.get("expression");
let awaitExpression = j.awaitExpression(
j.callExpression(j.identifier(newAlias), expression.node.arguments)
);
p.scope.node.async = true;
expression.replace(awaitExpression);
})
}
}
function _removeUnusedLifecycleHooks(path) {
['beforeEach', 'afterEach', 'before', 'after', 'context',].forEach(name => {
j(path)
.find(j.ExpressionStatement, {
expression: {
callee: {
name
}
}
})
.forEach(node => {
if (!node.value.expression.arguments[0].body) {
return;
}
if (!node.value.expression.arguments[0].body.body.length >= 1) {
j(node).remove()
}
});
});
}
const printOptions = { quote: "single", wrapColumn: 100 };
updateToNewEmberMochaImports();
migrateAcceptanceTestImports();
processDescribeBlock();
return root.toSource(printOptions);
};