-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathtest.tree.ts
61 lines (54 loc) · 1.46 KB
/
test.tree.ts
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
import fs = require('fs');
import { Test } from 'nodeunit';
import path = require('path');
import { App, Construct, Resource, Stack } from '../../lib/index';
export = {
'annotations are generated as expected'(test: Test) {
const app = new App();
const stack = new Stack(app, 'mystack');
new Construct(stack, 'group1');
const group2 = new Construct(stack, 'group2');
new MyResource(group2, 'resource3');
const assembly = app.synth();
const annotationsFile = assembly.getMetadata('Tree').file;
test.deepEqual(readJson(assembly.directory, annotationsFile), {
version: 'tree-0.1',
tree: {
id: 'App',
path: '',
children: [
{
id: 'Tree',
path: 'Tree'
},
{
id: 'mystack',
path: 'mystack',
children: [
{
id: 'group1',
path: 'mystack/group1'
},
{
id: 'group2',
path: 'mystack/group2',
children: [
{ id: 'resource3', path: 'mystack/group2/resource3' }
]
}
]
},
]
}
});
test.done();
},
};
class MyResource extends Resource {
constructor(scope: Construct, id: string) {
super(scope, id);
}
}
function readJson(outdir: string, file: string) {
return JSON.parse(fs.readFileSync(path.join(outdir, file), 'utf-8'));
}