Skip to content

Commit 8f19e30

Browse files
Wr/remove mock registry (#521)
* chore: restore point - attempting global find/replace * chore: working through tests, 34 failing * test: the UTs are passing :) * chore: adding types for SDR * refactor: remove mock/registry dir * refactor: test constants easier to understand * chore: restore tests * chore: remove mock registry from new tests on main * chore: cleanup, fix all test constant names * chore: fix deps
1 parent f2a2262 commit 8f19e30

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+868
-1390
lines changed

contributing/metadata.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,9 @@ Only `source:push` and `source:pull` support source tracking, so the target type
141141

142142
## Unit Testing
143143

144-
SDR Unit tests are abstract (mockRegistry tries to represent possible patterns). If your type uses a combination of properties that don't match an existing type in the registry, there's a chance the behavior isn't covered.
145-
146144
Reach out to the CLI team for help with unit tests.
147145

148-
[metadataResolverRealRegistry.ts](../test/resolve/metadataResolverRealRegistry.test.ts) is an example of unit testing one behavior (resolving from source files) of a real metadata type.
146+
[metadataResolverRegistry.ts](../test/resolve/metadataResolverRegistry.test.ts) is an example of unit testing one behavior (resolving from source files) of a real metadata type.
149147

150148
## Integration Testing
151149

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"xmldom-sfdx-encoding": "^0.1.29"
3737
},
3838
"devDependencies": {
39-
"@salesforce/dev-config": "^2.1.2",
39+
"@salesforce/dev-config": "^2.1.3",
4040
"@salesforce/dev-scripts": "^1.0.2",
4141
"@salesforce/prettier-config": "^0.0.2",
4242
"@salesforce/ts-sinon": "^1.1.2",

src/collections/componentSet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import {
1919
ComponentLike,
2020
ManifestResolver,
2121
MetadataComponent,
22+
MetadataMember,
2223
MetadataResolver,
2324
SourceComponent,
2425
TreeContainer,
2526
} from '../resolve';
2627
import { MetadataType, RegistryAccess } from '../registry';
27-
import { MetadataMember } from '../resolve/types';
2828
import {
2929
DestructiveChangesType,
3030
FromManifestOptions,

src/resolve/metadataResolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import { basename, dirname, join, sep } from 'path';
88
import { Lifecycle } from '@salesforce/core';
99
import { TypeInferenceError } from '../errors';
1010
import { extName, parentName, parseMetadataXml } from '../utils';
11-
import { RegistryAccess } from '../registry/registryAccess';
11+
import { MetadataType, RegistryAccess } from '../registry';
1212
import { ComponentSet } from '../collections';
13-
import { MetadataType } from '../registry';
1413
import { META_XML_SUFFIX } from '../common';
1514
import { SourceAdapterFactory } from './adapters/sourceAdapterFactory';
1615
import { ForceIgnore } from './forceIgnore';
1716
import { SourceComponent } from './sourceComponent';
1817
import { NodeFSTreeContainer, TreeContainer } from './treeContainers';
18+
1919
/**
2020
* Resolver for metadata type and component objects.
2121
*

test/client/auraDefinitionMocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
import { QueryResult } from '../../src/client/types';
8+
import { QueryResult } from '../../src';
99

1010
export const auraComponent: QueryResult = {
1111
size: 8,

test/client/diagnosticUtil.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
import { join } from 'path';
88
import { expect } from 'chai';
99
import { DiagnosticUtil } from '../../src/client/diagnosticUtil';
10-
import { SourceComponent } from '../../src/resolve/sourceComponent';
11-
import { DeployMessage } from '../../src/client/types';
12-
import { registry } from '../../src';
10+
import { DeployMessage, registry, SourceComponent } from '../../src';
1311

1412
type MockDeployMessage = {
1513
problem?: string;

test/client/lightningComponentMocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
import { QueryResult } from '../../src/client/types';
8+
import { QueryResult } from '../../src';
99

1010
export const lwcComponentMock: QueryResult = {
1111
size: 4,

test/client/metadataApiDeploy.test.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,31 @@ import { assert, expect } from 'chai';
1010
import { AnyJson, getString } from '@salesforce/ts-types';
1111
import { PollingClient, StatusResult } from '@salesforce/core';
1212
import { Duration } from '@salesforce/kit';
13-
import { ComponentSet, registry, SourceComponent, DeployResult, MetadataApiDeploy } from '../../src';
14-
import { ComponentStatus, DeployMessage, FileResponse, MetadataApiDeployStatus } from '../../src/client/types';
13+
import {
14+
ComponentSet,
15+
ComponentStatus,
16+
DeployMessage,
17+
DeployResult,
18+
FileResponse,
19+
MetadataApiDeploy,
20+
MetadataApiDeployStatus,
21+
registry,
22+
SourceComponent,
23+
} from '../../src';
1524
import {
1625
MOCK_ASYNC_RESULT,
1726
MOCK_RECENTLY_VALIDATED_ID_REST,
1827
MOCK_RECENTLY_VALIDATED_ID_SOAP,
1928
stubMetadataDeploy,
2029
} from '../mock/client/transferOperations';
21-
import { mockRegistry, matchingContentFile } from '../mock/registry';
30+
import { matchingContentFile } from '../mock';
2231
import { META_XML_SUFFIX } from '../../src/common';
2332
import {
2433
DECOMPOSED_CHILD_COMPONENT_1,
2534
DECOMPOSED_CHILD_COMPONENT_2,
2635
DECOMPOSED_COMPONENT,
27-
} from '../mock/registry/type-constants/decomposedConstants';
28-
import { COMPONENT } from '../mock/registry/type-constants/matchingContentFileConstants';
36+
} from '../mock/type-constants/customObjectConstant';
37+
import { COMPONENT } from '../mock/type-constants/apexClassConstant';
2938
import { MissingJobIdError } from '../../src/errors';
3039

3140
const env = createSandbox();
@@ -95,7 +104,7 @@ describe('MetadataApiDeploy', () => {
95104

96105
it('should return an AsyncResult', async () => {
97106
const component = matchingContentFile.COMPONENT;
98-
const deployedComponents = new ComponentSet([component], mockRegistry);
107+
const deployedComponents = new ComponentSet([component]);
99108
const { operation } = await stubMetadataDeploy(env, {
100109
components: deployedComponents,
101110
});
@@ -107,7 +116,7 @@ describe('MetadataApiDeploy', () => {
107116

108117
it('should set the deploy ID', async () => {
109118
const component = matchingContentFile.COMPONENT;
110-
const deployedComponents = new ComponentSet([component], mockRegistry);
119+
const deployedComponents = new ComponentSet([component]);
111120
const { operation, response } = await stubMetadataDeploy(env, {
112121
components: deployedComponents,
113122
});
@@ -121,7 +130,7 @@ describe('MetadataApiDeploy', () => {
121130
describe('pollStatus', () => {
122131
it('should construct a result object with deployed components', async () => {
123132
const component = matchingContentFile.COMPONENT;
124-
const deployedComponents = new ComponentSet([component], mockRegistry);
133+
const deployedComponents = new ComponentSet([component]);
125134
const { operation, response } = await stubMetadataDeploy(env, {
126135
components: deployedComponents,
127136
});
@@ -145,7 +154,7 @@ describe('MetadataApiDeploy', () => {
145154

146155
it('should override timeout and frequency by number', async () => {
147156
const component = matchingContentFile.COMPONENT;
148-
const deployedComponents = new ComponentSet([component], mockRegistry);
157+
const deployedComponents = new ComponentSet([component]);
149158
const { operation, pollingClientSpy } = await stubMetadataDeploy(env, {
150159
components: deployedComponents,
151160
});
@@ -161,8 +170,7 @@ describe('MetadataApiDeploy', () => {
161170
});
162171

163172
it('should override polling client options', async () => {
164-
const component = matchingContentFile.COMPONENT;
165-
const deployedComponents = new ComponentSet([component], mockRegistry);
173+
const deployedComponents = new ComponentSet([matchingContentFile.COMPONENT]);
166174
const { operation, pollingClientSpy } = await stubMetadataDeploy(env, {
167175
components: deployedComponents,
168176
});

test/client/metadataApiRetrieve.test.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
FileResponse,
1818
MetadataApiRetrieve,
1919
MetadataApiRetrieveStatus,
20+
registry,
2021
RequestStatus,
2122
RetrieveResult,
2223
SourceComponent,
@@ -25,9 +26,9 @@ import {
2526
import { MetadataApiRetrieveError, MissingJobIdError } from '../../src/errors';
2627
import { nls } from '../../src/i18n';
2728
import { MOCK_ASYNC_RESULT, MOCK_DEFAULT_OUTPUT, stubMetadataRetrieve } from '../mock/client/transferOperations';
28-
import { mockRegistry, mockRegistryData, xmlInFolder } from '../mock/registry';
29-
import { COMPONENT } from '../mock/registry/type-constants/matchingContentFileConstants';
30-
import { DECOMPOSED_COMPONENT } from '../mock/registry/type-constants/decomposedConstants';
29+
import { xmlInFolder } from '../mock';
30+
import { COMPONENT } from '../mock/type-constants/apexClassConstant';
31+
import { DECOMPOSED_COMPONENT } from '../mock/type-constants/customObjectConstant';
3132

3233
const env = createSandbox();
3334

@@ -37,7 +38,7 @@ describe('MetadataApiRetrieve', () => {
3738
describe('Lifecycle', () => {
3839
describe('start', () => {
3940
it('should throw error if there are no components to retrieve', async () => {
40-
const toRetrieve = new ComponentSet([], mockRegistry);
41+
const toRetrieve = new ComponentSet([]);
4142
const { operation } = await stubMetadataRetrieve(env, {
4243
toRetrieve,
4344
merge: true,
@@ -53,7 +54,7 @@ describe('MetadataApiRetrieve', () => {
5354
});
5455

5556
it('should throw error if packageNames list is empty', async () => {
56-
const toRetrieve = new ComponentSet([], mockRegistry);
57+
const toRetrieve = new ComponentSet([]);
5758
const { operation } = await stubMetadataRetrieve(env, {
5859
toRetrieve,
5960
merge: true,
@@ -70,7 +71,7 @@ describe('MetadataApiRetrieve', () => {
7071
});
7172

7273
it('should call retrieve for unpackaged data', async () => {
73-
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
74+
const toRetrieve = new ComponentSet([COMPONENT]);
7475
const options = {
7576
toRetrieve,
7677
merge: true,
@@ -87,7 +88,7 @@ describe('MetadataApiRetrieve', () => {
8788
});
8889

8990
it('should call retrieve for a package as string[]', async () => {
90-
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
91+
const toRetrieve = new ComponentSet([COMPONENT]);
9192
const options = {
9293
toRetrieve,
9394
packageOptions: ['MyPackage'],
@@ -106,7 +107,7 @@ describe('MetadataApiRetrieve', () => {
106107
});
107108

108109
it('should call retrieve for a package as PackageOptions[] with name only', async () => {
109-
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
110+
const toRetrieve = new ComponentSet([COMPONENT]);
110111
const options = {
111112
toRetrieve,
112113
packageOptions: [{ name: 'MyPackage' }],
@@ -125,7 +126,7 @@ describe('MetadataApiRetrieve', () => {
125126
});
126127

127128
it('should call retrieve for a package as PackageOptions[] with name and outputDir', async () => {
128-
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
129+
const toRetrieve = new ComponentSet([COMPONENT]);
129130
const options = {
130131
toRetrieve,
131132
packageOptions: [{ name: 'MyPackage', outputDir: 'fake/output/dir' }],
@@ -144,7 +145,7 @@ describe('MetadataApiRetrieve', () => {
144145
});
145146

146147
it('should return an AsyncResult', async () => {
147-
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
148+
const toRetrieve = new ComponentSet([COMPONENT]);
148149
const options = {
149150
toRetrieve,
150151
packageNames: ['MyPackage'],
@@ -159,7 +160,7 @@ describe('MetadataApiRetrieve', () => {
159160
});
160161

161162
it('should set the retrieve ID', async () => {
162-
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
163+
const toRetrieve = new ComponentSet([COMPONENT]);
163164
const options = {
164165
toRetrieve,
165166
packageNames: ['MyPackage'],
@@ -178,7 +179,7 @@ describe('MetadataApiRetrieve', () => {
178179
const getPackageComponent = (packageName: string): SourceComponent => {
179180
const contentName = 'z.mcf';
180181
const metaName = `${contentName}-meta.xml`;
181-
const type = mockRegistryData.types.matchingcontentfile;
182+
const type = registry.types.apexclass;
182183
return new SourceComponent(
183184
{
184185
name: 'z',
@@ -197,7 +198,7 @@ describe('MetadataApiRetrieve', () => {
197198

198199
it('should retrieve zip and extract to directory', async () => {
199200
const component = COMPONENT;
200-
const toRetrieve = new ComponentSet([component], mockRegistry);
201+
const toRetrieve = new ComponentSet([component]);
201202
const { operation, convertStub } = await stubMetadataRetrieve(env, {
202203
toRetrieve,
203204
successes: toRetrieve,
@@ -220,8 +221,8 @@ describe('MetadataApiRetrieve', () => {
220221
const packageName = 'MyPackage';
221222
const pkgComponent = getPackageComponent(packageName);
222223
const fromSourceSpy = env.spy(ComponentSet, 'fromSource');
223-
const toRetrieve = new ComponentSet([component], mockRegistry);
224-
const successesCompSet = new ComponentSet([component, pkgComponent], mockRegistry);
224+
const toRetrieve = new ComponentSet([component]);
225+
const successesCompSet = new ComponentSet([component, pkgComponent]);
225226
const { operation, convertStub } = await stubMetadataRetrieve(env, {
226227
toRetrieve,
227228
packageOptions: [packageName],
@@ -254,8 +255,8 @@ describe('MetadataApiRetrieve', () => {
254255
const packageOutputDir = 'myPackageDir';
255256
const pkgComponent = getPackageComponent(packageName);
256257
const fromSourceSpy = env.spy(ComponentSet, 'fromSource');
257-
const toRetrieve = new ComponentSet([component], mockRegistry);
258-
const successesCompSet = new ComponentSet([component, pkgComponent], mockRegistry);
258+
const toRetrieve = new ComponentSet([component]);
259+
const successesCompSet = new ComponentSet([component, pkgComponent]);
259260
const { operation, convertStub } = await stubMetadataRetrieve(env, {
260261
toRetrieve,
261262
packageOptions: [{ name: packageName, outputDir: packageOutputDir }],
@@ -285,7 +286,7 @@ describe('MetadataApiRetrieve', () => {
285286
it('should save the temp directory if the environment variable is set', async () => {
286287
try {
287288
process.env.SFDX_MDAPI_TEMP_DIR = 'test';
288-
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
289+
const toRetrieve = new ComponentSet([COMPONENT]);
289290
const { operation, convertStub } = await stubMetadataRetrieve(env, {
290291
toRetrieve,
291292
merge: true,
@@ -303,7 +304,7 @@ describe('MetadataApiRetrieve', () => {
303304
});
304305

305306
it('should NOT save the temp directory if the environment variable is NOT set', async () => {
306-
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
307+
const toRetrieve = new ComponentSet([COMPONENT]);
307308
const { operation, convertStub } = await stubMetadataRetrieve(env, {
308309
toRetrieve,
309310
merge: true,
@@ -319,7 +320,7 @@ describe('MetadataApiRetrieve', () => {
319320

320321
it('should retrieve zip and merge with existing components', async () => {
321322
const component = COMPONENT;
322-
const toRetrieve = new ComponentSet([component], mockRegistry);
323+
const toRetrieve = new ComponentSet([component]);
323324
const { operation, convertStub } = await stubMetadataRetrieve(env, {
324325
toRetrieve,
325326
merge: true,
@@ -341,7 +342,7 @@ describe('MetadataApiRetrieve', () => {
341342
});
342343

343344
it('should construct a result object with retrieved components', async () => {
344-
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
345+
const toRetrieve = new ComponentSet([COMPONENT]);
345346
const { operation, response } = await stubMetadataRetrieve(env, {
346347
toRetrieve,
347348
merge: true,
@@ -356,7 +357,7 @@ describe('MetadataApiRetrieve', () => {
356357
});
357358

358359
it('should construct a result object with no components when components are forceIgnored', async () => {
359-
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
360+
const toRetrieve = new ComponentSet([COMPONENT]);
360361
toRetrieve.forceIgnoredPaths = new Set([COMPONENT.xml, COMPONENT.content]);
361362
const { operation } = await stubMetadataRetrieve(env, {
362363
toRetrieve,
@@ -371,7 +372,7 @@ describe('MetadataApiRetrieve', () => {
371372
});
372373

373374
it('should construct a result object with no components when no components are retrieved', async () => {
374-
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
375+
const toRetrieve = new ComponentSet([COMPONENT]);
375376
const { operation, response } = await stubMetadataRetrieve(env, {
376377
toRetrieve,
377378
merge: true,
@@ -384,7 +385,7 @@ describe('MetadataApiRetrieve', () => {
384385

385386
await operation.start();
386387
const result = await operation.pollStatus();
387-
const compSet = new ComponentSet(undefined, mockRegistry);
388+
const compSet = new ComponentSet(undefined);
388389
const expected = new RetrieveResult(response, compSet, toRetrieve);
389390

390391
expect(result).to.deep.equal(expected);
@@ -394,7 +395,7 @@ describe('MetadataApiRetrieve', () => {
394395

395396
describe('checkStatus', () => {
396397
it('should throw an error when attempting to call checkStatus without an id set', async () => {
397-
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
398+
const toRetrieve = new ComponentSet([COMPONENT]);
398399
const { operation } = await stubMetadataRetrieve(env, {
399400
toRetrieve,
400401
merge: true,
@@ -474,7 +475,7 @@ describe('MetadataApiRetrieve', () => {
474475
describe('cancel', () => {
475476
it('should immediately stop polling', async () => {
476477
const component = COMPONENT;
477-
const components = new ComponentSet([component], mockRegistry);
478+
const components = new ComponentSet([component]);
478479
const { operation, checkStatusStub } = await stubMetadataRetrieve(env, {
479480
toRetrieve: components,
480481
});
@@ -654,7 +655,7 @@ describe('MetadataApiRetrieve', () => {
654655
const component = new SourceComponent(
655656
{
656657
name: 'OnlyContent',
657-
type: mockRegistryData.types.matchingcontentfile,
658+
type: registry.types.apexclass,
658659
content: COMPONENT.content,
659660
},
660661
COMPONENT.tree

0 commit comments

Comments
 (0)