diff --git a/package.json b/package.json index f6e37f49..6c794f01 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/playwright/Dockerfile b/playwright/Dockerfile new file mode 100644 index 00000000..bb05122f --- /dev/null +++ b/playwright/Dockerfile @@ -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"] \ No newline at end of file diff --git a/playwright/playwright-docker-windows.sh b/playwright/playwright-docker-windows.sh new file mode 100644 index 00000000..ea634985 --- /dev/null +++ b/playwright/playwright-docker-windows.sh @@ -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 \ No newline at end of file diff --git a/playwright/playwright-docker.sh b/playwright/playwright-docker.sh new file mode 100644 index 00000000..0c930f09 --- /dev/null +++ b/playwright/playwright-docker.sh @@ -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 \ No newline at end of file diff --git a/playwright.config.ts b/playwright/playwright.config.ts similarity index 62% rename from playwright.config.ts rename to playwright/playwright.config.ts index cb108bbf..5af109d1 100644 --- a/playwright.config.ts +++ b/playwright/playwright.config.ts @@ -1,10 +1,18 @@ +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, @@ -12,7 +20,7 @@ export default defineConfig({ reporter: 'html', webServer: { reuseExistingServer: true, - command: 'npm run _storybook:watch', + command: 'BROWSER=true npm run dev', url: BASE_URL, timeout: 120 * 1000, }, diff --git a/playwright/variables.sh b/playwright/variables.sh new file mode 100644 index 00000000..9532a213 --- /dev/null +++ b/playwright/variables.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +IMAGE_NAME="playwright-docker" +CONTAINER_COMPONENTS_DIR="/usr/src/app/src/components" \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 0690aa69..2a8bfaf3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,6 +21,6 @@ "demo/**/*.tsx", "demo/.storybook/**/*.ts", "demo/.storybook/**/*.tsx", - "playwright.config.ts" + "playwright/playwright.config.ts" ] }