@salesforce/core 5.3.16 → 5.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/testSetup.js +29 -18
- package/package.json +1 -1
package/lib/testSetup.js
CHANGED
|
@@ -18,7 +18,6 @@ const events_1 = require("events");
|
|
|
18
18
|
const os_1 = require("os");
|
|
19
19
|
const path_1 = require("path");
|
|
20
20
|
const util = require("util");
|
|
21
|
-
const ts_sinon_1 = require("@salesforce/ts-sinon");
|
|
22
21
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
23
22
|
const configAggregator_1 = require("./config/configAggregator");
|
|
24
23
|
const configFile_1 = require("./config/configFile");
|
|
@@ -186,8 +185,9 @@ class TestContext {
|
|
|
186
185
|
async stubAuths(...orgs) {
|
|
187
186
|
const entries = await Promise.all(orgs.map(async (org) => [org.username, await org.getConfig()]));
|
|
188
187
|
const orgMap = new Map(entries);
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
// @ts-expect-error because private method
|
|
189
|
+
this.SANDBOX.stub(stateAggregator_1.OrgAccessor.prototype, 'getAllFiles').resolves([...orgMap.keys()].map((o) => `${o}.json`));
|
|
190
|
+
this.SANDBOX.stub(stateAggregator_1.OrgAccessor.prototype, 'hasFile').callsFake((username) => Promise.resolve(orgMap.has(username)));
|
|
191
191
|
const retrieveContents = async function () {
|
|
192
192
|
const username = (0, path_1.basename)(this.path.replace('.json', ''));
|
|
193
193
|
return Promise.resolve(orgMap.get(username) ?? {});
|
|
@@ -224,7 +224,12 @@ class TestContext {
|
|
|
224
224
|
? [adminOrg.orgId, { usernames: orgs.filter((org) => org.username !== adminUsername) }]
|
|
225
225
|
: [undefined, undefined];
|
|
226
226
|
}));
|
|
227
|
-
|
|
227
|
+
this.SANDBOX.stub(org_1.User.prototype, 'retrieve').callsFake((username) => {
|
|
228
|
+
const user = mockUsers.find((org) => org.username === username);
|
|
229
|
+
if (!user)
|
|
230
|
+
throw new sfError_1.SfError('User not found', 'UserNotFoundError');
|
|
231
|
+
return Promise.resolve(user);
|
|
232
|
+
});
|
|
228
233
|
const retrieveContents = async function () {
|
|
229
234
|
const orgId = (0, path_1.basename)(this.path.replace('.json', ''));
|
|
230
235
|
return Promise.resolve(userOrgsMap.get(orgId) ?? {});
|
|
@@ -237,7 +242,8 @@ class TestContext {
|
|
|
237
242
|
async stubSandboxes(...sandboxes) {
|
|
238
243
|
const entries = (await Promise.all(sandboxes.map(async (sandbox) => [sandbox.username, await sandbox.getConfig()])));
|
|
239
244
|
const sandboxMap = new Map(entries);
|
|
240
|
-
|
|
245
|
+
// @ts-expect-error because private method
|
|
246
|
+
this.SANDBOX.stub(sandboxAccessor_1.SandboxAccessor.prototype, 'getAllFiles').resolves([...sandboxMap.keys()].map((o) => `${o}.sandbox.json`));
|
|
241
247
|
const retrieveContents = async function () {
|
|
242
248
|
const username = (0, path_1.basename)(this.path.replace('.sandbox.json', ''));
|
|
243
249
|
return Promise.resolve(sandboxMap.get(username) ?? {});
|
|
@@ -391,12 +397,13 @@ const stubContext = (testContext) => {
|
|
|
391
397
|
global_1.Global.SFDX_INTEROPERABILITY = false;
|
|
392
398
|
const stubs = {};
|
|
393
399
|
// Most core files create a child logger so stub this to return our test logger.
|
|
394
|
-
|
|
395
|
-
|
|
400
|
+
testContext.SANDBOX.stub(logger_1.Logger, 'child').resolves(testContext.TEST_LOGGER);
|
|
401
|
+
testContext.SANDBOX.stub(logger_1.Logger, 'childFromRoot').returns(testContext.TEST_LOGGER);
|
|
396
402
|
testContext.inProject(true);
|
|
397
403
|
testContext.SANDBOXES.CONFIG.stub(configFile_1.ConfigFile, 'resolveRootFolder').callsFake((isGlobal) => testContext.rootPathRetriever(isGlobal, testContext.id));
|
|
398
404
|
testContext.SANDBOXES.CONFIG.stub(configFile_1.ConfigFile, 'resolveRootFolderSync').callsFake((isGlobal) => testContext.rootPathRetrieverSync(isGlobal, testContext.id));
|
|
399
|
-
|
|
405
|
+
// @ts-expect-error using private method
|
|
406
|
+
testContext.SANDBOXES.PROJECT.stub(sfProject_1.SfProjectJson.prototype, 'doesPackageExist').callsFake(() => true);
|
|
400
407
|
const initStubForRead = (configFile) => {
|
|
401
408
|
const stub = testContext.configStubs[configFile.constructor.name] ?? {};
|
|
402
409
|
// init calls read calls getPath which sets the path on the config file the first time.
|
|
@@ -454,33 +461,37 @@ const stubContext = (testContext) => {
|
|
|
454
461
|
writeSync.call(this);
|
|
455
462
|
}
|
|
456
463
|
};
|
|
457
|
-
stubs.configWriteSync =
|
|
458
|
-
stubs.configWrite =
|
|
459
|
-
|
|
464
|
+
stubs.configWriteSync = testContext.SANDBOXES.CONFIG.stub(configFile_1.ConfigFile.prototype, 'writeSync').callsFake(writeSync);
|
|
465
|
+
stubs.configWrite = testContext.SANDBOXES.CONFIG.stub(configFile_1.ConfigFile.prototype, 'write').callsFake(write);
|
|
466
|
+
// @ts-expect-error: getKeyChain is private
|
|
467
|
+
testContext.SANDBOXES.CRYPTO.stub(crypto_2.Crypto.prototype, 'getKeyChain').callsFake(() =>
|
|
468
|
+
// @ts-expect-error: not the full type
|
|
469
|
+
Promise.resolve({
|
|
460
470
|
setPassword: () => Promise.resolve(),
|
|
461
471
|
getPassword: (data, cb) => cb(undefined, '12345678901234567890123456789012'),
|
|
462
472
|
}));
|
|
463
|
-
|
|
464
|
-
|
|
473
|
+
testContext.SANDBOXES.CONNECTION.stub(connection_1.Connection.prototype, 'isResolvable').resolves(true);
|
|
474
|
+
// @ts-expect-error: just enough of an httpResponse for testing
|
|
475
|
+
testContext.SANDBOXES.CONNECTION.stub(connection_1.Connection.prototype, 'request').callsFake(function (request, options) {
|
|
465
476
|
if (request === `${this.instanceUrl}/services/data`) {
|
|
466
477
|
return Promise.resolve([{ version: '42.0' }]);
|
|
467
478
|
}
|
|
468
479
|
return testContext.fakeConnectionRequest.call(this, request, options);
|
|
469
480
|
});
|
|
470
|
-
|
|
471
|
-
stubs.configExists =
|
|
481
|
+
testContext.SANDBOX.stub(aliasAccessorEntireFile, 'getFileLocation').returns(getAliasFileLocation());
|
|
482
|
+
stubs.configExists = testContext.SANDBOXES.ORGS.stub(stateAggregator_1.OrgAccessor.prototype, 'exists').callsFake(async function (username) {
|
|
472
483
|
// @ts-expect-error because private member
|
|
473
484
|
if ([...this.contents.keys()].includes(username))
|
|
474
485
|
return Promise.resolve(true);
|
|
475
486
|
else
|
|
476
487
|
return Promise.resolve(false);
|
|
477
488
|
});
|
|
478
|
-
stubs.configRemove =
|
|
489
|
+
stubs.configRemove = testContext.SANDBOXES.ORGS.stub(stateAggregator_1.OrgAccessor.prototype, 'remove').callsFake(async function (username) {
|
|
479
490
|
// @ts-expect-error because private member
|
|
480
491
|
if ([...this.contents.keys()].includes(username))
|
|
481
|
-
return Promise.resolve(
|
|
492
|
+
return Promise.resolve();
|
|
482
493
|
else
|
|
483
|
-
return Promise.resolve(
|
|
494
|
+
return Promise.resolve();
|
|
484
495
|
});
|
|
485
496
|
// Always start with the default and tests beforeEach or it methods can override it.
|
|
486
497
|
testContext.fakeConnectionRequest = defaultFakeConnectionRequest;
|