
Real Docker Containers in Playwright Tests — Zero Boilerplate
You want real infrastructure in your integration tests. You don't want to write cleanup code. Here is how to get both. The problem with containers in Playwright today Testcontainers works great in Node.js, but fitting it into Playwright requires manual lifecycle management: // the old way — lots of ceremony let container : StartedTestContainer ; test . beforeAll ( async () => { container = await new GenericContainer ( " redis:8 " ) . withExposedPorts ( 6379 ) . start (); }); test . afterAll ( async () => { await container . stop (); // what if beforeAll threw halfway through? }); test ( " my test " , async () => { const port = container . getMappedPort ( 6379 ); // ... }); Problems: If beforeAll fails midway, afterAll still runs and may throw on container.stop() against an undefined value. All tests in the file share one container — isolation suffers. The container setup has nothing to do with what you're testing, but it's taking up a third of your file. The new way npm install -D @pla
Continue reading on Dev.to
Opens in a new tab
.jpg&w=1200&q=75)



