@@ -22,13 +22,14 @@ jest.mock('../../../common/util/logger', () => ({
22
22
} ,
23
23
} ) ) ;
24
24
25
- import * as explainer from '../../../if-run/lib/explain' ;
26
-
27
- import { compute } from '../../../if-run/lib/compute' ;
28
25
import { ComputeParams } from '../../../if-run/types/compute' ;
29
26
import { pluginStorage } from '../../../if-run/util/plugin-storage' ;
30
27
31
28
describe ( 'lib/compute: ' , ( ) => {
29
+ beforeEach ( ( ) => {
30
+ jest . resetModules ( ) ;
31
+ } ) ;
32
+
32
33
/**
33
34
* Mock plugins.
34
35
*/
@@ -135,6 +136,7 @@ describe('lib/compute: ', () => {
135
136
136
137
describe ( 'compute(): ' , ( ) => {
137
138
it ( 'computes simple tree with execute plugin.' , async ( ) => {
139
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
138
140
const tree = {
139
141
children : {
140
142
mockChild : {
@@ -156,6 +158,7 @@ describe('lib/compute: ', () => {
156
158
} ) ;
157
159
158
160
it ( 'computes simple tree with regroup on inputs only (no compute).' , async ( ) => {
161
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
159
162
const tree = {
160
163
children : {
161
164
mockChild : {
@@ -184,7 +187,34 @@ describe('lib/compute: ', () => {
184
187
expect ( response . children . mockChild . children ) . toEqual ( expectedResponse ) ;
185
188
} ) ;
186
189
190
+ it ( 'skips regrouping on already regrouped data.' , async ( ) => {
191
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
192
+ const expectedResponse = {
193
+ 'uk-west' : {
194
+ inputs : [ { region : 'uk-west' , timestamp : 'mock-timestamp-1' } ] ,
195
+ } ,
196
+ 'uk-east' : {
197
+ inputs : [
198
+ { region : 'uk-east' , timestamp : 'mock-timestamp-2' } ,
199
+ { region : 'uk-east' , timestamp : 'mock-timestamp-3' } ,
200
+ ] ,
201
+ } ,
202
+ } ;
203
+ const tree = {
204
+ children : {
205
+ mockChild : {
206
+ pipeline : { regroup : [ 'region' ] } ,
207
+ children : expectedResponse ,
208
+ } ,
209
+ } ,
210
+ } ;
211
+ const response = await compute ( tree , paramsExecute ) ;
212
+
213
+ expect ( response . children . mockChild . children ) . toEqual ( expectedResponse ) ;
214
+ } ) ;
215
+
187
216
it ( 'computes simple tree with regroup, grouping inputs and outputs.' , async ( ) => {
217
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
188
218
const tree = {
189
219
children : {
190
220
mockChild : {
@@ -232,6 +262,7 @@ describe('lib/compute: ', () => {
232
262
} ) ;
233
263
234
264
it ( 'computes simple tree with defaults and execute plugin.' , async ( ) => {
265
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
235
266
const tree = {
236
267
children : {
237
268
mockChild : {
@@ -259,6 +290,7 @@ describe('lib/compute: ', () => {
259
290
} ) ;
260
291
261
292
it ( 'computes nested tree with defaults and execute plugin.' , async ( ) => {
293
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
262
294
const tree = {
263
295
children : {
264
296
mockChild1 : {
@@ -308,6 +340,7 @@ describe('lib/compute: ', () => {
308
340
} ) ;
309
341
310
342
it ( 'computes simple tree with no defaults and no inputs with execute plugin.' , async ( ) => {
343
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
311
344
const tree = {
312
345
children : {
313
346
mockChild : {
@@ -323,6 +356,7 @@ describe('lib/compute: ', () => {
323
356
} ) ;
324
357
325
358
it ( 'computes simple tree with defaults and no inputs with execute plugin.' , async ( ) => {
359
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
326
360
const tree = {
327
361
children : {
328
362
mockChild : {
@@ -343,6 +377,7 @@ describe('lib/compute: ', () => {
343
377
} ) ;
344
378
345
379
it ( 'computes simple tree with append, preserving existing outputs.' , async ( ) => {
380
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
346
381
const tree = {
347
382
children : {
348
383
mockChild : {
@@ -378,6 +413,7 @@ describe('lib/compute: ', () => {
378
413
} ) ;
379
414
380
415
it ( 'computes simple tree with append when outputs is null.' , async ( ) => {
416
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
381
417
const tree = {
382
418
children : {
383
419
mockChild : {
@@ -402,6 +438,7 @@ describe('lib/compute: ', () => {
402
438
} ) ;
403
439
404
440
it ( 'computes simple tree with regroup and append, with existing outputs preserved and regrouped without re-computing.' , async ( ) => {
441
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
405
442
const tree = {
406
443
children : {
407
444
mockChild : {
@@ -434,6 +471,7 @@ describe('lib/compute: ', () => {
434
471
} ) ;
435
472
436
473
it ( 'computes simple tree with regroup and append, with existing outputs preserved and without new outputs.' , async ( ) => {
474
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
437
475
const tree = {
438
476
children : {
439
477
mockChild : {
@@ -460,6 +498,7 @@ describe('lib/compute: ', () => {
460
498
} ) ;
461
499
462
500
it ( 'computes simple tree with regroup and no append, with existing outputs that are removed.' , async ( ) => {
501
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
463
502
const tree = {
464
503
children : {
465
504
mockChild : {
@@ -488,6 +527,7 @@ describe('lib/compute: ', () => {
488
527
} ) ;
489
528
490
529
it ( 'computes simple tree with observe plugin.' , async ( ) => {
530
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
491
531
const tree = {
492
532
children : {
493
533
mockChild : {
@@ -507,6 +547,7 @@ describe('lib/compute: ', () => {
507
547
} ) ;
508
548
509
549
it ( 'computes simple tree with observe plugin.' , async ( ) => {
550
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
510
551
const tree = {
511
552
children : {
512
553
mockChild : {
@@ -526,6 +567,7 @@ describe('lib/compute: ', () => {
526
567
} ) ;
527
568
528
569
it ( 'observes simple tree with observe plugin.' , async ( ) => {
570
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
529
571
const tree = {
530
572
children : {
531
573
mockChild : {
@@ -545,6 +587,7 @@ describe('lib/compute: ', () => {
545
587
} ) ;
546
588
547
589
it ( 'observes simple tree with config.' , async ( ) => {
590
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
548
591
const tree = {
549
592
children : {
550
593
mockChild : {
@@ -565,6 +608,7 @@ describe('lib/compute: ', () => {
565
608
} ) ;
566
609
567
610
it ( 'warns when pipeline is null.' , async ( ) => {
611
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
568
612
process . env . LOGGER = 'invalid' ;
569
613
const tree = {
570
614
children : {
@@ -583,6 +627,7 @@ describe('lib/compute: ', () => {
583
627
} ) ;
584
628
585
629
it ( 'warns when pipeline is an empty object.' , async ( ) => {
630
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
586
631
const tree = {
587
632
children : {
588
633
mockChild : {
@@ -598,6 +643,7 @@ describe('lib/compute: ', () => {
598
643
} ) ;
599
644
600
645
it ( 'warns when config is provided in the tree.' , async ( ) => {
646
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
601
647
process . env . LOGGER = 'true' ;
602
648
const tree = {
603
649
children : {
@@ -624,6 +670,7 @@ describe('lib/compute: ', () => {
624
670
} ) ;
625
671
626
672
it ( 'warns when config is provided in the tree and it is null.' , async ( ) => {
673
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
627
674
process . env . LOGGER = 'empty' ;
628
675
const tree = {
629
676
children : {
@@ -650,6 +697,8 @@ describe('lib/compute: ', () => {
650
697
} ) ;
651
698
652
699
it ( 'observes simple tree with execute plugin and explain property.' , async ( ) => {
700
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
701
+ const explainer = require ( '../../../if-run/lib/explain' ) ;
653
702
const tree = {
654
703
children : {
655
704
mockChild : {
@@ -678,6 +727,7 @@ describe('lib/compute: ', () => {
678
727
} ) ;
679
728
680
729
it ( 'computes simple tree with execute plugin and explain property.' , async ( ) => {
730
+ const { compute} = require ( '../../../if-run/lib/compute' ) ;
681
731
const tree = {
682
732
children : {
683
733
mockChild : {
0 commit comments