@@ -14,6 +14,18 @@ import {loadWasmBinary} from "./utils";
1414const CLI_PACKAGE = 'scw'
1515const CLI_CALLBACK = 'cliLoaded'
1616
17+ const emptyConfig = (
18+ override ?: {
19+ jwt ?: string ,
20+ defaultProjectID ?: string ,
21+ defaultOrganizationID ?: string
22+ }
23+ ) : RunConfig => ( {
24+ jwt : override ?. jwt || "" ,
25+ defaultProjectID : override ?. defaultProjectID || "" ,
26+ defaultOrganizationID : override ?. defaultOrganizationID || "" ,
27+ } )
28+
1729describe ( 'With wasm CLI' , async ( ) => {
1830 let cli : CLI
1931
@@ -24,10 +36,7 @@ describe('With wasm CLI', async () => {
2436
2537 const run = async ( expected : string | RegExp , command : string [ ] , runCfg : RunConfig | null = null ) => {
2638 if ( runCfg === null ) {
27- runCfg = {
28- jwt : "" ,
29- defaultProjectID : ""
30- }
39+ runCfg = emptyConfig ( )
3140 }
3241
3342 const resp = await cli . run ( runCfg , command )
@@ -37,10 +46,7 @@ describe('With wasm CLI', async () => {
3746
3847 const runWithError = async ( expected : string | RegExp , command : string [ ] , runCfg : RunConfig | null = null ) => {
3948 if ( runCfg === null ) {
40- runCfg = {
41- jwt : "" ,
42- defaultProjectID : "" ,
43- }
49+ runCfg = emptyConfig ( )
4450 }
4551 const resp = await cli . run ( runCfg , command )
4652 expect ( resp . exitCode ) . toBeGreaterThan ( 0 )
@@ -49,10 +55,7 @@ describe('With wasm CLI', async () => {
4955
5056 const complete = async ( expected : string [ ] , command : string [ ] , runCfg : RunConfig | null = null ) => {
5157 if ( runCfg === null ) {
52- runCfg = {
53- jwt : "" ,
54- defaultProjectID : ""
55- }
58+ runCfg = emptyConfig ( )
5659 }
5760 let toComplete = command . pop ( ) || ""
5861
@@ -74,25 +77,19 @@ describe('With wasm CLI', async () => {
7477 it ( 'can complete' , async ( ) => complete ( [ 'server' , 'image' , 'volume' ] , [ 'instance' , '' ] ) )
7578
7679 it ( 'can configure terminal size' , async ( ) => {
77- const runCfg = {
78- jwt : "" ,
79- defaultProjectID : ""
80- }
80+ const runCfg = emptyConfig ( )
8181
8282 await cli . configureOutput ( { width : 100 , color : false } )
8383 const resp = await cli . run ( runCfg , [ 'marketplace' , 'image' , 'list' ] )
84- console . log ( resp )
8584 expect ( resp . exitCode ) . toBe ( 0 )
85+
8686 const lines = resp . stdout . split ( "\n" )
8787 expect ( lines . length ) . toBeGreaterThan ( 1 )
8888 expect ( lines [ 2 ] . length ) . toBeLessThan ( 100 )
8989 } )
9090
9191 it ( 'can enable colors' , async ( ) => {
92- const runCfg = {
93- jwt : "" ,
94- defaultProjectID : ""
95- }
92+ const runCfg = emptyConfig ( )
9693
9794 await cli . configureOutput ( { width : 100 , color : false } )
9895 const resp = await cli . run ( runCfg , [ 'invalid' ] )
0 commit comments