Skip to content

Commit

Permalink
Create volume for caching playwright browsers
Browse files Browse the repository at this point in the history
Playwright must download and install browsers before it can run any
tests. Users can do this (inside their devcontainers) by running:

    npx playwright install [chromium [firefox]]

Plenty of other browsers are available.

You don't want to be doing this every time you build a devcontainer, so
we'll cache the downloaded browsers in a named volume. The volume will
still be available after devcontainer images have been torn down and
rebuilt.

The feature configures playwright to automatically use this volume by
setting the PLAYWRIGHT_BROWSERS_PATH environment variable.
  • Loading branch information
gma committed Nov 7, 2024
1 parent 2ab6e01 commit 17264a0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/playwright/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
"version": "1.0.0",
"description": "Install Playwright's dependencies and cache installed browsers",
"keywords": ["playwright", "testing", "browser-testing"],
"containerEnv": {
"PLAYWRIGHT_BROWSERS_PATH": "/playwright/browsers"
},
"mounts": [{
"source": "playwright-browsers",
"target": "/playwright/browsers",
"type": "volume"
}],
"options": {
"browsers": {
"type": "string",
Expand Down
11 changes: 11 additions & 0 deletions test/playwright/browser_volume.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -e

source dev-container-features-test-lib

CACHE_DIR="/playwright/browsers"

check "playwright-browsers volume is mounted" test -d "$CACHE_DIR"

check "PLAYWRIGHT_BROWSERS_PATH is set" env | grep "PLAYWRIGHT_BROWSERS_PATH=$CACHE_DIR"
7 changes: 7 additions & 0 deletions test/playwright/scenarios.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"browser_volume": {
"image": "debian:latest",
"features": {
"ghcr.io/devcontainers/features/node:1": {},
"playwright": {}
}
},
"chromium_dependencies": {
"image": "debian:latest",
"features": {
Expand Down

0 comments on commit 17264a0

Please sign in to comment.