From d61dc59e64976d37d98bc264aa62e2f7b67de347 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 31 May 2022 17:55:39 -0500 Subject: [PATCH 1/2] fix: multiple plugin-config versions --- .vscode/launch.json | 15 +++++++++++++++ src/testkit.ts | 21 +++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..cff7007c --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "attach", + "name": "Attach", + "port": 9229, + "skipFiles": ["/**"] + }, + ] +} diff --git a/src/testkit.ts b/src/testkit.ts index 9f48cc06..874a162d 100644 --- a/src/testkit.ts +++ b/src/testkit.ts @@ -14,7 +14,7 @@ import * as fg from 'fast-glob'; import { exec, find, mv, rm, which } from 'shelljs'; import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit'; import { AsyncCreatable, Env, set, parseJsonMap } from '@salesforce/kit'; -import { AnyJson, Dictionary, ensureString, get, JsonMap, Nullable } from '@salesforce/ts-types'; +import { AnyJson, Dictionary, ensureString, JsonMap, Nullable } from '@salesforce/ts-types'; import { AuthInfo, SfdxPropertyKeys, Connection, NamedPackageDir, SfdxProject } from '@salesforce/core'; import { debug, Debugger } from 'debug'; import { MetadataResolver } from '@salesforce/source-deploy-retrieve'; @@ -382,7 +382,7 @@ export class SourceTestkit extends AsyncCreatable { } /** - * Returns true if the executable being used belongs to a local pacakage + * Returns true if the executable being used belongs to a local package */ public isLocalExecutable(): boolean { return ( @@ -537,10 +537,19 @@ export class SourceTestkit extends AsyncCreatable { } private async getDefaultUsername(): Promise { - const configVar = this.executableName === Executable.SF ? 'target-org' : SfdxPropertyKeys.DEFAULT_USERNAME; - const configResult = execCmd(`config:get ${configVar} --json`).jsonOutput!; - const results = get(configResult, 'result', configResult) as Array<{ key?: string; name?: string; value: string }>; - const username = results.find((r) => r.key === configVar || r.name === configVar)!.value; + const configVar = 'target-org'; + const configResult = execCmd>( + `config:get ${configVar} --json` + ).jsonOutput?.result; + // depending on which version of config:get the user has available, there may be a name or key + // eventually, drop the `key` option and the deprecated SfdxPropertyKeys + const possibleKeys = [configVar, SfdxPropertyKeys.DEFAULT_USERNAME]; + const username = configResult?.find( + (r) => (r.key && possibleKeys.includes(r.key)) || (r.name && possibleKeys.includes(r.name)) + )?.value; + if (!username) { + throw new Error('No default username found'); + } return username; } From 86f7a1c3ceb938f52dc77f4d549f861b2fda7bfa Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 31 May 2022 17:59:42 -0500 Subject: [PATCH 2/2] refactor: change fewer things I don't understand --- src/testkit.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/testkit.ts b/src/testkit.ts index 874a162d..fc30978c 100644 --- a/src/testkit.ts +++ b/src/testkit.ts @@ -547,10 +547,7 @@ export class SourceTestkit extends AsyncCreatable { const username = configResult?.find( (r) => (r.key && possibleKeys.includes(r.key)) || (r.name && possibleKeys.includes(r.name)) )?.value; - if (!username) { - throw new Error('No default username found'); - } - return username; + return username!; } private async createConnection(): Promise> {