@@ -70,28 +70,32 @@ Wait until the container's health check is successful:
7070``` js
7171const { GenericContainer , Wait } = require (" testcontainers" );
7272
73- const container = await new GenericContainer (" alpine" ).withWaitStrategy (Wait .forHealthCheck ()).start ();
73+ const container = await new GenericContainer (" alpine" )
74+ .withWaitStrategy (Wait .forHealthCheck ())
75+ .start ();
7476```
7577
76- Define your own health check:
78+ Define your own health check. Note that time units are in seconds :
7779
7880``` js
7981const { GenericContainer , Wait } = require (" testcontainers" );
8082
8183const container = await new GenericContainer (" alpine" )
8284 .withHealthCheck ({
8385 test: [" CMD-SHELL" , " curl -f http://localhost || exit 1" ],
84- interval: 1000 , // 1 second
85- timeout: 3000 , // 3 seconds
86+ interval: 1000 ,
87+ timeout: 3000 ,
8688 retries: 5 ,
87- startPeriod: 1000 , // 1 second
89+ startPeriod: 1000 ,
8890 })
8991 .withWaitStrategy (Wait .forHealthCheck ())
9092 .start ();
9193```
9294
9395Note that ` interval ` , ` timeout ` , ` retries ` and ` startPeriod ` are optional as they are inherited from the image or parent image if omitted.
9496
97+ ---
98+
9599To execute the test with a shell use the form ` ["CMD-SHELL", "command"] ` :
96100
97101``` js
@@ -106,12 +110,14 @@ To execute the test without a shell, use the form: `["CMD", "command", "arg1", "
106110
107111## HTTP
108112
109- Wait for an HTTP request to satisfy a condition. By default, it will wait for a 200 response:
113+ Wait for a HTTP request to satisfy a condition. By default, it will wait for a 200 response:
110114
111115``` js
112116const { GenericContainer , Wait } = require (" testcontainers" );
113117
114- const container = await new GenericContainer (" redis" ).withWaitStrategy (Wait .forHttp (" /health" , 8080 )).start ();
118+ const container = await new GenericContainer (" redis" )
119+ .withWaitStrategy (Wait .forHttp (" /health" , 8080 ))
120+ .start ();
115121```
116122
117123Stop waiting after container exited if waiting for container restart not needed.
@@ -131,7 +137,7 @@ const container = await new GenericContainer("redis")
131137 .forStatusCode (201 ))
132138
133139.withWaitStrategy (Wait .forHttp (" /health" , 8080 )
134- .forStatusCodeMatching (statusCode => statusCode === 201 ))
140+ .forStatusCodeMatching (statusCode => ` ${ statusCode} ` . startsWith ( " 2 " ) ))
135141```
136142
137143### For response body
0 commit comments