|
7 | 7 |
|
8 | 8 | import { expect } from 'chai';
|
9 | 9 | import { join } from 'path';
|
10 |
| -import { createSandbox } from 'sinon'; |
| 10 | +import { createSandbox, match } from 'sinon'; |
11 | 11 | import { Readable } from 'stream';
|
12 |
| -import { SourceComponent } from '../../src'; |
| 12 | +import { SourceComponent, VirtualTreeContainer } from '../../src'; |
13 | 13 | import { ComponentSet } from '../../src/collections';
|
14 |
| -import { XML_NS_KEY, XML_NS_URL } from '../../src/common'; |
| 14 | +import { |
| 15 | + DEFAULT_PACKAGE_ROOT_SFDX, |
| 16 | + META_XML_SUFFIX, |
| 17 | + XML_NS_KEY, |
| 18 | + XML_NS_URL, |
| 19 | +} from '../../src/common'; |
15 | 20 | import { WriterFormat } from '../../src/convert';
|
16 | 21 | import { ConvertContext } from '../../src/convert/convertContext';
|
17 | 22 | import { JsToXml } from '../../src/convert/streams';
|
18 |
| -import { matchingContentFile, mockRegistry, regina } from '../mock/registry'; |
| 23 | +import { matchingContentFile, mockRegistry, regina, nonDecomposed } from '../mock/registry'; |
19 | 24 |
|
20 | 25 | const env = createSandbox();
|
21 | 26 |
|
@@ -158,5 +163,141 @@ describe('Convert Transaction Constructs', () => {
|
158 | 163 | ]);
|
159 | 164 | });
|
160 | 165 | });
|
| 166 | + |
| 167 | + describe('NonDecomposition', () => { |
| 168 | + it('should return WriterFormats for claimed children', async () => { |
| 169 | + const component = nonDecomposed.COMPONENT; |
| 170 | + const context = new ConvertContext(); |
| 171 | + env.stub(VirtualTreeContainer.prototype, 'readDirectory').returns([]); |
| 172 | + const writeInfos = [ |
| 173 | + { |
| 174 | + output: component.xml, |
| 175 | + source: new JsToXml(nonDecomposed.XML_CONTENT), |
| 176 | + }, |
| 177 | + ]; |
| 178 | + context.nonDecomposition.setState((state) => { |
| 179 | + state.claimed = { |
| 180 | + [component.xml]: { |
| 181 | + parent: component, |
| 182 | + children: { |
| 183 | + [nonDecomposed.CHILD_1_NAME]: nonDecomposed.CHILD_1_XML, |
| 184 | + [nonDecomposed.CHILD_2_NAME]: nonDecomposed.CHILD_2_XML, |
| 185 | + [nonDecomposed.CHILD_3_NAME]: nonDecomposed.CHILD_3_XML, |
| 186 | + }, |
| 187 | + }, |
| 188 | + }; |
| 189 | + }); |
| 190 | + |
| 191 | + const result = await context.nonDecomposition.finalize(process.cwd()); |
| 192 | + |
| 193 | + expect(result).to.deep.equal([{ component, writeInfos }]); |
| 194 | + }); |
| 195 | + |
| 196 | + it('should return WriterFormats for unclaimed children', async () => { |
| 197 | + const component = nonDecomposed.COMPONENT; |
| 198 | + const context = new ConvertContext(); |
| 199 | + env.stub(VirtualTreeContainer.prototype, 'readDirectory').returns([]); |
| 200 | + const [baseName] = component.fullName.split('.'); |
| 201 | + const output = join( |
| 202 | + DEFAULT_PACKAGE_ROOT_SFDX, |
| 203 | + component.type.directoryName, |
| 204 | + `${baseName}.${component.type.suffix}${META_XML_SUFFIX}` |
| 205 | + ); |
| 206 | + const writeInfos = [{ output, source: new JsToXml(nonDecomposed.XML_CONTENT) }]; |
| 207 | + context.nonDecomposition.setState((state) => { |
| 208 | + state.unclaimed = { |
| 209 | + [component.xml]: { |
| 210 | + parent: component, |
| 211 | + children: { |
| 212 | + [nonDecomposed.CHILD_1_NAME]: nonDecomposed.CHILD_1_XML, |
| 213 | + [nonDecomposed.CHILD_2_NAME]: nonDecomposed.CHILD_2_XML, |
| 214 | + [nonDecomposed.CHILD_3_NAME]: nonDecomposed.CHILD_3_XML, |
| 215 | + }, |
| 216 | + }, |
| 217 | + }; |
| 218 | + }); |
| 219 | + |
| 220 | + const result = await context.nonDecomposition.finalize(process.cwd()); |
| 221 | + |
| 222 | + expect(result).to.deep.equal([{ component, writeInfos }]); |
| 223 | + }); |
| 224 | + |
| 225 | + it('should add unclaimed children to default parent component', async () => { |
| 226 | + const component = nonDecomposed.COMPONENT; |
| 227 | + const context = new ConvertContext(); |
| 228 | + env.stub(VirtualTreeContainer.prototype, 'readDirectory').returns([]); |
| 229 | + |
| 230 | + const writeInfos = [ |
| 231 | + { output: component.xml, source: new JsToXml(nonDecomposed.XML_CONTENT) }, |
| 232 | + ]; |
| 233 | + context.nonDecomposition.setState((state) => { |
| 234 | + state.claimed = { |
| 235 | + [component.xml]: { |
| 236 | + parent: component, |
| 237 | + children: { |
| 238 | + [nonDecomposed.CHILD_1_NAME]: nonDecomposed.CHILD_1_XML, |
| 239 | + [nonDecomposed.CHILD_2_NAME]: nonDecomposed.CHILD_2_XML, |
| 240 | + }, |
| 241 | + }, |
| 242 | + }; |
| 243 | + state.unclaimed = { |
| 244 | + [component.xml]: { |
| 245 | + parent: component, |
| 246 | + children: { |
| 247 | + [nonDecomposed.CHILD_3_NAME]: nonDecomposed.CHILD_3_XML, |
| 248 | + }, |
| 249 | + }, |
| 250 | + }; |
| 251 | + }); |
| 252 | + |
| 253 | + const result = await context.nonDecomposition.finalize(process.cwd()); |
| 254 | + |
| 255 | + expect(result).to.deep.equal([{ component, writeInfos }]); |
| 256 | + }); |
| 257 | + |
| 258 | + it('should find all unprocessed components so that unclaimed children can be claimed', async () => { |
| 259 | + const component = nonDecomposed.COMPONENT; |
| 260 | + const context = new ConvertContext(); |
| 261 | + const unprocessedComponent = nonDecomposed.COMPONENT2; |
| 262 | + |
| 263 | + env.stub(unprocessedComponent, 'parseXml').resolves(nonDecomposed.PARTIAL_XML_CONTENT); |
| 264 | + env.stub(unprocessedComponent, 'parseXmlSync').returns(nonDecomposed.PARTIAL_XML_CONTENT); |
| 265 | + env.stub(VirtualTreeContainer.prototype, 'readDirectory').returns(['my-app']); |
| 266 | + env |
| 267 | + .stub(VirtualTreeContainer.prototype, 'isDirectory') |
| 268 | + .withArgs(match('my-app')) |
| 269 | + .returns(true); |
| 270 | + env |
| 271 | + .stub(ComponentSet, 'fromSource') |
| 272 | + .withArgs({ fsPaths: [match('my-app')], include: match.any }) |
| 273 | + .returns(new ComponentSet([unprocessedComponent])); |
| 274 | + |
| 275 | + const writeInfos = [ |
| 276 | + { output: component.xml, source: new JsToXml(nonDecomposed.XML_CONTENT) }, |
| 277 | + ]; |
| 278 | + context.nonDecomposition.setState((state) => { |
| 279 | + state.claimed = { |
| 280 | + [component.xml]: { |
| 281 | + parent: component, |
| 282 | + children: { |
| 283 | + [nonDecomposed.CHILD_1_NAME]: nonDecomposed.CHILD_1_XML, |
| 284 | + [nonDecomposed.CHILD_2_NAME]: nonDecomposed.CHILD_2_XML, |
| 285 | + }, |
| 286 | + }, |
| 287 | + }; |
| 288 | + state.unclaimed = { |
| 289 | + [component.xml]: { |
| 290 | + parent: component, |
| 291 | + children: { |
| 292 | + [nonDecomposed.CHILD_3_NAME]: nonDecomposed.CHILD_3_XML, |
| 293 | + }, |
| 294 | + }, |
| 295 | + }; |
| 296 | + }); |
| 297 | + |
| 298 | + const result = await context.nonDecomposition.finalize(process.cwd()); |
| 299 | + expect(result).to.deep.equal([{ component, writeInfos }]); |
| 300 | + }); |
| 301 | + }); |
161 | 302 | });
|
162 | 303 | });
|
0 commit comments