@salesforce/core 5.3.15 → 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.
Files changed (2) hide show
  1. package/lib/testSetup.js +29 -18
  2. package/package.json +4 -4
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
- (0, ts_sinon_1.stubMethod)(this.SANDBOX, stateAggregator_1.OrgAccessor.prototype, 'getAllFiles').resolves([...orgMap.keys()].map((o) => `${o}.json`));
190
- (0, ts_sinon_1.stubMethod)(this.SANDBOX, stateAggregator_1.OrgAccessor.prototype, 'hasFile').callsFake((username) => orgMap.has(username));
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
- (0, ts_sinon_1.stubMethod)(this.SANDBOX, org_1.User.prototype, 'retrieve').callsFake((username) => Promise.resolve(mockUsers.find((org) => org.username === username)));
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
- (0, ts_sinon_1.stubMethod)(this.SANDBOX, sandboxAccessor_1.SandboxAccessor.prototype, 'getAllFiles').resolves([...sandboxMap.keys()].map((o) => `${o}.sandbox.json`));
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
- (0, ts_sinon_1.stubMethod)(testContext.SANDBOX, logger_1.Logger, 'child').resolves(testContext.TEST_LOGGER);
395
- (0, ts_sinon_1.stubMethod)(testContext.SANDBOX, logger_1.Logger, 'childFromRoot').returns(testContext.TEST_LOGGER);
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
- (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.PROJECT, sfProject_1.SfProjectJson.prototype, 'doesPackageExist').callsFake(() => true);
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 = (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.CONFIG, configFile_1.ConfigFile.prototype, 'writeSync').callsFake(writeSync);
458
- stubs.configWrite = (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.CONFIG, configFile_1.ConfigFile.prototype, 'write').callsFake(write);
459
- (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.CRYPTO, crypto_2.Crypto.prototype, 'getKeyChain').callsFake(() => Promise.resolve({
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
- (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.CONNECTION, connection_1.Connection.prototype, 'isResolvable').resolves(true);
464
- (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.CONNECTION, connection_1.Connection.prototype, 'request').callsFake(function (request, options) {
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
- (0, ts_sinon_1.stubMethod)(testContext.SANDBOX, aliasAccessorEntireFile, 'getFileLocation').returns(getAliasFileLocation());
471
- stubs.configExists = (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.ORGS, stateAggregator_1.OrgAccessor.prototype, 'exists').callsFake(async function (username) {
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 = (0, ts_sinon_1.stubMethod)(testContext.SANDBOXES.ORGS, stateAggregator_1.OrgAccessor.prototype, 'remove').callsFake(async function (username) {
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(true);
492
+ return Promise.resolve();
482
493
  else
483
- return Promise.resolve(false);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "5.3.15",
3
+ "version": "5.3.17",
4
4
  "description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",
@@ -39,7 +39,7 @@
39
39
  "messageTransformer/messageTransformer.ts"
40
40
  ],
41
41
  "dependencies": {
42
- "@salesforce/kit": "^3.0.14",
42
+ "@salesforce/kit": "^3.0.15",
43
43
  "@salesforce/schemas": "^1.6.1",
44
44
  "@salesforce/ts-types": "^2.0.9",
45
45
  "@types/semver": "^7.5.3",
@@ -59,7 +59,7 @@
59
59
  "ts-retry-promise": "^0.7.1"
60
60
  },
61
61
  "devDependencies": {
62
- "@salesforce/dev-config": "^4.0.1",
62
+ "@salesforce/dev-config": "^4.1.0",
63
63
  "@salesforce/dev-scripts": "^5.4.2",
64
64
  "@salesforce/prettier-config": "^0.0.3",
65
65
  "@salesforce/ts-sinon": "^1.4.18",
@@ -74,7 +74,7 @@
74
74
  "benchmark": "^2.1.4",
75
75
  "chai": "^4.3.10",
76
76
  "chai-string": "^1.5.0",
77
- "eslint": "^8.51.0",
77
+ "eslint": "^8.52.0",
78
78
  "eslint-config-prettier": "^8.10.0",
79
79
  "eslint-config-salesforce": "^2.0.2",
80
80
  "eslint-config-salesforce-license": "^0.2.0",