@@ -10,12 +10,13 @@ import * as fs from 'node:fs/promises';
1010import path from 'node:path' ;
1111import { fileURLToPath } from 'node:url' ;
1212import { getSharedContext , hasSharedSandbox } from './shared-context.js' ;
13+ import { getSandboxId , getHostname , parseJSONOutput , runCLIWithRetry , TIMEOUTS , toString } from './test-utils.js' ;
1314
1415const __filename = fileURLToPath ( import . meta. url ) ;
1516const __dirname = path . dirname ( __filename ) ;
1617
1718describe ( 'Code Lifecycle E2E Tests' , function ( ) {
18- this . timeout ( 900_000 ) ;
19+ this . timeout ( TIMEOUTS . CODE_DEPLOY * 3 ) ; // 15 minutes
1920 this . retries ( 2 ) ;
2021
2122 const CLI_BIN = path . resolve ( __dirname , '../../../bin/run.js' ) ;
@@ -42,33 +43,25 @@ describe('Code Lifecycle E2E Tests', function () {
4243 } else {
4344 // Fallback: Create own sandbox
4445 console . log ( 'No shared sandbox available, creating dedicated sandbox for Code tests...' ) ;
45- this . timeout ( 720_000 ) ; // 12 minutes for sandbox creation
46+ this . timeout ( TIMEOUTS . ODS_OPERATION ) ;
4647
4748 if ( ! process . env . TEST_REALM ) {
4849 throw new Error ( 'TEST_REALM required to create sandbox' ) ;
4950 }
5051
51- const result = await runCLI (
52+ const result = await runCLIWithRetry (
5253 [ 'ods' , 'create' , '--realm' , process . env . TEST_REALM , '--ttl' , '4' , '--wait' , '--set-permissions' , '--json' ] ,
53- { timeout : 720_000 } ,
54+ { timeout : TIMEOUTS . ODS_OPERATION , verbose : true } ,
5455 ) ;
5556
56- expect ( result . exitCode ) . to . equal ( 0 , `Failed to create sandbox: ${ result . stderr } ` ) ;
57- const sandbox = JSON . parse ( result . stdout ) ;
58- ownSandboxId = sandbox . id ;
59- serverHostname = sandbox . hostName ;
60- console . log ( `Created dedicated sandbox ${ ownSandboxId } at ${ serverHostname } ` ) ;
57+ expect ( result . exitCode , `Failed to create sandbox: ${ toString ( result . stderr ) } ` ) . to . equal ( 0 ) ;
58+ const sandbox = parseJSONOutput ( result ) ;
59+ ownSandboxId = getSandboxId ( sandbox ) ;
60+ serverHostname = getHostname ( sandbox ) ;
61+ console . log ( ` ✓ Created dedicated sandbox ${ ownSandboxId } at ${ serverHostname } ` ) ;
6162 }
6263 } ) ;
6364
64- async function runCLI ( args : string [ ] , options : { timeout ?: number } = { } ) {
65- return execa ( 'node' , [ CLI_BIN , ...args ] , {
66- env : { ...process . env , SFCC_LOG_LEVEL : 'silent' } ,
67- reject : false ,
68- timeout : options . timeout ,
69- } ) ;
70- }
71-
7265 after ( async function ( ) {
7366 this . timeout ( 180_000 ) ; // 3 minutes for cleanup
7467
@@ -78,13 +71,13 @@ describe('Code Lifecycle E2E Tests', function () {
7871
7972 // Delete remaining code versions
8073 if ( codeVersionB && serverHostname ) {
81- await runCLI ( [ 'code' , 'delete' , codeVersionB , '--server' , serverHostname , '--force' ] ) ;
74+ await runCLIWithRetry ( [ 'code' , 'delete' , codeVersionB , '--server' , serverHostname , '--force' ] ) ;
8275 }
8376
8477 // Delete own sandbox if we created one
8578 if ( ownSandboxId ) {
8679 console . log ( `Cleaning up dedicated sandbox ${ ownSandboxId } ...` ) ;
87- await runCLI ( [ 'ods' , 'delete' , ownSandboxId , '--force' ] ) ;
80+ await runCLIWithRetry ( [ 'ods' , 'delete' , ownSandboxId , '--force' ] ) ;
8881 console . log ( 'Dedicated sandbox deleted' ) ;
8982 }
9083 } ) ;
@@ -94,7 +87,7 @@ describe('Code Lifecycle E2E Tests', function () {
9487 it ( 'should deploy first code version' , async function ( ) {
9588 codeVersionA = `e2e-a-${ Date . now ( ) } ` ;
9689
97- const result = await runCLI ( [
90+ const result = await runCLIWithRetry ( [
9891 'code' ,
9992 'deploy' ,
10093 CARTRIDGES_DIR ,
@@ -105,24 +98,24 @@ describe('Code Lifecycle E2E Tests', function () {
10598 '--json' ,
10699 ] ) ;
107100
108- expect ( result . exitCode ) . to . equal ( 0 , result . stderr ) ;
101+ expect ( result . exitCode ) . to . equal ( 0 , toString ( result . stderr ) ) ;
109102 } ) ;
110103 } ) ;
111104
112105 describe ( 'Step 2: Verify Code Version A in List' , function ( ) {
113106 it ( 'should find code version A in list' , async function ( ) {
114- const result = await runCLI ( [ 'code' , 'list' , '--server' , serverHostname , '--json' ] ) ;
107+ const result = await runCLIWithRetry ( [ 'code' , 'list' , '--server' , serverHostname , '--json' ] ) ;
115108 expect ( result . exitCode ) . to . equal ( 0 ) ;
116109
117- const response = JSON . parse ( result . stdout ) ;
110+ const response = parseJSONOutput ( result ) ;
118111 const found = response . data . find ( ( v : any ) => v . id === codeVersionA ) ;
119112 expect ( found ) . to . exist ;
120113 } ) ;
121114 } ) ;
122115
123116 describe ( 'Step 3: Activate Code Version A' , function ( ) {
124117 it ( 'should activate version A' , async function ( ) {
125- const result = await runCLI ( [ 'code' , 'activate' , codeVersionA , '--server' , serverHostname , '--json' ] ) ;
118+ const result = await runCLIWithRetry ( [ 'code' , 'activate' , codeVersionA , '--server' , serverHostname , '--json' ] ) ;
126119
127120 expect ( result . exitCode ) . to . equal ( 0 ) ;
128121 } ) ;
@@ -132,7 +125,7 @@ describe('Code Lifecycle E2E Tests', function () {
132125 it ( 'should deploy second code version' , async function ( ) {
133126 codeVersionB = `e2e-b-${ Date . now ( ) } ` ;
134127
135- const result = await runCLI ( [
128+ const result = await runCLIWithRetry ( [
136129 'code' ,
137130 'deploy' ,
138131 CARTRIDGES_DIR ,
@@ -149,27 +142,27 @@ describe('Code Lifecycle E2E Tests', function () {
149142
150143 describe ( 'Step 5: Verify Code Version B in List' , function ( ) {
151144 it ( 'should find code version B in list' , async function ( ) {
152- const result = await runCLI ( [ 'code' , 'list' , '--server' , serverHostname , '--json' ] ) ;
145+ const result = await runCLIWithRetry ( [ 'code' , 'list' , '--server' , serverHostname , '--json' ] ) ;
153146 expect ( result . exitCode ) . to . equal ( 0 ) ;
154147
155- const response = JSON . parse ( result . stdout ) ;
148+ const response = parseJSONOutput ( result ) ;
156149 const found = response . data . find ( ( v : any ) => v . id === codeVersionB ) ;
157150 expect ( found ) . to . exist ;
158151 } ) ;
159152 } ) ;
160153
161154 describe ( 'Step 6: Activate Code Version B' , function ( ) {
162155 it ( 'should activate version B (A becomes inactive)' , async function ( ) {
163- const result = await runCLI ( [ 'code' , 'activate' , codeVersionB , '--server' , serverHostname , '--json' ] ) ;
156+ const result = await runCLIWithRetry ( [ 'code' , 'activate' , codeVersionB , '--server' , serverHostname , '--json' ] ) ;
164157
165158 expect ( result . exitCode ) . to . equal ( 0 ) ;
166159 } ) ;
167160 } ) ;
168161
169162 describe ( 'Step 7: Verify Active Code Version' , function ( ) {
170163 it ( 'should show version B as active' , async function ( ) {
171- const result = await runCLI ( [ 'code' , 'list' , '--server' , serverHostname , '--json' ] ) ;
172- const response = JSON . parse ( result . stdout ) ;
164+ const result = await runCLIWithRetry ( [ 'code' , 'list' , '--server' , serverHostname , '--json' ] ) ;
165+ const response = parseJSONOutput ( result ) ;
173166
174167 const active = response . data . find ( ( v : any ) => v . active === true ) ;
175168 expect ( active . id ) . to . equal ( codeVersionB ) ;
@@ -208,21 +201,24 @@ describe('Code Lifecycle E2E Tests', function () {
208201 it ( 'should delete inactive version A' , async function ( ) {
209202 console . log ( `Starting deletion of code version: ${ codeVersionA } ` ) ;
210203
211- const result = await runCLI ( [ 'code' , 'delete' , codeVersionA , '--server' , serverHostname , '--force' , '--json' ] , {
212- timeout : 120_000 ,
213- } ) ; // 2 minutes timeout
204+ const result = await runCLIWithRetry (
205+ [ 'code' , 'delete' , codeVersionA , '--server' , serverHostname , '--force' , '--json' ] ,
206+ {
207+ timeout : 120_000 ,
208+ } ,
209+ ) ; // 2 minutes timeout
214210
215211 console . log ( `Deletion finished with exit code: ${ result . exitCode } ` ) ;
216212
217- expect ( result . exitCode ) . to . equal ( 0 , `Delete failed: ${ result . stderr } ` ) ;
213+ expect ( result . exitCode ) . to . equal ( 0 , `Delete failed: ${ toString ( result . stderr ) } ` ) ;
218214 codeVersionA = '' ;
219215 } ) ;
220216 } ) ;
221217
222218 describe ( 'Step 10: Verify Code Version A Removed' , function ( ) {
223219 it ( 'should not find deleted version A' , async function ( ) {
224- const result = await runCLI ( [ 'code' , 'list' , '--server' , serverHostname , '--json' ] ) ;
225- const response = JSON . parse ( result . stdout ) ;
220+ const result = await runCLIWithRetry ( [ 'code' , 'list' , '--server' , serverHostname , '--json' ] ) ;
221+ const response = parseJSONOutput ( result ) ;
226222
227223 const found = response . data . find ( ( v : any ) => v . id === codeVersionA ) ;
228224 expect ( found ) . to . not . exist ;
0 commit comments