7
7
import fs from 'node:fs' ;
8
8
import { Connection , Org } from '@salesforce/core' ;
9
9
import 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' ;
13
12
import { TestService } from '@salesforce/apex-node' ;
14
13
import Test from '../../../../src/commands/apex/get/test.js' ;
15
14
import { runWithFailures , testRunSimple , testRunSimpleResult , testRunWithFailuresResult } from '../../../testData.js' ;
16
15
16
+ config . truncateThreshold = 0 ;
17
+
17
18
let logStub : sinon . SinonStub ;
18
19
let styledJsonStub : sinon . SinonStub ;
19
20
20
21
describe ( 'apex:test:report' , ( ) => {
21
22
let sandbox : sinon . SinonSandbox ;
22
- let config : Config ;
23
+ let uxStub : ReturnType < typeof stubSfCommandUx > ;
23
24
24
25
beforeEach ( async ( ) => {
25
- config = await Config . load ( import . meta. url ) ;
26
26
sandbox = sinon . createSandbox ( ) ;
27
+ uxStub = stubSfCommandUx ( sandbox ) ;
27
28
logStub = sandbox . stub ( Ux . prototype , 'log' ) ;
28
29
styledJsonStub = sandbox . stub ( Ux . prototype , 'styledJSON' ) ;
29
30
sandbox . stub ( Connection . prototype , 'getUsername' ) . returns ( 'test@example.com' ) ;
@@ -46,19 +47,20 @@ describe('apex:test:report', () => {
46
47
it ( 'should return a success human format message with async' , async ( ) => {
47
48
sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( runWithFailures ) ;
48
49
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' ] ) ;
50
51
51
52
expect ( result ) . to . deep . equal ( testRunWithFailuresResult ) ;
52
53
expect ( logStub . firstCall . args [ 0 ] ) . to . include ( '=== Test Summary' ) ;
53
54
expect ( logStub . firstCall . args [ 0 ] ) . to . include ( '=== Test Results' ) ;
54
55
expect ( logStub . firstCall . args [ 0 ] ) . to . include ( 'Test Run Id 707xx0000AUS2gH' ) ;
55
56
expect ( logStub . firstCall . args [ 0 ] ) . to . include ( 'MyApexTests.testConfig Fail' ) ;
57
+ expect ( uxStub . log . callCount ) . to . equal ( 0 ) ;
56
58
} ) ;
57
59
58
60
it ( 'should return a success tap format message with async' , async ( ) => {
59
61
sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( runWithFailures ) ;
60
62
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' ] ) ;
62
64
63
65
expect ( result ) . to . deep . equal ( testRunWithFailuresResult ) ;
64
66
expect ( logStub . firstCall . args [ 0 ] ) . to . include ( '1..1' ) ;
@@ -68,7 +70,7 @@ describe('apex:test:report', () => {
68
70
69
71
it ( 'should return a success junit format message with async' , async ( ) => {
70
72
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' ] ) ;
72
74
expect ( result ) . to . deep . equal ( testRunWithFailuresResult ) ;
73
75
expect ( logStub . firstCall . args [ 0 ] ) . to . include ( '<property name="failRate" value="50%"/>' ) ;
74
76
expect ( logStub . firstCall . args [ 0 ] ) . to . include ( '<property name="outcome" value="Failed"/>' ) ;
@@ -77,33 +79,30 @@ describe('apex:test:report', () => {
77
79
78
80
it ( 'should return a success json format message with async' , async ( ) => {
79
81
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' ] ) ;
81
83
expect ( result ) . to . deep . equal ( testRunWithFailuresResult ) ;
82
84
expect ( styledJsonStub . firstCall . args [ 0 ] ) . to . deep . equal ( { result : testRunWithFailuresResult , status : 100 } ) ;
83
85
} ) ;
84
86
85
87
it ( 'should return a success --json format message with sync' , async ( ) => {
86
88
sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( runWithFailures ) ;
87
89
sandbox . stub ( Org . prototype , 'getUsername' ) . returns ( 'test@user.com' ) ;
88
- const result = await new Test ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--json' ] , config ) . run ( ) ;
90
+ const result = await Test . run ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--json' ] ) ;
89
91
expect ( result ) . to . deep . equal ( testRunWithFailuresResult ) ;
90
92
expect ( styledJsonStub . notCalled ) . to . be . true ;
91
93
} ) ;
92
94
93
95
it ( 'should return a success human format with synchronous' , async ( ) => {
94
96
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' ] ) ;
96
98
expect ( logStub . firstCall . args [ 0 ] ) . to . contain ( 'Test Summary' ) ;
97
99
expect ( logStub . firstCall . args [ 0 ] ) . to . contain ( 'Test Results' ) ;
98
100
expect ( logStub . firstCall . args [ 0 ] ) . to . not . contain ( 'Apex Code Coverage by Class' ) ;
99
101
} ) ;
100
102
101
103
it ( 'should warn when using --outputdir' , async ( ) => {
102
104
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' ] ) ;
107
106
expect ( logStub . firstCall . args [ 0 ] ) . to . contain ( 'Test result files written to myDirectory' ) ;
108
107
} ) ;
109
108
} ) ;
@@ -112,7 +111,7 @@ describe('apex:test:report', () => {
112
111
it ( 'should return a success human format message with async' , async ( ) => {
113
112
sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( testRunSimple ) ;
114
113
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' ] ) ;
116
115
117
116
expect ( result ) . to . deep . equal ( testRunSimpleResult ) ;
118
117
expect ( logStub . firstCall . args [ 0 ] ) . to . include ( '=== Test Summary' ) ;
@@ -124,7 +123,7 @@ describe('apex:test:report', () => {
124
123
it ( 'should return a success tap format message with async' , async ( ) => {
125
124
sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( testRunSimple ) ;
126
125
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' ] ) ;
128
127
129
128
expect ( result ) . to . deep . equal ( testRunSimpleResult ) ;
130
129
expect ( logStub . firstCall . args [ 0 ] ) . to . include ( '1..1' ) ;
@@ -134,7 +133,7 @@ describe('apex:test:report', () => {
134
133
135
134
it ( 'should return a success junit format message with async' , async ( ) => {
136
135
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' ] ) ;
138
137
expect ( result ) . to . deep . equal ( testRunSimpleResult ) ;
139
138
expect ( logStub . firstCall . args [ 0 ] ) . to . contain ( '<testcase name="testConfig" classname="MyApexTests" time="0.05">' ) ;
140
139
expect ( logStub . firstCall . args [ 0 ] ) . to . contain ( '<property name="testsRan" value="1"/>' ) ;
@@ -143,33 +142,30 @@ describe('apex:test:report', () => {
143
142
it ( 'should return a success json format message with async' , async ( ) => {
144
143
process . exitCode = 0 ;
145
144
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' ] ) ;
147
146
expect ( result ) . to . deep . equal ( testRunSimpleResult ) ;
148
147
expect ( styledJsonStub . firstCall . args [ 0 ] ) . to . deep . equal ( { result : testRunSimpleResult , status : 0 } ) ;
149
148
} ) ;
150
149
151
150
it ( 'should return a success --json format message with sync' , async ( ) => {
152
151
sandbox . stub ( TestService . prototype , 'reportAsyncResults' ) . resolves ( testRunSimple ) ;
153
152
sandbox . stub ( Org . prototype , 'getUsername' ) . returns ( 'test@user.com' ) ;
154
- const result = await new Test ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--json' ] , config ) . run ( ) ;
153
+ const result = await Test . run ( [ '--test-run-id' , '707xxxxxxxxxxxx' , '--json' ] ) ;
155
154
expect ( result ) . to . deep . equal ( testRunSimpleResult ) ;
156
155
expect ( styledJsonStub . notCalled ) . to . be . true ;
157
156
} ) ;
158
157
159
158
it ( 'should return a success human format with synchronous' , async ( ) => {
160
159
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' ] ) ;
162
161
expect ( logStub . firstCall . args [ 0 ] ) . to . contain ( 'Test Summary' ) ;
163
162
expect ( logStub . firstCall . args [ 0 ] ) . to . contain ( 'Test Results' ) ;
164
163
expect ( logStub . firstCall . args [ 0 ] ) . to . not . contain ( 'Apex Code Coverage by Class' ) ;
165
164
} ) ;
166
165
167
166
it ( 'should warn when using --outputdir' , async ( ) => {
168
167
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' ] ) ;
173
169
expect ( logStub . firstCall . args [ 0 ] ) . to . contain ( 'Test result files written to myDirectory' ) ;
174
170
} ) ;
175
171
} ) ;
0 commit comments