Skip to content

Commit

Permalink
fix: clear globalInfo instance after every possible touchpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jun 2, 2022
1 parent 91264d4 commit ca7dc01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/hubAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as os from 'os';
import * as fs from 'fs';
import * as shell from 'shelljs';
import { debug } from 'debug';
import { AuthFields } from '@salesforce/core';
import { AuthFields, GlobalInfo } from '@salesforce/core';
import { env } from '@salesforce/kit';

// this seems to be a known eslint error for enums
Expand Down Expand Up @@ -94,6 +94,8 @@ export const testkitHubAuth = (homeDir: string, authStrategy: AuthStrategy = get
)} -f ${jwtKey} -r ${env.getString('TESTKIT_HUB_INSTANCE', DEFAULT_INSTANCE_URL)}`,
execOpts
) as shell.ShellString;
GlobalInfo.clearInstance();

if (results.code !== 0) {
throw new Error(
`jwt:grant for org ${env.getString(
Expand All @@ -110,6 +112,7 @@ export const testkitHubAuth = (homeDir: string, authStrategy: AuthStrategy = get
const tmpUrl = prepareForAuthUrl(homeDir);

const shellOutput = shell.exec(`sfdx auth:sfdxurl:store -d -f ${tmpUrl}`, execOpts) as shell.ShellString;
GlobalInfo.clearInstance();
logger(shellOutput);
if (shellOutput.code !== 0) {
throw new Error(
Expand Down Expand Up @@ -185,6 +188,8 @@ export const transferExistingAuthToEnv = (authStrategy: AuthStrategy = getAuthSt
const displayContents = JSON.parse(
shell.exec(`sfdx force:org:display -u ${devhub} --verbose --json`, execOpts) as string
) as OrgDisplayResult;
GlobalInfo.clearInstance();

logger(`found ${displayContents.result.sfdxAuthUrl}`);
env.setString('TESTKIT_AUTH_URL', displayContents.result.sfdxAuthUrl);
return;
Expand Down
4 changes: 4 additions & 0 deletions src/testSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as fs from 'fs';
import * as path from 'path';
import { RetryConfig } from 'ts-retry-promise';
import { debug, Debugger } from 'debug';
import { GlobalInfo } from '@salesforce/core';
import { AsyncOptionalCreatable, Duration, env, parseJson, sleep } from '@salesforce/kit';
import { AnyJson, getString, Optional } from '@salesforce/ts-types';
import { createSandbox, SinonStub } from 'sinon';
Expand Down Expand Up @@ -249,6 +250,7 @@ export class TestSession extends AsyncOptionalCreatable<TestSessionOptions> {
}
this.debug('Deleted org result=', rv.stdout);
}
GlobalInfo.clearInstance();
}
}

Expand Down Expand Up @@ -344,6 +346,8 @@ export class TestSession extends AsyncOptionalCreatable<TestSessionOptions> {
await this.sleep(timeout);
}
}
// there may be globalInfo touches from org:create or other setup commands run
GlobalInfo.clearInstance();
}

private async sleep(duration: Duration): Promise<void> {
Expand Down

0 comments on commit ca7dc01

Please sign in to comment.