@@ -17,9 +17,7 @@ The default wait strategy used by Testcontainers. It will wait up to 60 seconds
1717``` javascript
1818const { GenericContainer } = require (" testcontainers" );
1919
20- const container = await new GenericContainer (" alpine" )
21- .withExposedPorts (6379 )
22- .start ();
20+ const container = await new GenericContainer (" alpine" ).withExposedPorts (6379 ).start ();
2321```
2422
2523It can be set explicitly but is not required:
@@ -72,9 +70,7 @@ Wait until the container's health check is successful:
7270``` javascript
7371const { GenericContainer , Wait } = require (" testcontainers" );
7472
75- const container = await new GenericContainer (" alpine" )
76- .withWaitStrategy (Wait .forHealthCheck ())
77- .start ();
73+ const container = await new GenericContainer (" alpine" ).withWaitStrategy (Wait .forHealthCheck ()).start ();
7874```
7975
8076Define your own health check:
@@ -88,7 +84,7 @@ const container = await new GenericContainer("alpine")
8884 interval: 1000 ,
8985 timeout: 3000 ,
9086 retries: 5 ,
91- startPeriod: 1000
87+ startPeriod: 1000 ,
9288 })
9389 .withWaitStrategy (Wait .forHealthCheck ())
9490 .start ();
@@ -99,13 +95,13 @@ Note that `interval`, `timeout`, `retries` and `startPeriod` are optional as the
9995To execute the test with a shell use the form ` ["CMD-SHELL", "command"] ` :
10096
10197``` javascript
102- [" CMD-SHELL" , " curl -f http://localhost:8000 || exit 1" ]
98+ [" CMD-SHELL" , " curl -f http://localhost:8000 || exit 1" ];
10399```
104100
105101To execute the test without a shell, use the form: ` ["CMD", "command", "arg1", "arg2"] ` . This may be needed when working with distroless images:
106102
107103``` javascript
108- [" CMD" , " /usr/bin/wget" , " --no-verbose" , " --tries=1" , " --spider" , " http://localhost:8080/hello-world" ]
104+ [" CMD" , " /usr/bin/wget" , " --no-verbose" , " --tries=1" , " --spider" , " http://localhost:8080/hello-world" ];
109105```
110106
111107## HTTP
@@ -115,9 +111,7 @@ Wait for an HTTP request to satisfy a condition. By default, it will wait for a
115111``` javascript
116112const { GenericContainer , Wait } = require (" testcontainers" );
117113
118- const container = await new GenericContainer (" redis" )
119- .withWaitStrategy (Wait .forHttp (" /health" , 8080 ))
120- .start ();
114+ const container = await new GenericContainer (" redis" ).withWaitStrategy (Wait .forHttp (" /health" , 8080 )).start ();
121115```
122116
123117Stop waiting after container exited if waiting for container restart not needed.
@@ -184,6 +178,18 @@ const container = await new GenericContainer("alpine")
184178 .start ();
185179```
186180
181+ ## One shot
182+
183+ This strategy is intended for use with containers that only run briefly and exit of their own accord. As such, success is deemed to be when the container has stopped with exit code 0.
184+
185+ ``` javascript
186+ const { GenericContainer , Wait } = require (" testcontainers" );
187+
188+ const container = await new GenericContainer (" alpine" )
189+ .withWaitStrategy (Wait .forOneShotStartup ()))
190+ .start ();
191+ ```
192+
187193## Composite
188194
189195Multiple wait strategies can be chained together:
@@ -192,10 +198,7 @@ Multiple wait strategies can be chained together:
192198const { GenericContainer , Wait } = require (" testcontainers" );
193199
194200const container = await new GenericContainer (" alpine" )
195- .withWaitStrategy (Wait .forAll ([
196- Wait .forListeningPorts (),
197- Wait .forLogMessage (" Ready to accept connections" )
198- ]))
201+ .withWaitStrategy (Wait .forAll ([Wait .forListeningPorts (), Wait .forLogMessage (" Ready to accept connections" )]))
199202 .start ();
200203```
201204
@@ -205,7 +208,7 @@ The composite wait strategy by default will respect each individual wait strateg
205208const w1 = Wait .forListeningPorts ().withStartupTimeout (1000 );
206209const w2 = Wait .forLogMessage (" READY" ).withStartupTimeout (2000 );
207210
208- const composite = Wait .forAll ([w1, w2])
211+ const composite = Wait .forAll ([w1, w2]);
209212
210213expect (w1 .getStartupTimeout ()).toBe (1000 );
211214expect (w2 .getStartupTimeout ()).toBe (2000 );
@@ -217,7 +220,7 @@ The startup timeout of inner wait strategies that have not defined their own sta
217220const w1 = Wait .forListeningPorts ().withStartupTimeout (1000 );
218221const w2 = Wait .forLogMessage (" READY" );
219222
220- const composite = Wait .forAll ([w1, w2]).withStartupTimeout (2000 )
223+ const composite = Wait .forAll ([w1, w2]).withStartupTimeout (2000 );
221224
222225expect (w1 .getStartupTimeout ()).toBe (1000 );
223226expect (w2 .getStartupTimeout ()).toBe (2000 );
@@ -228,7 +231,7 @@ The startup timeout of all wait strategies can be controlled by setting a deadli
228231``` javascript
229232const w1 = Wait .forListeningPorts ();
230233const w2 = Wait .forLogMessage (" READY" );
231- const composite = Wait .forAll ([w1, w2]).withDeadline (2000 )
234+ const composite = Wait .forAll ([w1, w2]).withDeadline (2000 );
232235```
233236
234237## Other startup strategies
@@ -237,8 +240,8 @@ If these options do not meet your requirements, you can subclass `StartupCheckSt
237240
238241``` javascript
239242const Dockerode = require (" dockerode" );
240- const {
241- GenericContainer,
243+ const {
244+ GenericContainer ,
242245 StartupCheckStrategy ,
243246 StartupStatus
244247} = require (" testcontainers" );
0 commit comments