@@ -18,8 +18,17 @@ import {
1818import { flags , SfdxCommand } from '@salesforce/command' ;
1919import { Messages , SfError } from '@salesforce/core' ;
2020import { AnyJson } from '@salesforce/ts-types' ;
21- import { buildOutputDirConfig , CliJsonFormat , JsonReporter } from '../../../../reporters' ;
22- import { buildDescription , logLevels , resultFormat , FAILURE_EXIT_CODE } from '../../../../utils' ;
21+ import {
22+ buildOutputDirConfig ,
23+ CliJsonFormat ,
24+ JsonReporter
25+ } from '../../../../reporters' ;
26+ import {
27+ buildDescription ,
28+ logLevels ,
29+ resultFormat ,
30+ FAILURE_EXIT_CODE
31+ } from '../../../../utils' ;
2332
2433Messages . importMessagesDirectory ( __dirname ) ;
2534const messages = Messages . load ( '@salesforce/plugin-apex' , 'run' , [
@@ -51,7 +60,11 @@ const messages = Messages.load('@salesforce/plugin-apex', 'run', [
5160 'warningMessage'
5261] ) ;
5362
54- export const TestLevelValues = [ 'RunLocalTests' , 'RunAllTestsInOrg' , 'RunSpecifiedTests' ] ;
63+ export const TestLevelValues = [
64+ 'RunLocalTests' ,
65+ 'RunAllTestsInOrg' ,
66+ 'RunSpecifiedTests'
67+ ] ;
5568export default class Run extends SfdxCommand {
5669 protected static requiresUsername = true ;
5770 protected cancellationTokenSource = new CancellationTokenSource ( ) ;
@@ -137,7 +150,9 @@ export default class Run extends SfdxCommand {
137150
138151 // add listener for errors
139152 process . on ( 'uncaughtException' , err => {
140- const formattedErr = this . formatError ( new SfError ( messages . getMessage ( 'apexLibErr' , [ err . message ] ) ) ) ;
153+ const formattedErr = this . formatError (
154+ new SfError ( messages . getMessage ( 'apexLibErr' , [ err . message ] ) )
155+ ) ;
141156 this . ux . error ( ...formattedErr ) ;
142157 process . exit ( ) ;
143158 } ) ;
@@ -163,7 +178,11 @@ export default class Run extends SfdxCommand {
163178 // This was re-introduced due to https://github.com/forcedotcom/salesforcedx-vscode/issues/3154
164179 // Address with W-9163533
165180 if ( this . flags . synchronous && testLevel === TestLevel . RunSpecifiedTests ) {
166- const payload = await testService . buildSyncPayload ( testLevel , this . flags . tests , this . flags . classnames ) ;
181+ const payload = await testService . buildSyncPayload (
182+ testLevel ,
183+ this . flags . tests ,
184+ this . flags . classnames
185+ ) ;
167186 payload . skipCodeCoverage = this . flags . codecoverage ? false : true ;
168187 result = ( await testService . runTestSynchronous (
169188 payload ,
@@ -204,19 +223,28 @@ export default class Run extends SfdxCommand {
204223 this . flags . synchronous
205224 ) ;
206225
207- await testService . writeResultFiles ( result , outputDirConfig , this . flags . codecoverage ) ;
226+ await testService . writeResultFiles (
227+ result ,
228+ outputDirConfig ,
229+ this . flags . codecoverage
230+ ) ;
208231 }
209232
210233 try {
211234 if (
212235 result . hasOwnProperty ( 'summary' ) &&
213- ( result as TestResult ) . summary . outcome === ApexTestRunResultStatus . Failed
236+ ( result as TestResult ) . summary . outcome ===
237+ ApexTestRunResultStatus . Failed
214238 ) {
215239 process . exitCode = FAILURE_EXIT_CODE ;
216240 }
217241 switch ( this . flags . resultformat ) {
218242 case 'human' :
219- this . logHuman ( result as TestResult , this . flags . detailedcoverage , this . flags . outputdir ) ;
243+ this . logHuman (
244+ result as TestResult ,
245+ this . flags . detailedcoverage ,
246+ this . flags . outputdir
247+ ) ;
220248 break ;
221249 case 'tap' :
222250 this . logTap ( result as TestResult ) ;
@@ -235,15 +263,26 @@ export default class Run extends SfdxCommand {
235263 break ;
236264 default :
237265 if ( this . flags . synchronous || this . flags . wait ) {
238- this . logHuman ( result as TestResult , this . flags . detailedcoverage , this . flags . outputdir ) ;
266+ this . logHuman (
267+ result as TestResult ,
268+ this . flags . detailedcoverage ,
269+ this . flags . outputdir
270+ ) ;
239271 } else {
240- const id : TestRunIdResult = ( ( result as TestResult ) . tests [ 0 ] . id as unknown ) as TestRunIdResult ;
241- this . ux . log ( messages . getMessage ( 'runTestReportCommand' , [ String ( id ) , this . org ?. getUsername ( ) ] ) ) ;
272+ const id = ( result as TestRunIdResult ) . testRunId ;
273+ this . ux . log (
274+ messages . getMessage ( 'runTestReportCommand' , [
275+ id ,
276+ this . org ?. getUsername ( )
277+ ] )
278+ ) ;
242279 }
243280 }
244281 } catch ( e ) {
245282 this . ux . logJson ( result ) ;
246- const msg = messages . getMessage ( 'testResultProcessErr' , [ ( e as Error ) . message ] ) ;
283+ const msg = messages . getMessage ( 'testResultProcessErr' , [
284+ ( e as Error ) . message
285+ ] ) ;
247286 this . ux . error ( msg ) ;
248287 }
249288
@@ -252,19 +291,24 @@ export default class Run extends SfdxCommand {
252291
253292 public async validateFlags ( ) : Promise < void > {
254293 if ( this . flags . codecoverage && ! this . flags . resultformat ) {
255- return Promise . reject ( new Error ( messages . getMessage ( 'missingReporterErr' ) ) ) ;
294+ return Promise . reject (
295+ new Error ( messages . getMessage ( 'missingReporterErr' ) )
296+ ) ;
256297 }
257298
258299 if (
259300 ( this . flags . classnames && ( this . flags . suitenames || this . flags . tests ) ) ||
260301 ( this . flags . suitenames && this . flags . tests )
261302 ) {
262- return Promise . reject ( new Error ( messages . getMessage ( 'classSuiteTestErr' ) ) ) ;
303+ return Promise . reject (
304+ new Error ( messages . getMessage ( 'classSuiteTestErr' ) )
305+ ) ;
263306 }
264307
265308 if (
266309 this . flags . synchronous &&
267- ( this . flags . suitenames || ( this . flags . classnames && this . flags . classnames . split ( ',' ) . length > 1 ) )
310+ ( this . flags . suitenames ||
311+ ( this . flags . classnames && this . flags . classnames . split ( ',' ) . length > 1 ) )
268312 ) {
269313 return Promise . reject ( new Error ( messages . getMessage ( 'syncClassErr' ) ) ) ;
270314 }
@@ -282,7 +326,11 @@ export default class Run extends SfdxCommand {
282326 let testLevel : TestLevel ;
283327 if ( this . flags . testlevel ) {
284328 testLevel = this . flags . testlevel ;
285- } else if ( this . flags . classnames || this . flags . suitenames || this . flags . tests ) {
329+ } else if (
330+ this . flags . classnames ||
331+ this . flags . suitenames ||
332+ this . flags . tests
333+ ) {
286334 testLevel = TestLevel . RunSpecifiedTests ;
287335 } else {
288336 testLevel = TestLevel . RunLocalTests ;
@@ -291,7 +339,11 @@ export default class Run extends SfdxCommand {
291339 return testLevel ;
292340 }
293341
294- private logHuman ( result : TestResult , detailedCoverage : boolean , outputDir : string ) : void {
342+ private logHuman (
343+ result : TestResult ,
344+ detailedCoverage : boolean ,
345+ outputDir : string
346+ ) : void {
295347 if ( outputDir ) {
296348 this . ux . log ( messages . getMessage ( 'outputDirHint' , [ outputDir ] ) ) ;
297349 }
@@ -311,20 +363,26 @@ export default class Run extends SfdxCommand {
311363 this . ux . log ( reporter . format ( result ) ) ;
312364 }
313365
314- private formatResultInJson ( result : TestResult | TestRunIdResult ) : CliJsonFormat | TestRunIdResult {
366+ private formatResultInJson (
367+ result : TestResult | TestRunIdResult
368+ ) : CliJsonFormat | TestRunIdResult {
315369 try {
316370 const reporter = new JsonReporter ( ) ;
317- return result . hasOwnProperty ( 'summary' ) ? reporter . format ( result as TestResult ) : ( result as TestRunIdResult ) ;
371+ return result . hasOwnProperty ( 'summary' )
372+ ? reporter . format ( result as TestResult )
373+ : ( result as TestRunIdResult ) ;
318374 } catch ( e ) {
319375 this . ux . logJson ( result ) ;
320- const msg = messages . getMessage ( 'testResultProcessErr' , [ ( e as Error ) . message ] ) ;
376+ const msg = messages . getMessage ( 'testResultProcessErr' , [
377+ ( e as Error ) . message
378+ ] ) ;
321379 this . ux . error ( msg ) ;
322380 throw e ;
323381 }
324382 }
325383
326384 private formatReportHint ( result : TestResult ) : string {
327- let reportArgs = `-i ${ result . summary ? .testRunId } ` ;
385+ let reportArgs = `-i ${ result . summary . testRunId } ` ;
328386 if ( this . flags . targetusername ) {
329387 reportArgs += ` -u ${ this . flags . targetusername } ` ;
330388 }
0 commit comments