@@ -5,15 +5,15 @@ import { Construct, ConstructOrder, DependencyGroup, Dependable, IConstruct } fr
5
5
// tslint:disable:max-line-length
6
6
7
7
test ( 'the "Root" construct is a special construct which can be used as the root of the tree' , ( ) => {
8
- const root = Construct . createRoot ( ) ;
8
+ const root = new Root ( ) ;
9
9
const node = root . node ;
10
10
expect ( node . id ) . toBe ( '' ) ;
11
11
expect ( node . scope ) . toBeUndefined ( ) ;
12
12
expect ( node . children . length ) . toBe ( 0 ) ;
13
13
} ) ;
14
14
15
15
test ( 'an empty string is a valid name for the root construct' , ( ) => {
16
- const root = Construct . createRoot ( ) ;
16
+ const root = new Root ( ) ;
17
17
expect ( root . node . id ) . toEqual ( '' ) ;
18
18
19
19
expect ( ( ) => new Construct ( root , '' ) ) . toThrow ( / O n l y r o o t c o n s t r u c t s / ) ;
@@ -32,7 +32,7 @@ test('construct.name returns the name of the construct', () => {
32
32
} ) ;
33
33
34
34
test ( 'construct id can use any character except the path separator' , ( ) => {
35
- const root = Construct . createRoot ( ) ;
35
+ const root = new Root ( ) ;
36
36
expect ( ( ) => new Construct ( root , 'valid' ) ) . not . toThrow ( ) ;
37
37
expect ( ( ) => new Construct ( root , 'ValiD' ) ) . not . toThrow ( ) ;
38
38
expect ( ( ) => new Construct ( root , 'Va123lid' ) ) . not . toThrow ( ) ;
@@ -48,7 +48,7 @@ test('construct id can use any character except the path separator', () => {
48
48
} ) ;
49
49
50
50
test ( 'if construct id contains path seperators, they will be replaced by double-dash' , ( ) => {
51
- const root = Construct . createRoot ( ) ;
51
+ const root = new Root ( ) ;
52
52
const c = new Construct ( root , 'Boom/Boom/Bam' ) ;
53
53
expect ( c . node . id ) . toBe ( 'Boom--Boom--Bam' ) ;
54
54
} ) ;
@@ -59,7 +59,7 @@ test('if "undefined" is forcefully used as an "id", it will be treated as an emp
59
59
} ) ;
60
60
61
61
test ( 'node.addr returns an opaque app-unique address for any construct' , ( ) => {
62
- const root = Construct . createRoot ( ) ;
62
+ const root = new Root ( ) ;
63
63
64
64
const child1 = new Construct ( root , 'This is the first child' ) ;
65
65
const child2 = new Construct ( child1 , 'Second level' ) ;
@@ -76,7 +76,7 @@ test('node.addr returns an opaque app-unique address for any construct', () => {
76
76
77
77
test ( 'node.addr excludes "default" from the address calculation' , ( ) => {
78
78
// GIVEN
79
- const root = Construct . createRoot ( ) ;
79
+ const root = new Root ( ) ;
80
80
const c1 = new Construct ( root , 'c1' ) ;
81
81
82
82
// WHEN:
@@ -97,23 +97,23 @@ test('node.addr excludes "default" from the address calculation', () => {
97
97
} ) ;
98
98
99
99
test ( 'construct.getChildren() returns an array of all children' , ( ) => {
100
- const root = Construct . createRoot ( ) ;
100
+ const root = new Root ( ) ;
101
101
const child = new Construct ( root , 'Child1' ) ;
102
102
new Construct ( root , 'Child2' ) ;
103
103
expect ( child . node . children . length ) . toBe ( 0 ) ;
104
104
expect ( root . node . children . length ) . toBe ( 2 ) ;
105
105
} ) ;
106
106
107
107
test ( 'construct.findChild(name) can be used to retrieve a child from a parent' , ( ) => {
108
- const root = Construct . createRoot ( ) ;
109
- const child = new Construct ( root , 'Construct ' ) ;
108
+ const root = new Root ( ) ;
109
+ const child = new Construct ( root , 'Contruct ' ) ;
110
110
expect ( root . node . tryFindChild ( child . node . id ) ) . toBe ( child ) ;
111
111
expect ( root . node . tryFindChild ( 'NotFound' ) ) . toBeUndefined ( ) ;
112
112
} ) ;
113
113
114
114
test ( 'construct.getChild(name) can be used to retrieve a child from a parent' , ( ) => {
115
- const root = Construct . createRoot ( ) ;
116
- const child = new Construct ( root , 'Construct ' ) ;
115
+ const root = new Root ( ) ;
116
+ const child = new Construct ( root , 'Contruct ' ) ;
117
117
expect ( root . node . findChild ( child . node . id ) ) . toBe ( child ) ;
118
118
expect ( ( ) => root . node . findChild ( 'NotFound' ) ) . toThrow ( / N o c h i l d w i t h i d : ' N o t F o u n d ' / ) ;
119
119
} ) ;
@@ -158,7 +158,7 @@ test('construct.getAllContext can be used to read the full context of a root nod
158
158
} ;
159
159
160
160
// WHEN
161
- const t = Construct . createRoot ( ) ;
161
+ const t = new Root ( ) ;
162
162
for ( const [ k , v ] of Object . entries ( context ) ) {
163
163
t . node . setContext ( k , v ) ;
164
164
}
@@ -196,7 +196,7 @@ test('construct.tryGetContext(key) can be used to read a value from context defi
196
196
197
197
// tslint:disable-next-line:max-line-length
198
198
test ( 'construct.setContext(k,v) sets context at some level and construct.tryGetContext(key) will return the lowermost value defined in the stack' , ( ) => {
199
- const root = Construct . createRoot ( ) ;
199
+ const root = new Root ( ) ;
200
200
const highChild = new Construct ( root , 'highChild' ) ;
201
201
highChild . node . setContext ( 'c1' , 'root' ) ;
202
202
highChild . node . setContext ( 'c2' , 'root' ) ;
@@ -229,7 +229,7 @@ test('construct.setContext(k,v) sets context at some level and construct.tryGetC
229
229
} ) ;
230
230
231
231
test ( 'construct.setContext(key, value) can only be called before adding any children' , ( ) => {
232
- const root = Construct . createRoot ( ) ;
232
+ const root = new Root ( ) ;
233
233
new Construct ( root , 'child1' ) ;
234
234
expect ( ( ) => root . node . setContext ( 'k' , 'v' ) ) . toThrow ( / C a n n o t s e t c o n t e x t a f t e r c h i l d r e n h a v e b e e n a d d e d : c h i l d 1 / ) ;
235
235
} ) ;
@@ -265,7 +265,7 @@ test('construct can not be created with the name of a sibling', () => {
265
265
} ) ;
266
266
267
267
test ( 'addMetadata(type, data) can be used to attach metadata to constructs' , ( ) => {
268
- const root = Construct . createRoot ( ) ;
268
+ const root = new Root ( ) ;
269
269
const con = new Construct ( root , 'MyConstruct' ) ;
270
270
expect ( con . node . metadata ) . toEqual ( [ ] ) ;
271
271
@@ -285,7 +285,7 @@ test('addMetadata(type, data) can be used to attach metadata to constructs', ()
285
285
} ) ;
286
286
287
287
test ( 'addMetadata() respects the "stackTrace" option' , ( ) => {
288
- const root = Construct . createRoot ( ) ;
288
+ const root = new Root ( ) ;
289
289
const con = new Construct ( root , 'Foo' ) ;
290
290
291
291
con . node . addMetadata ( 'foo' , 'bar1' , { stackTrace : true } ) ;
@@ -297,7 +297,7 @@ test('addMetadata() respects the "stackTrace" option', () => {
297
297
} ) ;
298
298
299
299
test ( 'addMetadata(type, undefined/null) is ignored' , ( ) => {
300
- const root = Construct . createRoot ( ) ;
300
+ const root = new Root ( ) ;
301
301
const con = new Construct ( root , 'Foo' ) ;
302
302
const node = con . node ;
303
303
node . addMetadata ( 'Null' , null ) ;
@@ -316,7 +316,7 @@ test('addMetadata(type, undefined/null) is ignored', () => {
316
316
} ) ;
317
317
318
318
test ( 'multiple children of the same type, with explicit names are welcome' , ( ) => {
319
- const root = Construct . createRoot ( ) ;
319
+ const root = new Root ( ) ;
320
320
new MyBeautifulConstruct ( root , 'mbc1' ) ;
321
321
new MyBeautifulConstruct ( root , 'mbc2' ) ;
322
322
new MyBeautifulConstruct ( root , 'mbc3' ) ;
@@ -392,15 +392,15 @@ test('node.addValidation() can be implemented to perform validation, node.valida
392
392
393
393
test ( 'node.validate() returns an empty array if the construct does not implement IValidation' , ( ) => {
394
394
// GIVEN
395
- const root = Construct . createRoot ( ) ;
395
+ const root = new Root ( ) ;
396
396
397
397
// THEN
398
398
expect ( root . node . validate ( ) ) . toStrictEqual ( [ ] ) ;
399
399
} ) ;
400
400
401
401
test ( 'node.addValidation() can be used to add a validation function to a construct' , ( ) => {
402
402
// GIVEN
403
- const construct = Construct . createRoot ( ) ;
403
+ const construct = new Root ( ) ;
404
404
construct . node . addValidation ( { validate : ( ) => [ 'error1' , 'error2' ] } ) ;
405
405
construct . node . addValidation ( { validate : ( ) => [ 'error3' ] } ) ;
406
406
@@ -409,7 +409,7 @@ test('node.addValidation() can be used to add a validation function to a constru
409
409
410
410
test ( 'construct.lock() protects against adding children anywhere under this construct (direct or indirect)' , ( ) => {
411
411
412
- const root = Construct . createRoot ( ) ;
412
+ const root = new Root ( ) ;
413
413
414
414
const c0a = new Construct ( root , 'c0a' ) ;
415
415
const c0b = new Construct ( root , 'c0b' ) ;
@@ -461,38 +461,38 @@ test('"root" returns the root construct', () => {
461
461
462
462
describe ( 'defaultChild' , ( ) => {
463
463
test ( 'returns the child with id "Resource"' , ( ) => {
464
- const root = Construct . createRoot ( ) ;
464
+ const root = new Root ( ) ;
465
465
new Construct ( root , 'child1' ) ;
466
466
const defaultChild = new Construct ( root , 'Resource' ) ;
467
467
new Construct ( root , 'child2' ) ;
468
468
469
469
expect ( root . node . defaultChild ) . toBe ( defaultChild ) ;
470
470
} ) ;
471
471
test ( 'returns the child with id "Default"' , ( ) => {
472
- const root = Construct . createRoot ( ) ;
472
+ const root = new Root ( ) ;
473
473
new Construct ( root , 'child1' ) ;
474
474
const defaultChild = new Construct ( root , 'Default' ) ;
475
475
new Construct ( root , 'child2' ) ;
476
476
477
477
expect ( root . node . defaultChild ) . toBe ( defaultChild ) ;
478
478
} ) ;
479
479
test ( 'can override defaultChild' , ( ) => {
480
- const root = Construct . createRoot ( ) ;
480
+ const root = new Root ( ) ;
481
481
new Construct ( root , 'Resource' ) ;
482
482
const defaultChild = new Construct ( root , 'OtherResource' ) ;
483
483
root . node . defaultChild = defaultChild ;
484
484
485
485
expect ( root . node . defaultChild ) . toBe ( defaultChild ) ;
486
486
} ) ;
487
487
test ( 'returns "undefined" if there is no default' , ( ) => {
488
- const root = Construct . createRoot ( ) ;
488
+ const root = new Root ( ) ;
489
489
new Construct ( root , 'child1' ) ;
490
490
new Construct ( root , 'child2' ) ;
491
491
492
492
expect ( root . node . defaultChild ) . toBeUndefined ( ) ;
493
493
} ) ;
494
494
test ( 'fails if there are both "Resource" and "Default"' , ( ) => {
495
- const root = Construct . createRoot ( ) ;
495
+ const root = new Root ( ) ;
496
496
new Construct ( root , 'child1' ) ;
497
497
new Construct ( root , 'Default' ) ;
498
498
new Construct ( root , 'child2' ) ;
@@ -507,7 +507,7 @@ describe('dependencies', () => {
507
507
508
508
test ( 'addDependency() defines a dependency between two scopes' , ( ) => {
509
509
// GIVEN
510
- const root = Construct . createRoot ( ) ;
510
+ const root = new Root ( ) ;
511
511
const consumer = new Construct ( root , 'consumer' ) ;
512
512
const producer1 = new Construct ( root , 'producer1' ) ;
513
513
const producer2 = new Construct ( root , 'producer2' ) ;
@@ -522,7 +522,7 @@ describe('dependencies', () => {
522
522
523
523
test ( 'are deduplicated' , ( ) => {
524
524
// GIVEN
525
- const root = Construct . createRoot ( ) ;
525
+ const root = new Root ( ) ;
526
526
const consumer = new Construct ( root , 'consumer' ) ;
527
527
const producer = new Construct ( root , 'producer' ) ;
528
528
@@ -539,7 +539,7 @@ describe('dependencies', () => {
539
539
540
540
test ( 'DependencyGroup can represent a group of disjoined producers' , ( ) => {
541
541
// GIVEN
542
- const root = Construct . createRoot ( ) ;
542
+ const root = new Root ( ) ;
543
543
const group = new DependencyGroup ( new Construct ( root , 'producer1' ) , new Construct ( root , 'producer2' ) ) ;
544
544
const consumer = new Construct ( root , 'consumer' ) ;
545
545
@@ -553,7 +553,7 @@ describe('dependencies', () => {
553
553
554
554
test ( 'Dependable.implement() can be used to implement IDependable on any object' , ( ) => {
555
555
// GIVEN
556
- const root = Construct . createRoot ( ) ;
556
+ const root = new Root ( ) ;
557
557
const producer = new Construct ( root , 'producer' ) ;
558
558
const consumer = new Construct ( root , 'consumer' ) ;
559
559
@@ -575,7 +575,7 @@ describe('dependencies', () => {
575
575
576
576
test ( 'dependencyRoots are only resolved when node dependencies are evaluated' , ( ) => {
577
577
// GIVEN
578
- const root = Construct . createRoot ( ) ;
578
+ const root = new Root ( ) ;
579
579
const c1 = new Construct ( root , 'c1' ) ;
580
580
const c2 = new Construct ( root , 'c2' ) ;
581
581
const c3 = new Construct ( root , 'c3' ) ;
@@ -594,7 +594,7 @@ describe('dependencies', () => {
594
594
595
595
test ( 'DependencyGroup can also include other IDependables' , ( ) => {
596
596
// GIVEN
597
- const root = Construct . createRoot ( ) ;
597
+ const root = new Root ( ) ;
598
598
const c1 = new Construct ( root , 'c1' ) ;
599
599
600
600
// WHEN
@@ -614,7 +614,7 @@ describe('dependencies', () => {
614
614
615
615
test ( 'tryRemoveChild()' , ( ) => {
616
616
// GIVEN
617
- const root = Construct . createRoot ( ) ;
617
+ const root = new Root ( ) ;
618
618
new Construct ( root , 'child1' ) ;
619
619
new Construct ( root , 'child2' ) ;
620
620
@@ -629,7 +629,7 @@ test('tryRemoveChild()', () => {
629
629
630
630
test ( 'toString()' , ( ) => {
631
631
// GIVEN
632
- const root = Construct . createRoot ( ) ;
632
+ const root = new Root ( ) ;
633
633
const child = new Construct ( root , 'child' ) ;
634
634
const grand = new Construct ( child , 'grand' ) ;
635
635
@@ -641,7 +641,7 @@ test('toString()', () => {
641
641
642
642
test ( 'Construct.isConstruct returns true for constructs' , ( ) => {
643
643
// GIVEN
644
- const root = Construct . createRoot ( ) ;
644
+ const root = new Root ( ) ;
645
645
class Subclass extends Construct { } ;
646
646
const subclass = new Subclass ( root , 'subclass' ) ;
647
647
const someRandomObject = { } ;
@@ -659,7 +659,7 @@ test('Construct.isConstruct returns true for constructs', () => {
659
659
} ) ;
660
660
661
661
function createTree ( context ?: any ) {
662
- const root = Construct . createRoot ( ) ;
662
+ const root = new Root ( ) ;
663
663
const highChild = new Construct ( root , 'HighChild' ) ;
664
664
if ( context ) {
665
665
Object . keys ( context ) . forEach ( key => highChild . node . setContext ( key , context [ key ] ) ) ;
0 commit comments