77import fs from 'node:fs' ;
88import { Connection , Org } from '@salesforce/core' ;
99import sinon from 'sinon' ;
10- import { Ux } from '@salesforce/sf-plugins-core' ;
11- import { Config } from '@oclif/core' ;
12- import { expect } from 'chai' ;
10+ import { Ux , stubSfCommandUx } from '@salesforce/sf-plugins-core' ;
11+ import { expect , config } from 'chai' ;
1312import { TestService } from '@salesforce/apex-node' ;
1413import Test from '../../../../src/commands/apex/get/test.js' ;
1514import { runWithFailures , testRunSimple , testRunSimpleResult , testRunWithFailuresResult } from '../../../testData.js' ;
1615
16+ config . truncateThreshold = 0 ;
17+
1718let logStub : sinon . SinonStub ;
1819let styledJsonStub : sinon . SinonStub ;
1920
2021describe ( 'apex:test:report' , ( ) => {
2122 let sandbox : sinon . SinonSandbox ;
22- let config : Config ;
23+ let uxStub : ReturnType < typeof stubSfCommandUx > ;
2324
2425 beforeEach ( async ( ) => {
25- config = await Config . load ( import . meta. url ) ;
2626 sandbox = sinon . createSandbox ( ) ;
27+ uxStub = stubSfCommandUx ( sandbox ) ;
2728 logStub = sandbox . stub ( Ux . prototype , 'log' ) ;
2829 styledJsonStub = sandbox . stub ( Ux . prototype , 'styledJSON' ) ;
2930 sandbox . stub ( Connection . prototype , 'getUsername' ) . returns ( '[email protected] ' ) ; @@ -46,19 +47,20 @@ describe('apex:test:report', () => {
4647 it ( 'should return a success human format message with async' , async ( ) => {
4748 sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( runWithFailures ) ;
4849
49- const result = await new Test ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'human' ] , config ) . run ( ) ;
50+ const result = await Test . run ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'human' ] ) ;
5051
5152 expect ( result ) . to . deep . equal ( testRunWithFailuresResult ) ;
5253 expect ( logStub . firstCall . args [ 0 ] ) . to . include ( '=== Test Summary' ) ;
5354 expect ( logStub . firstCall . args [ 0 ] ) . to . include ( '=== Test Results' ) ;
5455 expect ( logStub . firstCall . args [ 0 ] ) . to . include ( 'Test Run Id 707xx0000AUS2gH' ) ;
5556 expect ( logStub . firstCall . args [ 0 ] ) . to . include ( 'MyApexTests.testConfig Fail' ) ;
57+ expect ( uxStub . log . callCount ) . to . equal ( 0 ) ;
5658 } ) ;
5759
5860 it ( 'should return a success tap format message with async' , async ( ) => {
5961 sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( runWithFailures ) ;
6062
61- const result = await new Test ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'tap' ] , config ) . run ( ) ;
63+ const result = await Test . run ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'tap' ] ) ;
6264
6365 expect ( result ) . to . deep . equal ( testRunWithFailuresResult ) ;
6466 expect ( logStub . firstCall . args [ 0 ] ) . to . include ( '1..1' ) ;
@@ -68,7 +70,7 @@ describe('apex:test:report', () => {
6870
6971 it ( 'should return a success junit format message with async' , async ( ) => {
7072 sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( runWithFailures ) ;
71- const result = await new Test ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'junit' ] , config ) . run ( ) ;
73+ const result = await Test . run ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'junit' ] ) ;
7274 expect ( result ) . to . deep . equal ( testRunWithFailuresResult ) ;
7375 expect ( logStub . firstCall . args [ 0 ] ) . to . include ( '<property name="failRate" value="50%"/>' ) ;
7476 expect ( logStub . firstCall . args [ 0 ] ) . to . include ( '<property name="outcome" value="Failed"/>' ) ;
@@ -77,33 +79,30 @@ describe('apex:test:report', () => {
7779
7880 it ( 'should return a success json format message with async' , async ( ) => {
7981 sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( runWithFailures ) ;
80- const result = await new Test ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'json' ] , config ) . run ( ) ;
82+ const result = await Test . run ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'json' ] ) ;
8183 expect ( result ) . to . deep . equal ( testRunWithFailuresResult ) ;
8284 expect ( styledJsonStub . firstCall . args [ 0 ] ) . to . deep . equal ( { result : testRunWithFailuresResult , status : 100 } ) ;
8385 } ) ;
8486
8587 it ( 'should return a success --json format message with sync' , async ( ) => {
8688 sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( runWithFailures ) ;
8789 sandbox . stub ( Org . prototype , 'getUsername' ) . returns ( '[email protected] ' ) ; 88- const result = await new Test ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--json' ] , config ) . run ( ) ;
90+ const result = await Test . run ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--json' ] ) ;
8991 expect ( result ) . to . deep . equal ( testRunWithFailuresResult ) ;
9092 expect ( styledJsonStub . notCalled ) . to . be . true ;
9193 } ) ;
9294
9395 it ( 'should return a success human format with synchronous' , async ( ) => {
9496 sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( runWithFailures ) ;
95- await new Test ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'human' ] , config ) . run ( ) ;
97+ await Test . run ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'human' ] ) ;
9698 expect ( logStub . firstCall . args [ 0 ] ) . to . contain ( 'Test Summary' ) ;
9799 expect ( logStub . firstCall . args [ 0 ] ) . to . contain ( 'Test Results' ) ;
98100 expect ( logStub . firstCall . args [ 0 ] ) . to . not . contain ( 'Apex Code Coverage by Class' ) ;
99101 } ) ;
100102
101103 it ( 'should warn when using --outputdir' , async ( ) => {
102104 sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( runWithFailures ) ;
103- await new Test (
104- [ '--output-dir' , 'myDirectory' , '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'human' ] ,
105- config
106- ) . run ( ) ;
105+ await Test . run ( [ '--output-dir' , 'myDirectory' , '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'human' ] ) ;
107106 expect ( logStub . firstCall . args [ 0 ] ) . to . contain ( 'Test result files written to myDirectory' ) ;
108107 } ) ;
109108 } ) ;
@@ -112,7 +111,7 @@ describe('apex:test:report', () => {
112111 it ( 'should return a success human format message with async' , async ( ) => {
113112 sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( testRunSimple ) ;
114113
115- const result = await new Test ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'human' ] , config ) . run ( ) ;
114+ const result = await Test . run ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'human' ] ) ;
116115
117116 expect ( result ) . to . deep . equal ( testRunSimpleResult ) ;
118117 expect ( logStub . firstCall . args [ 0 ] ) . to . include ( '=== Test Summary' ) ;
@@ -124,7 +123,7 @@ describe('apex:test:report', () => {
124123 it ( 'should return a success tap format message with async' , async ( ) => {
125124 sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( testRunSimple ) ;
126125
127- const result = await new Test ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'tap' ] , config ) . run ( ) ;
126+ const result = await Test . run ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'tap' ] ) ;
128127
129128 expect ( result ) . to . deep . equal ( testRunSimpleResult ) ;
130129 expect ( logStub . firstCall . args [ 0 ] ) . to . include ( '1..1' ) ;
@@ -134,7 +133,7 @@ describe('apex:test:report', () => {
134133
135134 it ( 'should return a success junit format message with async' , async ( ) => {
136135 sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( testRunSimple ) ;
137- const result = await new Test ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'junit' ] , config ) . run ( ) ;
136+ const result = await Test . run ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'junit' ] ) ;
138137 expect ( result ) . to . deep . equal ( testRunSimpleResult ) ;
139138 expect ( logStub . firstCall . args [ 0 ] ) . to . contain ( '<testcase name="testConfig" classname="MyApexTests" time="0.05">' ) ;
140139 expect ( logStub . firstCall . args [ 0 ] ) . to . contain ( '<property name="testsRan" value="1"/>' ) ;
@@ -143,33 +142,30 @@ describe('apex:test:report', () => {
143142 it ( 'should return a success json format message with async' , async ( ) => {
144143 process . exitCode = 0 ;
145144 sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( testRunSimple ) ;
146- const result = await new Test ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'json' ] , config ) . run ( ) ;
145+ const result = await Test . run ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'json' ] ) ;
147146 expect ( result ) . to . deep . equal ( testRunSimpleResult ) ;
148147 expect ( styledJsonStub . firstCall . args [ 0 ] ) . to . deep . equal ( { result : testRunSimpleResult , status : 0 } ) ;
149148 } ) ;
150149
151150 it ( 'should return a success --json format message with sync' , async ( ) => {
152151 sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( testRunSimple ) ;
153152 sandbox . stub ( Org . prototype , 'getUsername' ) . returns ( '[email protected] ' ) ; 154- const result = await new Test ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--json' ] , config ) . run ( ) ;
153+ const result = await Test . run ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--json' ] ) ;
155154 expect ( result ) . to . deep . equal ( testRunSimpleResult ) ;
156155 expect ( styledJsonStub . notCalled ) . to . be . true ;
157156 } ) ;
158157
159158 it ( 'should return a success human format with synchronous' , async ( ) => {
160159 sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( testRunSimple ) ;
161- await new Test ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'human' ] , config ) . run ( ) ;
160+ await Test . run ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'human' ] ) ;
162161 expect ( logStub . firstCall . args [ 0 ] ) . to . contain ( 'Test Summary' ) ;
163162 expect ( logStub . firstCall . args [ 0 ] ) . to . contain ( 'Test Results' ) ;
164163 expect ( logStub . firstCall . args [ 0 ] ) . to . not . contain ( 'Apex Code Coverage by Class' ) ;
165164 } ) ;
166165
167166 it ( 'should warn when using --outputdir' , async ( ) => {
168167 sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( testRunSimple ) ;
169- await new Test (
170- [ '--output-dir' , 'myDirectory' , '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'human' ] ,
171- config
172- ) . run ( ) ;
168+ await Test . run ( [ '--output-dir' , 'myDirectory' , '--test-run-id' , '707xxxxxxxxxxxx' , '--result-format' , 'human' ] ) ;
173169 expect ( logStub . firstCall . args [ 0 ] ) . to . contain ( 'Test result files written to myDirectory' ) ;
174170 } ) ;
175171 } ) ;
0 commit comments