44 * Licensed under the BSD 3-Clause license.
55 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66 */
7- import { $$ , expect , test } from '@salesforce/command/lib/test' ;
7+ import { expect , test } from '@salesforce/command/lib/test' ;
88import { Org , MyDomainResolver , Messages } from '@salesforce/core' ;
9+ import * as sinon from 'sinon' ;
910import { stubMethod } from '@salesforce/ts-sinon' ;
1011import * as utils from '../../../../src/shared/utils' ;
1112
@@ -30,20 +31,23 @@ const testJsonStructure = (response: Record<string, unknown>) => {
3031} ;
3132
3233describe ( 'open commands' , ( ) => {
34+ const sandbox = sinon . createSandbox ( ) ;
3335 const spies = new Map ( ) ;
3436 afterEach ( ( ) => spies . clear ( ) ) ;
3537
3638 beforeEach ( async function ( ) {
37- $$ . SANDBOX . restore ( ) ;
38- stubMethod ( $$ . SANDBOX , Org , 'create' ) . resolves ( Org . prototype ) ;
39- stubMethod ( $$ . SANDBOX , Org . prototype , 'getField' ) . withArgs ( Org . Fields . INSTANCE_URL ) . returns ( testInstance ) ;
40- stubMethod ( $$ . SANDBOX , Org . prototype , 'refreshAuth' ) . resolves ( { } ) ;
41- stubMethod ( $$ . SANDBOX , Org . prototype , 'getOrgId' ) . returns ( orgId ) ;
42- stubMethod ( $$ . SANDBOX , Org . prototype , 'getUsername' ) . returns ( username ) ;
43- stubMethod ( $$ . SANDBOX , Org . prototype , 'getConnection' ) . returns ( {
39+ stubMethod ( sandbox , Org , 'create' ) . resolves ( Org . prototype ) ;
40+ stubMethod ( sandbox , Org . prototype , 'getField' ) . withArgs ( Org . Fields . INSTANCE_URL ) . returns ( testInstance ) ;
41+ stubMethod ( sandbox , Org . prototype , 'refreshAuth' ) . resolves ( { } ) ;
42+ stubMethod ( sandbox , Org . prototype , 'getOrgId' ) . returns ( orgId ) ;
43+ stubMethod ( sandbox , Org . prototype , 'getUsername' ) . returns ( username ) ;
44+ stubMethod ( sandbox , Org . prototype , 'getConnection' ) . returns ( {
4445 accessToken,
4546 } ) ;
46- spies . set ( 'open' , stubMethod ( $$ . SANDBOX , utils , 'openUrl' ) . resolves ( ) ) ;
47+ spies . set ( 'open' , stubMethod ( sandbox , utils , 'openUrl' ) . resolves ( ) ) ;
48+ } ) ;
49+ afterEach ( ( ) => {
50+ sandbox . restore ( ) ;
4751 } ) ;
4852
4953 describe ( 'url generation' , ( ) => {
@@ -88,11 +92,11 @@ describe('open commands', () => {
8892
8993 describe ( 'domain resolution, with callout' , ( ) => {
9094 beforeEach ( ( ) => {
91- stubMethod ( $$ . SANDBOX , MyDomainResolver , 'create' ) . resolves ( MyDomainResolver . prototype ) ;
95+ stubMethod ( sandbox , MyDomainResolver , 'create' ) . resolves ( MyDomainResolver . prototype ) ;
9296 } ) ;
9397 test
9498 . do ( ( ) => {
95- spies . set ( 'resolver' , stubMethod ( $$ . SANDBOX , MyDomainResolver . prototype , 'resolve' ) . resolves ( '1.1.1.1' ) ) ;
99+ spies . set ( 'resolver' , stubMethod ( sandbox , MyDomainResolver . prototype , 'resolve' ) . resolves ( '1.1.1.1' ) ) ;
96100 } )
97101 . stdout ( )
98102 . command ( [ 'force:org:open' , '--json' , '--targetusername' , username , '--path' , testPath ] )
@@ -109,7 +113,7 @@ describe('open commands', () => {
109113 . do ( ( ) => {
110114 spies . set (
111115 'resolver' ,
112- stubMethod ( $$ . SANDBOX , MyDomainResolver . prototype , 'resolve' ) . throws ( { message : 'timeout' } )
116+ stubMethod ( sandbox , MyDomainResolver . prototype , 'resolve' ) . throws ( { message : 'timeout' } )
113117 ) ;
114118 } )
115119 . stdout ( )
@@ -125,8 +129,8 @@ describe('open commands', () => {
125129
126130 describe ( 'domain resolution, no callout' , ( ) => {
127131 beforeEach ( ( ) => {
128- stubMethod ( $$ . SANDBOX , MyDomainResolver , 'create' ) . resolves ( MyDomainResolver . prototype ) ;
129- spies . set ( 'resolver' , stubMethod ( $$ . SANDBOX , MyDomainResolver . prototype , 'resolve' ) . resolves ( '1.1.1.1' ) ) ;
132+ stubMethod ( sandbox , MyDomainResolver , 'create' ) . resolves ( MyDomainResolver . prototype ) ;
133+ spies . set ( 'resolver' , stubMethod ( sandbox , MyDomainResolver . prototype , 'resolve' ) . resolves ( '1.1.1.1' ) ) ;
130134 } ) ;
131135 it ( 'does not wait for domains on internal urls' ) ;
132136
@@ -168,7 +172,7 @@ describe('open commands', () => {
168172 describe ( 'human output' , ( ) => {
169173 test
170174 . do ( ( ) => {
171- spies . set ( 'resolver' , stubMethod ( $$ . SANDBOX , MyDomainResolver . prototype , 'resolve' ) . resolves ( '1.1.1.1' ) ) ;
175+ spies . set ( 'resolver' , stubMethod ( sandbox , MyDomainResolver . prototype , 'resolve' ) . resolves ( '1.1.1.1' ) ) ;
172176 } )
173177 . stdout ( )
174178 . command ( [ 'force:org:open' , '--targetusername' , username , '--path' , testPath ] )
@@ -180,7 +184,7 @@ describe('open commands', () => {
180184
181185 test
182186 . do ( ( ) => {
183- spies . set ( 'resolver' , stubMethod ( $$ . SANDBOX , MyDomainResolver . prototype , 'resolve' ) . resolves ( '1.1.1.1' ) ) ;
187+ spies . set ( 'resolver' , stubMethod ( sandbox , MyDomainResolver . prototype , 'resolve' ) . resolves ( '1.1.1.1' ) ) ;
184188 } )
185189 . stdout ( )
186190 . command ( [ 'force:org:open' , '--targetusername' , username , '--path' , testPath , '--urlonly' ] )
@@ -192,7 +196,7 @@ describe('open commands', () => {
192196 . do ( ( ) => {
193197 spies . set (
194198 'resolver' ,
195- stubMethod ( $$ . SANDBOX , MyDomainResolver . prototype , 'resolve' ) . throws ( { message : 'timeout' } )
199+ stubMethod ( sandbox , MyDomainResolver . prototype , 'resolve' ) . throws ( { message : 'timeout' } )
196200 ) ;
197201 } )
198202 . stderr ( )
@@ -207,7 +211,7 @@ describe('open commands', () => {
207211 describe ( 'browser argument' , ( ) => {
208212 test
209213 . do ( ( ) => {
210- spies . set ( 'resolver' , stubMethod ( $$ . SANDBOX , MyDomainResolver . prototype , 'resolve' ) . resolves ( '1.1.1.1' ) ) ;
214+ spies . set ( 'resolver' , stubMethod ( sandbox , MyDomainResolver . prototype , 'resolve' ) . resolves ( '1.1.1.1' ) ) ;
211215 } )
212216 . stdout ( )
213217 . command ( [ 'force:org:open' , '--targetusername' , username , '--path' , testPath ] )
@@ -219,7 +223,7 @@ describe('open commands', () => {
219223
220224 test
221225 . do ( ( ) => {
222- spies . set ( 'resolver' , stubMethod ( $$ . SANDBOX , MyDomainResolver . prototype , 'resolve' ) . resolves ( '1.1.1.1' ) ) ;
226+ spies . set ( 'resolver' , stubMethod ( sandbox , MyDomainResolver . prototype , 'resolve' ) . resolves ( '1.1.1.1' ) ) ;
223227 } )
224228 . stdout ( )
225229 . command ( [ 'force:org:open' , '--targetusername' , username , '--path' , testPath , '-b' , testBrowser ] )
@@ -231,7 +235,7 @@ describe('open commands', () => {
231235
232236 test
233237 . do ( ( ) => {
234- spies . set ( 'resolver' , stubMethod ( $$ . SANDBOX , MyDomainResolver . prototype , 'resolve' ) . resolves ( '1.1.1.1' ) ) ;
238+ spies . set ( 'resolver' , stubMethod ( sandbox , MyDomainResolver . prototype , 'resolve' ) . resolves ( '1.1.1.1' ) ) ;
235239 } )
236240 . stdout ( )
237241 . command ( [ 'force:org:open' , '--targetusername' , username , '--path' , testPath , '-b' , 'duff' ] )
0 commit comments