@@ -8,7 +8,7 @@ import { basename, join, sep } from 'node:path';
8
8
import { MockTestOrgData , TestContext } from '@salesforce/core/testSetup' ;
9
9
import chai , { assert , expect } from 'chai' ;
10
10
import { AnyJson , ensureString , getString } from '@salesforce/ts-types' ;
11
- import { Lifecycle , Messages , PollingClient , StatusResult } from '@salesforce/core' ;
11
+ import { envVars , Lifecycle , Messages , PollingClient , StatusResult } from '@salesforce/core' ;
12
12
import { Duration } from '@salesforce/kit' ;
13
13
import deepEqualInAnyOrder = require( 'deep-equal-in-any-order' ) ;
14
14
import {
@@ -144,6 +144,99 @@ describe('MetadataApiDeploy', () => {
144
144
145
145
expect ( operation . id ) . to . deep . equal ( response . id ) ;
146
146
} ) ;
147
+
148
+ it ( 'should call warnIfDeployThresholdExceeded' , async ( ) => {
149
+ const component = matchingContentFile . COMPONENT ;
150
+ const deployedComponents = new ComponentSet ( [ component ] ) ;
151
+ const { operation, response } = await stubMetadataDeploy ( $$ , testOrg , {
152
+ components : deployedComponents ,
153
+ } ) ;
154
+ // @ts -expect-error stubbing private method
155
+ const warnStub = $$ . SANDBOX . spy ( operation , 'warnIfDeployThresholdExceeded' ) ;
156
+
157
+ await operation . start ( ) ;
158
+
159
+ expect ( operation . id ) . to . deep . equal ( response . id ) ;
160
+ expect ( warnStub . callCount ) . to . equal ( 1 , 'warnIfDeployThresholdExceeded() should have been called' ) ;
161
+ // 4 is the expected byte size (zipBuffer is set to '1234')
162
+ // undefined is expected since we're not computing the number of files in the zip
163
+ expect ( warnStub . firstCall . args ) . to . deep . equal ( [ 4 , undefined ] ) ;
164
+ } ) ;
165
+ } ) ;
166
+
167
+ describe ( 'warnIfDeployThresholdExceeded' , ( ) => {
168
+ let emitWarningStub : sinon . SinonStub ;
169
+
170
+ beforeEach ( ( ) => {
171
+ emitWarningStub = $$ . SANDBOX . stub ( Lifecycle . prototype , 'emitWarning' ) . resolves ( ) ;
172
+ } ) ;
173
+
174
+ it ( 'should emit warning with default threshold when zipSize > 80%' , async ( ) => {
175
+ const loggerDebugSpy = $$ . SANDBOX . spy ( $$ . TEST_LOGGER , 'debug' ) ;
176
+ const mdapThis = { logger : $$ . TEST_LOGGER } ;
177
+ // @ts -expect-error testing private method
178
+ await MetadataApiDeploy . prototype . warnIfDeployThresholdExceeded . call ( mdapThis , 31_200_001 , 8000 ) ;
179
+ expect ( emitWarningStub . calledOnce , 'emitWarning for fileSize should have been called' ) . to . be . true ;
180
+ const warningMsg =
181
+ 'Deployment zip file size is approaching the Metadata API limit (~39MB). Warning threshold is 80%' ;
182
+ expect ( emitWarningStub . firstCall . args [ 0 ] ) . to . include ( warningMsg ) ;
183
+ expect ( loggerDebugSpy . called ) . to . be . false ;
184
+ } ) ;
185
+
186
+ it ( 'should emit warning with default threshold when zipFileCount > 80%' , async ( ) => {
187
+ const loggerDebugSpy = $$ . SANDBOX . spy ( $$ . TEST_LOGGER , 'debug' ) ;
188
+ const mdapThis = { logger : $$ . TEST_LOGGER } ;
189
+ // @ts -expect-error testing private method
190
+ await MetadataApiDeploy . prototype . warnIfDeployThresholdExceeded . call ( mdapThis , 31_200_000 , 8001 ) ;
191
+ expect ( emitWarningStub . calledOnce , 'emitWarning for fileSize should have been called' ) . to . be . true ;
192
+ const warningMsg =
193
+ 'Deployment zip file count is approaching the Metadata API limit (10,000). Warning threshold is 80%' ;
194
+ expect ( emitWarningStub . firstCall . args [ 0 ] ) . to . include ( warningMsg ) ;
195
+ expect ( loggerDebugSpy . called ) . to . be . false ;
196
+ } ) ;
197
+
198
+ it ( 'should not emit warning but log debug output when threshold >= 100%' , async ( ) => {
199
+ const loggerDebugSpy = $$ . SANDBOX . spy ( $$ . TEST_LOGGER , 'debug' ) ;
200
+ $$ . SANDBOX . stub ( envVars , 'getNumber' ) . returns ( 100 ) ;
201
+ const mdapThis = { logger : $$ . TEST_LOGGER } ;
202
+ // @ts -expect-error testing private method
203
+ await MetadataApiDeploy . prototype . warnIfDeployThresholdExceeded . call ( mdapThis , 310_200_000 , 12_000 ) ;
204
+ expect ( emitWarningStub . called ) . to . be . false ;
205
+ expect ( loggerDebugSpy . calledOnce ) . to . be . true ;
206
+ const expectedMsg = 'Deploy size warning is disabled since SF_DEPLOY_SIZE_THRESHOLD is overridden to: 100' ;
207
+ expect ( loggerDebugSpy . firstCall . args [ 0 ] ) . to . equal ( expectedMsg ) ;
208
+ } ) ;
209
+
210
+ it ( 'should emit warnings and log debug output with exceeded overridden threshold' , async ( ) => {
211
+ const loggerDebugSpy = $$ . SANDBOX . spy ( $$ . TEST_LOGGER , 'debug' ) ;
212
+ $$ . SANDBOX . stub ( envVars , 'getNumber' ) . returns ( 75 ) ;
213
+ const mdapThis = { logger : $$ . TEST_LOGGER } ;
214
+ // @ts -expect-error testing private method
215
+ await MetadataApiDeploy . prototype . warnIfDeployThresholdExceeded . call ( mdapThis , 29_250_001 , 7501 ) ;
216
+ expect ( emitWarningStub . calledTwice , 'emitWarning for fileSize and fileCount should have been called' ) . to . be
217
+ . true ;
218
+ const fileSizeWarningMsg =
219
+ 'Deployment zip file size is approaching the Metadata API limit (~39MB). Warning threshold is 75%' ;
220
+ const fileCountWarningMsg =
221
+ 'Deployment zip file count is approaching the Metadata API limit (10,000). Warning threshold is 75%' ;
222
+ expect ( emitWarningStub . firstCall . args [ 0 ] ) . to . include ( fileSizeWarningMsg ) ;
223
+ expect ( emitWarningStub . secondCall . args [ 0 ] ) . to . include ( fileCountWarningMsg ) ;
224
+ expect ( loggerDebugSpy . calledOnce ) . to . be . true ;
225
+ const expectedMsg = 'Deploy size warning threshold has been overridden by SF_DEPLOY_SIZE_THRESHOLD to: 75' ;
226
+ expect ( loggerDebugSpy . firstCall . args [ 0 ] ) . to . equal ( expectedMsg ) ;
227
+ } ) ;
228
+
229
+ it ( 'should NOT emit warnings but log debug output with overridden threshold that is not exceeded' , async ( ) => {
230
+ const loggerDebugSpy = $$ . SANDBOX . spy ( $$ . TEST_LOGGER , 'debug' ) ;
231
+ $$ . SANDBOX . stub ( envVars , 'getNumber' ) . returns ( 75 ) ;
232
+ const mdapThis = { logger : $$ . TEST_LOGGER } ;
233
+ // @ts -expect-error testing private method
234
+ await MetadataApiDeploy . prototype . warnIfDeployThresholdExceeded . call ( mdapThis , 29_250_000 , 7500 ) ;
235
+ expect ( emitWarningStub . called , 'emitWarning should not have been called' ) . to . be . false ;
236
+ expect ( loggerDebugSpy . calledOnce ) . to . be . true ;
237
+ const expectedMsg = 'Deploy size warning threshold has been overridden by SF_DEPLOY_SIZE_THRESHOLD to: 75' ;
238
+ expect ( loggerDebugSpy . firstCall . args [ 0 ] ) . to . equal ( expectedMsg ) ;
239
+ } ) ;
147
240
} ) ;
148
241
149
242
describe ( 'pollStatus' , ( ) => {
0 commit comments