1 |
|
2 |
|
3 | const tymly = require('./../lib')
|
4 | const path = require('path')
|
5 | const chai = require('chai')
|
6 | chai.use(require('chai-string'))
|
7 | const expect = chai.expect
|
8 |
|
9 | describe('TymlyRef first-stage resolution', () => {
|
10 | const probePluginPath = path.resolve(__dirname, 'fixtures/plugins/with-ref-plugin')
|
11 | const bpDir = path.resolve(__dirname, 'fixtures/blueprints')
|
12 |
|
13 | const inner = {
|
14 | blueprintName: 'withRef',
|
15 | blueprintVersion: '1.0',
|
16 | namespace: 'refResolution',
|
17 | id: 'inner',
|
18 | name: 'inner'
|
19 | }
|
20 | const between = {
|
21 | blueprintName: 'withRef',
|
22 | blueprintVersion: '1.0',
|
23 | namespace: 'refResolution',
|
24 | id: 'between',
|
25 | name: 'middle',
|
26 | description: 'sits in the middle',
|
27 | contents: inner
|
28 | }
|
29 |
|
30 | const goodTests = [
|
31 | [
|
32 | 'good reference',
|
33 | 'with-good-ref-blueprint',
|
34 | inner
|
35 | ],
|
36 | [
|
37 | 'good reference in an array',
|
38 | 'with-good-ref-in-array-blueprint',
|
39 | [
|
40 | 'some stuff before',
|
41 | inner,
|
42 | 'some stuff afterwards'
|
43 | ]
|
44 | ],
|
45 | [
|
46 | 'reference the same file twice',
|
47 | 'with-two-good-refs-blueprint',
|
48 | {
|
49 | once: inner,
|
50 | again: inner
|
51 | }
|
52 | ],
|
53 | [
|
54 | 'nested ref',
|
55 | 'with-refs-in-refs-blueprint',
|
56 | between
|
57 | ],
|
58 | [
|
59 | 'multiple nested ref',
|
60 | 'with-multiple-refs-in-refs-blueprint',
|
61 | [
|
62 | between,
|
63 | {
|
64 | blueprintName: 'withRef',
|
65 | blueprintVersion: '1.0',
|
66 | namespace: 'refResolution',
|
67 | id: 'shim',
|
68 | name: 'shim',
|
69 | contents: between
|
70 | }
|
71 | ]
|
72 | ],
|
73 | [
|
74 | 'wildcard namespace reference',
|
75 | 'with-wildcard-namespace-ref-blueprint',
|
76 | [inner]
|
77 | ],
|
78 | [
|
79 | 'wildcard name reference',
|
80 | 'with-wildcard-name-ref-blueprint',
|
81 | [inner]
|
82 | ],
|
83 | [
|
84 | 'reference with JSONPath selection',
|
85 | 'with-good-ref-and-jsonpath-blueprint',
|
86 | {
|
87 | name: 'the subsection'
|
88 | }
|
89 | ],
|
90 | [
|
91 | 'reference with JSONPath Array selection',
|
92 | 'with-good-ref-and-jsonpath-array-blueprint',
|
93 | [
|
94 | {
|
95 | name: 'the before subsection'
|
96 | },
|
97 | {
|
98 | name: 'the subsection'
|
99 | },
|
100 | {
|
101 | name: 'the next subsection'
|
102 | }
|
103 | ]
|
104 | ],
|
105 | [
|
106 | 'reference with JSONPath Array subselect',
|
107 | 'with-good-ref-and-jsonpath-array-subselect-blueprint',
|
108 | [
|
109 | {
|
110 | name: 'the subsection'
|
111 | },
|
112 | {
|
113 | name: 'the next subsection'
|
114 | }
|
115 | ]
|
116 | ]
|
117 | ]
|
118 |
|
119 | describe('Good references', () => {
|
120 | for (const [label, bp, contents] of goodTests) {
|
121 | it(label, async () => {
|
122 | const tymlyServices = await tymly.boot({
|
123 | pluginPaths: [probePluginPath],
|
124 | blueprintPaths: [path.resolve(bpDir, bp)]
|
125 | })
|
126 |
|
127 | const files = tymlyServices.probe.files
|
128 |
|
129 | expect(files.refResolution_outer.contents).to.eql(contents)
|
130 | })
|
131 | }
|
132 | })
|
133 |
|
134 | const badTests = [
|
135 | [
|
136 | 'bad reference name',
|
137 | 'with-bad-ref-name-blueprint',
|
138 | 'Error: Could not resolve files:refResolution_inner in files:refResolution_outer'
|
139 | ],
|
140 | [
|
141 | 'circular reference',
|
142 | 'with-bad-circular-ref-blueprint',
|
143 | 'Error: Circular dependency in '
|
144 | ]
|
145 |
|
146 | ]
|
147 |
|
148 | describe('Bad references', () => {
|
149 | for (const [label, bp, error] of badTests) {
|
150 | it(label, async () => {
|
151 | try {
|
152 | await tymly.boot({
|
153 | blueprintPaths: [path.resolve(bpDir, bp)]
|
154 | })
|
155 | expect.fail('Tymly Ref should have failed')
|
156 | } catch (err) {
|
157 | expect(err.message).to.startWith(error)
|
158 | }
|
159 | })
|
160 | }
|
161 | })
|
162 | })
|