Skip to content

Commit

Permalink
feat: add scripts for testing in docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel-Tyan committed Dec 22, 2024
1 parent aa4b805 commit 956e9aa
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 7 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@
"deps:install": "npm ci",
"deps:truncate": "npm prune --production",
"typecheck": "tsc -p . --noEmit",
"test": "exit 0",
"test": "npx playwright test --config playwright/playwright.config.ts",
"test:docker": "sh ./playwright/playwright-docker.sh",
"test:docker:windows": "sh ./playwright/playwright-docker-windows.sh",
"dev": "run-s build _dev:watch",
"_dev:watch": "run-p _build:watch _storybook:watch",
"build:clean": "rm -rf build",
"build:compile": "./esbuild/build.js",
"build:compile": "node esbuild/build.js",
"_build:declarations:esm": "tsc --emitDeclarationOnly -p tsconfig.esm.json",
"_build:declarations:cjs": "tsc --emitDeclarationOnly -p tsconfig.cjs.json",
"build": "run-s build:clean build:compile _build:declarations:*",
"_build:watch": "./esbuild/build.js --watch",
"_build:watch": "node esbuild/build.js --watch",
"_storybook:watch": "cd demo && npm run storybook",
"prepublishOnly": "npm run lint && npm run test && npm run build",
"postinstall": "cd demo && npm i || true",
Expand Down
15 changes: 15 additions & 0 deletions playwright/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM mcr.microsoft.com/playwright:v1.48.2-jammy
WORKDIR /usr/src/app
RUN cd ..
COPY package*.json ./
RUN npm ci
COPY . .
RUN rm -r node_modules && \
npm ci && \
cd demo && \
rm -r node_modules && \
npm ci && \
cd .. && \
npx playwright install && \
npm run build
CMD ["npm", "run", "test"]
10 changes: 10 additions & 0 deletions playwright/playwright-docker-windows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -e

source ./playwright/variables.sh

HOST_COMPONENTS_DIR="/src/components"

docker build --no-cache -t $IMAGE_NAME -f ./playwright/Dockerfile . &&
docker run --rm -v /${PWD}$HOST_COMPONENTS_DIR:$CONTAINER_COMPONENTS_DIR $IMAGE_NAME
10 changes: 10 additions & 0 deletions playwright/playwright-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -e

source ./playwright/variables.sh

HOST_COMPONENTS_DIR="./src/components"

docker build --no-cache -t $IMAGE_NAME -f ./playwright/Dockerfile . &&
docker run --rm -v $HOST_COMPONENTS_DIR:$CONTAINER_COMPONENTS_DIR $IMAGE_NAME
14 changes: 11 additions & 3 deletions playwright.config.ts → playwright/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import {resolve} from 'path';
import {defineConfig, devices} from '@playwright/test';

import {BASE_URL} from './src/components/constants';
import {BASE_URL} from '../src/components/constants';

function pathFromRoot(p: string) {
// replace for Windows users
return resolve(__dirname, '../', p).replace(/\\/g, '/');
}

export default defineConfig({
testDir: pathFromRoot('src/components'),
updateSnapshots: 'missing',
snapshotPathTemplate: '{testFilePath}/../../__screenshots__/{arg}-{projectName}{ext}',
snapshotPathTemplate:
'{testDir}/{testFilePath}/../../__screenshots__/{arg}-{projectName}-{platform}{ext}',
fullyParallel: false,
forbidOnly: true,
retries: 2,
workers: 1,
reporter: 'html',
webServer: {
reuseExistingServer: true,
command: 'npm run _storybook:watch',
command: 'BROWSER=true npm run dev',
url: BASE_URL,
timeout: 120 * 1000,
},
Expand Down
4 changes: 4 additions & 0 deletions playwright/variables.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

IMAGE_NAME="playwright-docker"
CONTAINER_COMPONENTS_DIR="/usr/src/app/src/components"
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"demo/**/*.tsx",
"demo/.storybook/**/*.ts",
"demo/.storybook/**/*.tsx",
"playwright.config.ts"
"playwright/playwright.config.ts"
]
}

0 comments on commit 956e9aa

Please sign in to comment.