Skip to content

Commit

Permalink
test: stub requests done when instantiating AuthInfo
Browse files Browse the repository at this point in the history
`AuthInfo.determineIfDevHub` and `AuthInfo.getNamespacePrefix` do some
requests when creating a new AuthInfo instance, if we don't stub these
methods the requests are done and jsforce keeps retrying requests until
mocha times out.
  • Loading branch information
cristiand391 committed Apr 30, 2024
1 parent 0f0d32f commit fb71b45
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/util/sfdcUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ export class SfdcUrl extends URL {
* @returns {boolean} true if this domain is a lightning domain
*/
public isLightningDomain(): boolean {
return this.origin.includes('.lightning.force.com') || this.origin.includes('.lightning.crmforce.mil') || this.origin.includes('.lightning.sfcrmapps.cn');
return (
this.origin.includes('.lightning.force.com') ||
this.origin.includes('.lightning.crmforce.mil') ||
this.origin.includes('.lightning.sfcrmapps.cn')
);
}
}
30 changes: 30 additions & 0 deletions test/unit/org/authInfoTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ describe('AuthInfo', () => {
});

it('should return an AuthInfo instance when passed a parent username', async () => {
stubMethod($$.SANDBOX, AuthInfo.prototype, 'determineIfDevHub').resolves(false);
stubMethod($$.SANDBOX, AuthInfo.prototype, 'getNamespacePrefix').resolves();

await $$.stubConfig({ [OrgConfigProperties.ORG_INSTANCE_URL]: testOrg.instanceUrl });
// Stub the http request (OAuth2.refreshToken())
// This will be called for both, and we want to make sure the clientSecret is the
Expand Down Expand Up @@ -462,6 +465,9 @@ describe('AuthInfo', () => {
});

it('should return a JWT AuthInfo instance when passed a username and JWT auth options despite failed DNS lookup', async () => {
stubMethod($$.SANDBOX, AuthInfo.prototype, 'determineIfDevHub').resolves(false);
stubMethod($$.SANDBOX, AuthInfo.prototype, 'getNamespacePrefix').resolves();

$$.setConfigStubContents('AuthInfoConfig', { contents: await testOrg.getConfig() });

const jwtConfig = {
Expand Down Expand Up @@ -531,6 +537,9 @@ describe('AuthInfo', () => {

describe('Refresh Token', () => {
it('should return a refresh token AuthInfo instance when passed a username and refresh token auth options', async () => {
stubMethod($$.SANDBOX, AuthInfo.prototype, 'determineIfDevHub').resolves(false);
stubMethod($$.SANDBOX, AuthInfo.prototype, 'getNamespacePrefix').resolves();

const refreshTokenConfig = {
refreshToken: testOrg.refreshToken,
loginUrl: testOrg.loginUrl,
Expand Down Expand Up @@ -585,6 +594,9 @@ describe('AuthInfo', () => {
});

it('should return a refresh token AuthInfo instance with username in auth options', async () => {
stubMethod($$.SANDBOX, AuthInfo.prototype, 'determineIfDevHub').resolves(false);
stubMethod($$.SANDBOX, AuthInfo.prototype, 'getNamespacePrefix').resolves();

const refreshTokenConfig = {
refreshToken: testOrg.refreshToken,
loginUrl: testOrg.loginUrl,
Expand Down Expand Up @@ -705,6 +717,9 @@ describe('AuthInfo', () => {
});

it('should return a refresh token AuthInfo instance with custom clientId and clientSecret', async () => {
stubMethod($$.SANDBOX, AuthInfo.prototype, 'determineIfDevHub').resolves(false);
stubMethod($$.SANDBOX, AuthInfo.prototype, 'getNamespacePrefix').resolves();

const refreshTokenConfig = {
clientId: 'authInfoTest_clientId',
clientSecret: 'authInfoTest_clientSecret',
Expand Down Expand Up @@ -986,6 +1001,9 @@ describe('AuthInfo', () => {

describe('save', () => {
it('should update the AuthInfo fields, and write to file', async () => {
stubMethod($$.SANDBOX, AuthInfo.prototype, 'determineIfDevHub').resolves(false);
stubMethod($$.SANDBOX, AuthInfo.prototype, 'getNamespacePrefix').resolves();

const refreshTokenConfig = {
refreshToken: testOrg.refreshToken,
loginUrl: testOrg.loginUrl,
Expand Down Expand Up @@ -1227,6 +1245,9 @@ describe('AuthInfo', () => {

describe('getSfdxAuthUrl', () => {
it('should return the correct sfdx auth url', async () => {
stubMethod($$.SANDBOX, AuthInfo.prototype, 'determineIfDevHub').resolves(false);
stubMethod($$.SANDBOX, AuthInfo.prototype, 'getNamespacePrefix').resolves();

const authResponse = {
access_token: testOrg.accessToken,
instance_url: testOrg.instanceUrl,
Expand All @@ -1251,6 +1272,9 @@ describe('AuthInfo', () => {
});

it('should handle undefined client secret', async () => {
stubMethod($$.SANDBOX, AuthInfo.prototype, 'determineIfDevHub').resolves(false);
stubMethod($$.SANDBOX, AuthInfo.prototype, 'getNamespacePrefix').resolves();

const authResponse = {
access_token: testOrg.accessToken,
instance_url: testOrg.instanceUrl,
Expand All @@ -1276,6 +1300,9 @@ describe('AuthInfo', () => {
});

it('should handle undefined refresh token', async () => {
stubMethod($$.SANDBOX, AuthInfo.prototype, 'determineIfDevHub').resolves(false);
stubMethod($$.SANDBOX, AuthInfo.prototype, 'getNamespacePrefix').resolves();

const authResponse = {
access_token: testOrg.accessToken,
instance_url: testOrg.instanceUrl,
Expand All @@ -1300,6 +1327,9 @@ describe('AuthInfo', () => {
});

it('should handle undefined instance url', async () => {
stubMethod($$.SANDBOX, AuthInfo.prototype, 'determineIfDevHub').resolves(false);
stubMethod($$.SANDBOX, AuthInfo.prototype, 'getNamespacePrefix').resolves();

const authResponse = {
access_token: testOrg.accessToken,
instance_url: testOrg.instanceUrl,
Expand Down

3 comments on commit fb71b45

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: fb71b45 Previous: c6615aa Ratio
Child logger creation 477583 ops/sec (±0.57%) 476995 ops/sec (±1.51%) 1.00
Logging a string on root logger 785501 ops/sec (±8.96%) 801359 ops/sec (±10.07%) 1.02
Logging an object on root logger 620688 ops/sec (±5.62%) 630787 ops/sec (±6.26%) 1.02
Logging an object with a message on root logger 6827 ops/sec (±212.85%) 9098 ops/sec (±204.35%) 1.33
Logging an object with a redacted prop on root logger 465103 ops/sec (±5.73%) 455560 ops/sec (±13.25%) 0.98
Logging a nested 3-level object on root logger 397394 ops/sec (±6.94%) 368030 ops/sec (±8.14%) 0.93

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - windows-latest

Benchmark suite Current: fb71b45 Previous: c6615aa Ratio
Child logger creation 342843 ops/sec (±0.50%) 339458 ops/sec (±0.28%) 0.99
Logging a string on root logger 837027 ops/sec (±8.72%) 781227 ops/sec (±10.49%) 0.93
Logging an object on root logger 655434 ops/sec (±7.25%) 572291 ops/sec (±6.79%) 0.87
Logging an object with a message on root logger 3522 ops/sec (±223.79%) 10076 ops/sec (±198.64%) 2.86
Logging an object with a redacted prop on root logger 471568 ops/sec (±8.55%) 420809 ops/sec (±8.99%) 0.89
Logging a nested 3-level object on root logger 340636 ops/sec (±6.43%) 317858 ops/sec (±5.10%) 0.93

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - windows-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: fb71b45 Previous: c6615aa Ratio
Logging an object with a message on root logger 3522 ops/sec (±223.79%) 10076 ops/sec (±198.64%) 2.86

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.