From e7e2903dfd84e60270467b9359ec56eb655ea816 Mon Sep 17 00:00:00 2001 From: vrknetha Date: Sun, 8 Dec 2024 11:58:14 +0530 Subject: [PATCH] adds docker file and change the ci yml --- .github/workflows/ci.yml | 23 +++++++---------------- .github/workflows/publish.yml | 14 +++++++++----- Dockerfile | 34 ++++++++++++++++++++++++++++++++++ package.json | 5 +++-- playwright.config.ts | 26 +++++++++++++++++++++----- 5 files changed, 74 insertions(+), 28 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46ffaaf..2620538 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,26 +8,17 @@ on: jobs: test: + container: + image: mcr.microsoft.com/playwright:v1.49.0-jammy + options: --ipc=host runs-on: ubuntu-latest - strategy: - matrix: - node-version: [20.x] - + steps: - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - name: Install dependencies run: npm ci - - name: Install Playwright browsers - run: npx playwright install --with-deps - - name: Build run: npm run build @@ -35,10 +26,10 @@ jobs: run: npm run lint - name: Run tests - run: xvfb-run --auto-servernum -- npm test + run: xvfb-run --auto-servernum --server-args="-screen 0 1280x720x24" npm test env: CI: true - DEBUG: pw:webserver + DEBUG: pw:api,pw:webserver - name: Upload test results if: always() @@ -46,4 +37,4 @@ jobs: with: name: playwright-report path: playwright-report/ - retention-days: 30 \ No newline at end of file + retention-days: 30 \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1bc14d2..059375d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,16 +6,19 @@ on: jobs: publish: + container: + image: mcr.microsoft.com/playwright:v1.49.0-jammy + options: --ipc=host runs-on: ubuntu-latest + steps: - uses: actions/checkout@v3 - - name: Use Node.js + - name: Setup Node.js for NPM uses: actions/setup-node@v3 with: node-version: '20.x' registry-url: 'https://registry.npmjs.org' - cache: 'npm' - name: Install dependencies run: npm ci @@ -27,9 +30,10 @@ jobs: run: npm run lint - name: Test - run: | - npx playwright install --with-deps - npm test + run: xvfb-run --auto-servernum --server-args="-screen 0 1280x720x24" npm test + env: + CI: true + DEBUG: pw:api,pw:webserver - name: Publish run: npm publish diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ccf80a4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +FROM mcr.microsoft.com/playwright:v1.49.0-jammy + +# Set working directory +WORKDIR /app + +# Copy package files first for better caching +COPY package*.json ./ +COPY tsconfig.json ./ + +# Install dependencies +RUN npm ci + +# Copy source files +COPY src ./src +COPY tests ./tests +COPY index.html ./ +COPY playwright.config.ts ./ + +# Build the project +RUN npm run build + +# Install only Chromium browser +RUN npx playwright install chromium + +# Set environment variables +ENV CI=true +ENV DEBUG=pw:api,pw:webserver + +# Command to run tests +CMD xvfb-run --auto-servernum --server-args="-screen 0 1280x720x24" \ + npx playwright test \ + --project=chromium \ + --reporter=list \ + --workers=1 \ No newline at end of file diff --git a/package.json b/package.json index a3faf71..5522d80 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "build": "tsc", "test": "playwright test", "test:report": "playwright show-report", + "test:docker": "docker build -t playwright-clipboard-tests . && docker run --rm playwright-clipboard-tests", "prepare": "npm run build", "lint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\"", "lint:fix": "eslint \"src/**/*.ts\" \"tests/**/*.ts\" --fix", @@ -28,7 +29,7 @@ "license": "MIT", "devDependencies": { "@eslint/js": "^9.16.0", - "@playwright/test": "^1.40.0", + "@playwright/test": "^1.49.0", "@types/node": "^20.10.0", "@typescript-eslint/eslint-plugin": "^6.13.0", "@typescript-eslint/parser": "^6.13.0", @@ -40,7 +41,7 @@ "typescript": "^5.3.3" }, "peerDependencies": { - "@playwright/test": "^1.40.0" + "@playwright/test": "^1.49.0" }, "files": [ "dist", diff --git a/playwright.config.ts b/playwright.config.ts index e573c5d..7432538 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -2,14 +2,21 @@ import { defineConfig, devices } from '@playwright/test'; export default defineConfig({ testDir: './tests', - fullyParallel: true, + fullyParallel: false, forbidOnly: !!process.env.CI, retries: process.env.CI ? 2 : 0, - workers: process.env.CI ? 1 : undefined, + workers: 1, reporter: 'html', + timeout: 120000, + expect: { + timeout: 30000, + }, use: { baseURL: 'http://localhost:8080', trace: 'on-first-retry', + actionTimeout: 30000, + navigationTimeout: 30000, + headless: true }, webServer: { command: 'npm run serve', @@ -25,15 +32,24 @@ export default defineConfig({ use: { ...devices['Desktop Chrome'], permissions: ['clipboard-read', 'clipboard-write'], + viewport: { width: 1280, height: 720 } }, }, { name: 'firefox', - use: { ...devices['Desktop Firefox'] }, + use: { + ...devices['Desktop Firefox'], + permissions: ['clipboard-read', 'clipboard-write'], + viewport: { width: 1280, height: 720 } + }, }, { name: 'webkit', - use: { ...devices['Desktop Safari'] }, - }, + use: { + ...devices['Desktop Safari'], + permissions: ['clipboard-read', 'clipboard-write'], + viewport: { width: 1280, height: 720 } + }, + } ], }); \ No newline at end of file