Skip to content

Commit

Permalink
chore: improve playwright:docker commands
Browse files Browse the repository at this point in the history
  • Loading branch information
DakEnviy committed Dec 26, 2023
1 parent 4f4e13e commit fa527e2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@
"playwright:install": "playwright install --with-deps",
"playwright": "playwright test --config=playwright/playwright.config.ts",
"playwright:update": "npm run playwright -- -u",
"playwright:docker": "docker run --rm --network host -v $(pwd):/work/ -w /work/ -it mcr.microsoft.com/playwright:v1.39.0-jammy /bin/bash -c 'npm ci && npx playwright install && npm run playwright'",
"playwright:docker:update": " docker run --rm --network host -v $(pwd):/work/ -w /work/ -it mcr.microsoft.com/playwright:v1.39.0-jammy /bin/bash -c 'npm ci && npx playwright install && npm run playwright:update'"
"playwright:docker": "./scripts/playwright-docker.sh 'npm run playwright'",
"playwright:docker:update": "./scripts/playwright-docker.sh 'npm run playwright:update'",
"playwright:docker:clear-cache": "./scripts/playwright-docker.sh clear-cache"
},
"dependencies": {
"@bem-react/classname": "^1.6.0",
Expand Down
27 changes: 27 additions & 0 deletions scripts/playwright-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

set -euo pipefail

IMAGE_NAME="mcr.microsoft.com/playwright"
IMAGE_TAG="v1.38.1-jammy" # This version have to be synchronized with playwright version from package.json

NODE_MODULES_CACHE_DIR="$HOME/.cache/uikit-playwright-docker-node-modules"

run_command() {
docker run --rm --network host -it -w /work \
-v $(pwd):/work \
-v "$NODE_MODULES_CACHE_DIR:/work/node_modules" \
"$IMAGE_NAME:$IMAGE_TAG" \
/bin/bash -c "$1"
}

if [[ "$1" = "clear-cache" ]]; then
rm -rf "$NODE_MODULES_CACHE_DIR"
exit 0
fi

if [[ ! -d "$NODE_MODULES_CACHE_DIR" ]]; then
run_command 'npm ci'
fi

run_command "$1"

0 comments on commit fa527e2

Please sign in to comment.