@@ -14,7 +14,7 @@ import * as fg from 'fast-glob';
1414import { exec , find , mv , rm , which } from 'shelljs' ;
1515import { TestSession , execCmd } from '@salesforce/cli-plugins-testkit' ;
1616import { AsyncCreatable , Env , set , parseJsonMap } from '@salesforce/kit' ;
17- import { AnyJson , Dictionary , ensureString , get , JsonMap , Nullable } from '@salesforce/ts-types' ;
17+ import { AnyJson , Dictionary , ensureString , JsonMap , Nullable } from '@salesforce/ts-types' ;
1818import { AuthInfo , SfdxPropertyKeys , Connection , NamedPackageDir , SfdxProject } from '@salesforce/core' ;
1919import { debug , Debugger } from 'debug' ;
2020import { MetadataResolver } from '@salesforce/source-deploy-retrieve' ;
@@ -382,7 +382,7 @@ export class SourceTestkit extends AsyncCreatable<SourceTestkit.Options> {
382382 }
383383
384384 /**
385- * Returns true if the executable being used belongs to a local pacakage
385+ * Returns true if the executable being used belongs to a local package
386386 */
387387 public isLocalExecutable ( ) : boolean {
388388 return (
@@ -537,11 +537,17 @@ export class SourceTestkit extends AsyncCreatable<SourceTestkit.Options> {
537537 }
538538
539539 private async getDefaultUsername ( ) : Promise < string > {
540- const configVar = this . executableName === Executable . SF ? 'target-org' : SfdxPropertyKeys . DEFAULT_USERNAME ;
541- const configResult = execCmd ( `config:get ${ configVar } --json` ) . jsonOutput ! ;
542- const results = get ( configResult , 'result' , configResult ) as Array < { key ?: string ; name ?: string ; value : string } > ;
543- const username = results . find ( ( r ) => r . key === configVar || r . name === configVar ) ! . value ;
544- return username ;
540+ const configVar = 'target-org' ;
541+ const configResult = execCmd < Array < { key ?: string ; name ?: string ; value : string } > > (
542+ `config:get ${ configVar } --json`
543+ ) . jsonOutput ?. result ;
544+ // depending on which version of config:get the user has available, there may be a name or key
545+ // eventually, drop the `key` option and the deprecated SfdxPropertyKeys
546+ const possibleKeys = [ configVar , SfdxPropertyKeys . DEFAULT_USERNAME ] ;
547+ const username = configResult ?. find (
548+ ( r ) => ( r . key && possibleKeys . includes ( r . key ) ) || ( r . name && possibleKeys . includes ( r . name ) )
549+ ) ?. value ;
550+ return username ! ;
545551 }
546552
547553 private async createConnection ( ) : Promise < Nullable < Connection > > {
0 commit comments