@@ -18,17 +18,8 @@ import {
1818import { flags , SfdxCommand } from '@salesforce/command' ;
1919import { Messages , SfError } from '@salesforce/core' ;
2020import { AnyJson } from '@salesforce/ts-types' ;
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' ;
21+ import { buildOutputDirConfig , CliJsonFormat , JsonReporter } from '../../../../reporters' ;
22+ import { buildDescription , logLevels , resultFormat , FAILURE_EXIT_CODE } from '../../../../utils' ;
3223
3324Messages . importMessagesDirectory ( __dirname ) ;
3425const messages = Messages . load ( '@salesforce/plugin-apex' , 'run' , [
@@ -60,11 +51,7 @@ const messages = Messages.load('@salesforce/plugin-apex', 'run', [
6051 'warningMessage'
6152] ) ;
6253
63- export const TestLevelValues = [
64- 'RunLocalTests' ,
65- 'RunAllTestsInOrg' ,
66- 'RunSpecifiedTests'
67- ] ;
54+ export const TestLevelValues = [ 'RunLocalTests' , 'RunAllTestsInOrg' , 'RunSpecifiedTests' ] ;
6855export default class Run extends SfdxCommand {
6956 protected static requiresUsername = true ;
7057 protected cancellationTokenSource = new CancellationTokenSource ( ) ;
@@ -150,9 +137,7 @@ export default class Run extends SfdxCommand {
150137
151138 // add listener for errors
152139 process . on ( 'uncaughtException' , err => {
153- const formattedErr = this . formatError (
154- new SfError ( messages . getMessage ( 'apexLibErr' , [ err . message ] ) )
155- ) ;
140+ const formattedErr = this . formatError ( new SfError ( messages . getMessage ( 'apexLibErr' , [ err . message ] ) ) ) ;
156141 this . ux . error ( ...formattedErr ) ;
157142 process . exit ( ) ;
158143 } ) ;
@@ -178,11 +163,7 @@ export default class Run extends SfdxCommand {
178163 // This was re-introduced due to https://github.com/forcedotcom/salesforcedx-vscode/issues/3154
179164 // Address with W-9163533
180165 if ( this . flags . synchronous && testLevel === TestLevel . RunSpecifiedTests ) {
181- const payload = await testService . buildSyncPayload (
182- testLevel ,
183- this . flags . tests ,
184- this . flags . classnames
185- ) ;
166+ const payload = await testService . buildSyncPayload ( testLevel , this . flags . tests , this . flags . classnames ) ;
186167 payload . skipCodeCoverage = this . flags . codecoverage ? false : true ;
187168 result = ( await testService . runTestSynchronous (
188169 payload ,
@@ -223,28 +204,19 @@ export default class Run extends SfdxCommand {
223204 this . flags . synchronous
224205 ) ;
225206
226- await testService . writeResultFiles (
227- result ,
228- outputDirConfig ,
229- this . flags . codecoverage
230- ) ;
207+ await testService . writeResultFiles ( result , outputDirConfig , this . flags . codecoverage ) ;
231208 }
232209
233210 try {
234211 if (
235212 result . hasOwnProperty ( 'summary' ) &&
236- ( result as TestResult ) . summary . outcome ===
237- ApexTestRunResultStatus . Failed
213+ ( result as TestResult ) . summary . outcome === ApexTestRunResultStatus . Failed
238214 ) {
239215 process . exitCode = FAILURE_EXIT_CODE ;
240216 }
241217 switch ( this . flags . resultformat ) {
242218 case 'human' :
243- this . logHuman (
244- result as TestResult ,
245- this . flags . detailedcoverage ,
246- this . flags . outputdir
247- ) ;
219+ this . logHuman ( result as TestResult , this . flags . detailedcoverage , this . flags . outputdir ) ;
248220 break ;
249221 case 'tap' :
250222 this . logTap ( result as TestResult ) ;
@@ -263,26 +235,15 @@ export default class Run extends SfdxCommand {
263235 break ;
264236 default :
265237 if ( this . flags . synchronous || this . flags . wait ) {
266- this . logHuman (
267- result as TestResult ,
268- this . flags . detailedcoverage ,
269- this . flags . outputdir
270- ) ;
238+ this . logHuman ( result as TestResult , this . flags . detailedcoverage , this . flags . outputdir ) ;
271239 } else {
272- const id = ( result as TestRunIdResult ) . testRunId ;
273- this . ux . log (
274- messages . getMessage ( 'runTestReportCommand' , [
275- id ,
276- this . org ?. getUsername ( )
277- ] )
278- ) ;
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 ( ) ] ) ) ;
279242 }
280243 }
281244 } catch ( e ) {
282245 this . ux . logJson ( result ) ;
283- const msg = messages . getMessage ( 'testResultProcessErr' , [
284- ( e as Error ) . message
285- ] ) ;
246+ const msg = messages . getMessage ( 'testResultProcessErr' , [ ( e as Error ) . message ] ) ;
286247 this . ux . error ( msg ) ;
287248 }
288249
@@ -291,24 +252,19 @@ export default class Run extends SfdxCommand {
291252
292253 public async validateFlags ( ) : Promise < void > {
293254 if ( this . flags . codecoverage && ! this . flags . resultformat ) {
294- return Promise . reject (
295- new Error ( messages . getMessage ( 'missingReporterErr' ) )
296- ) ;
255+ return Promise . reject ( new Error ( messages . getMessage ( 'missingReporterErr' ) ) ) ;
297256 }
298257
299258 if (
300259 ( this . flags . classnames && ( this . flags . suitenames || this . flags . tests ) ) ||
301260 ( this . flags . suitenames && this . flags . tests )
302261 ) {
303- return Promise . reject (
304- new Error ( messages . getMessage ( 'classSuiteTestErr' ) )
305- ) ;
262+ return Promise . reject ( new Error ( messages . getMessage ( 'classSuiteTestErr' ) ) ) ;
306263 }
307264
308265 if (
309266 this . flags . synchronous &&
310- ( this . flags . suitenames ||
311- ( this . flags . classnames && this . flags . classnames . split ( ',' ) . length > 1 ) )
267+ ( this . flags . suitenames || ( this . flags . classnames && this . flags . classnames . split ( ',' ) . length > 1 ) )
312268 ) {
313269 return Promise . reject ( new Error ( messages . getMessage ( 'syncClassErr' ) ) ) ;
314270 }
@@ -326,11 +282,7 @@ export default class Run extends SfdxCommand {
326282 let testLevel : TestLevel ;
327283 if ( this . flags . testlevel ) {
328284 testLevel = this . flags . testlevel ;
329- } else if (
330- this . flags . classnames ||
331- this . flags . suitenames ||
332- this . flags . tests
333- ) {
285+ } else if ( this . flags . classnames || this . flags . suitenames || this . flags . tests ) {
334286 testLevel = TestLevel . RunSpecifiedTests ;
335287 } else {
336288 testLevel = TestLevel . RunLocalTests ;
@@ -339,11 +291,7 @@ export default class Run extends SfdxCommand {
339291 return testLevel ;
340292 }
341293
342- private logHuman (
343- result : TestResult ,
344- detailedCoverage : boolean ,
345- outputDir : string
346- ) : void {
294+ private logHuman ( result : TestResult , detailedCoverage : boolean , outputDir : string ) : void {
347295 if ( outputDir ) {
348296 this . ux . log ( messages . getMessage ( 'outputDirHint' , [ outputDir ] ) ) ;
349297 }
@@ -363,19 +311,13 @@ export default class Run extends SfdxCommand {
363311 this . ux . log ( reporter . format ( result ) ) ;
364312 }
365313
366- private formatResultInJson (
367- result : TestResult | TestRunIdResult
368- ) : CliJsonFormat | TestRunIdResult {
314+ private formatResultInJson ( result : TestResult | TestRunIdResult ) : CliJsonFormat | TestRunIdResult {
369315 try {
370316 const reporter = new JsonReporter ( ) ;
371- return result . hasOwnProperty ( 'summary' )
372- ? reporter . format ( result as TestResult )
373- : ( result as TestRunIdResult ) ;
317+ return result . hasOwnProperty ( 'summary' ) ? reporter . format ( result as TestResult ) : ( result as TestRunIdResult ) ;
374318 } catch ( e ) {
375319 this . ux . logJson ( result ) ;
376- const msg = messages . getMessage ( 'testResultProcessErr' , [
377- ( e as Error ) . message
378- ] ) ;
320+ const msg = messages . getMessage ( 'testResultProcessErr' , [ ( e as Error ) . message ] ) ;
379321 this . ux . error ( msg ) ;
380322 throw e ;
381323 }
0 commit comments