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 * as fs from 'fs' ;
87import { Org , Aliases , Config , ConfigAggregator , Lifecycle , SandboxEvents } from '@salesforce/core' ;
98import { fromStub , stubInterface , stubMethod } from '@salesforce/ts-sinon' ;
109import * as sinon from 'sinon' ;
@@ -66,7 +65,7 @@ describe('org:clone', () => {
6665 let configSetStub : sinon . SinonStub ;
6766 let configWriteStub : sinon . SinonStub ;
6867 let onStub : sinon . SinonStub ;
69- let readFileSyncStub : sinon . SinonStub ;
68+ let readJsonDefFileStub : sinon . SinonStub ;
7069 let cloneSandboxStub : sinon . SinonStub ;
7170 let configAggregatorStub ;
7271
@@ -115,7 +114,10 @@ describe('org:clone', () => {
115114 . callsArgWith ( 1 , statusEvent )
116115 . callsArgWith ( 1 , resultObject ) ;
117116 } else {
118- onStub = sandbox . stub ( ) . resolves ( true ) ;
117+ onStub = sandbox . stub ( ) . callsFake ( ( event , cb ) => {
118+ expect ( event ) . to . exist ;
119+ expect ( cb ) . to . be . a ( 'function' ) ;
120+ } ) ;
119121 }
120122 stubMethod ( sandbox , Lifecycle , 'getInstance' ) . returns ( {
121123 on : onStub ,
@@ -124,15 +126,16 @@ describe('org:clone', () => {
124126 uxTableStub = stubMethod ( sandbox , UX . prototype , 'table' ) ;
125127 uxLogStub = stubMethod ( sandbox , UX . prototype , 'log' ) ;
126128 uxStyledHeaderStub = stubMethod ( sandbox , UX . prototype , 'styledHeader' ) ;
127- readFileSyncStub = stubMethod ( sandbox , fs , 'readFileSync ' ) . returns ( JSON . stringify ( defFile ) ) ;
128- return cmd . runIt ( ) ;
129+ readJsonDefFileStub = stubMethod ( sandbox , cmd , 'readJsonDefFile ' ) . returns ( defFile ) ;
130+ return cmd ;
129131 } ;
130132
131133 it ( 'will return sandbox process object' , async ( ) => {
132- const res = await runCloneCommand ( [ '-t' , 'sandbox' , '-u' , 'DevHub' , '-f' , 'sandbox-def.json' ] ) ;
134+ const commmand = await runCloneCommand ( [ '-t' , 'sandbox' , '-u' , 'DevHub' , '-f' , 'sandbox-def.json' ] ) ;
135+ const res = await commmand . runIt ( ) ;
133136 expect ( uxStyledHeaderStub . calledOnce ) . to . be . true ;
134137 expect ( uxTableStub . firstCall . args [ 0 ] . length ) . to . be . equal ( 12 ) ;
135- expect ( readFileSyncStub . calledOnce ) . to . be . true ;
138+ expect ( readJsonDefFileStub . calledOnce ) . to . be . true ;
136139 expect ( uxLogStub . callCount ) . to . be . equal ( 3 ) ;
137140 expect ( aliasSetStub . callCount ) . to . be . equal ( 0 ) ;
138141 expect ( configSetStub . callCount ) . to . be . equal ( 0 ) ;
@@ -150,7 +153,7 @@ describe('org:clone', () => {
150153
151154 it ( 'will return sandbox process object varargs override defFile' , async ( ) => {
152155 const licenseType = 'Enterprise' ;
153- const res = await runCloneCommand ( [
156+ const commmand = await runCloneCommand ( [
154157 '-t' ,
155158 'sandbox' ,
156159 '-u' ,
@@ -159,9 +162,10 @@ describe('org:clone', () => {
159162 'sandbox-def.json' ,
160163 `licenseType=${ licenseType } ` ,
161164 ] ) ;
165+ const res = await commmand . runIt ( ) ;
162166 expect ( uxStyledHeaderStub . calledOnce ) . to . be . true ;
163167 expect ( uxTableStub . firstCall . args [ 0 ] . length ) . to . be . equal ( 12 ) ;
164- expect ( readFileSyncStub . calledOnce ) . to . be . true ;
168+ expect ( readJsonDefFileStub . calledOnce ) . to . be . true ;
165169 expect ( uxLogStub . callCount ) . to . be . equal ( 3 ) ;
166170 expect ( aliasSetStub . callCount ) . to . be . equal ( 0 ) ;
167171 expect ( configSetStub . callCount ) . to . be . equal ( 0 ) ;
@@ -178,7 +182,7 @@ describe('org:clone', () => {
178182 } ) ;
179183
180184 it ( 'will set alias and default username' , async ( ) => {
181- const res = await runCloneCommand ( [
185+ const commmand = await runCloneCommand ( [
182186 '-t' ,
183187 'sandbox' ,
184188 '-u' ,
@@ -189,9 +193,10 @@ describe('org:clone', () => {
189193 sandboxalias ,
190194 '-s' ,
191195 ] ) ;
196+ const res = await commmand . runIt ( ) ;
192197 expect ( uxStyledHeaderStub . calledOnce ) . to . be . true ;
193198 expect ( uxTableStub . firstCall . args [ 0 ] . length ) . to . be . equal ( 12 ) ;
194- expect ( readFileSyncStub . calledOnce ) . to . be . true ;
199+ expect ( readJsonDefFileStub . calledOnce ) . to . be . true ;
195200 expect ( uxLogStub . callCount ) . to . be . equal ( 3 ) ;
196201 expect ( aliasSetStub . callCount ) . to . be . equal ( 1 ) ;
197202 expect ( aliasSetStub . firstCall . args [ 0 ] ) . to . be . equal ( sandboxalias ) ;
@@ -212,15 +217,16 @@ describe('org:clone', () => {
212217
213218 it ( 'cloneSandbox fails and wont set alias or default username' , async ( ) => {
214219 try {
215- await runCloneCommand (
220+ const commmand = await runCloneCommand (
216221 [ '-t' , 'sandbox' , '-u' , 'DevHub' , '-f' , 'sandbox-def.json' , '-a' , sandboxalias , '-s' ] ,
217222 true
218223 ) ;
224+ await commmand . runIt ( ) ;
219225 sinon . assert . fail ( 'the above should throw an error' ) ;
220226 } catch ( e ) {
221227 expect ( uxStyledHeaderStub . calledOnce ) . to . be . false ;
222228 expect ( uxTableStub . calledOnce ) . to . be . false ;
223- expect ( readFileSyncStub . calledOnce ) . to . be . true ;
229+ expect ( readJsonDefFileStub . calledOnce ) . to . be . true ;
224230 expect ( uxLogStub . callCount ) . to . be . equal ( 0 ) ;
225231 expect ( aliasSetStub . callCount ) . to . be . equal ( 0 ) ;
226232 expect ( configSetStub . callCount ) . to . be . equal ( 0 ) ;
0 commit comments