From 0f7d73eb794af80d38c08fd66bf6f80e19f0b455 Mon Sep 17 00:00:00 2001 From: Arianrhod Sandlot Date: Wed, 27 Sep 2023 11:44:19 +0800 Subject: [PATCH] test: fix test in ci --- .github/workflows/test.yaml | 11 ++++++++--- package.json | 5 +++-- tests/e2e/homepage/homepage.spec.ts | 5 ++--- tests/e2e/playwright.config.ts | 5 +---- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 990e7e7..ac4672f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -3,6 +3,10 @@ on: [push] jobs: test: runs-on: ubuntu-latest + environment: + name: test + env: + VITE_ONEDRIVE_CLIENT_ID: ${{ vars.VITE_ONEDRIVE_CLIENT_ID }} steps: - uses: actions/checkout@v4 @@ -18,10 +22,11 @@ jobs: - uses: actions/cache@v3 with: - path: tests/fixtures - key: tests/fixtures + path: tests/fixtures/roms + key: tests/fixtures/roms - run: pnpm lint - - run: pnpm playwright install + - run: env + - run: pnpm playwright install chromium - run: pnpm prepare-test - run: pnpm t diff --git a/package.json b/package.json index da676ad..e740778 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,12 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "vite", "build": "vite build", - "preview": "vite build && vite preview", + "dev-test": "playwright test -c tests/e2e --headed --ui", + "dev": "vite", "lint": "eslint src", "prepare-test": "node ./scripts/prepare-test.js", + "preview": "vite build && vite preview", "test": "playwright test -c tests/e2e" }, "dependencies": { diff --git a/tests/e2e/homepage/homepage.spec.ts b/tests/e2e/homepage/homepage.spec.ts index 339939c..ffa0f56 100644 --- a/tests/e2e/homepage/homepage.spec.ts +++ b/tests/e2e/homepage/homepage.spec.ts @@ -12,21 +12,20 @@ function setMockLocalStorage() { test.beforeEach(async ({ page }) => { await page.goto('/') - await page.bringToFront() const dialog = page.getByRole('dialog') + const button = page.getByTestId('select-onedrive-directory') if (isUpdatingHar) { await page.routeFromHAR(harPath, { url: harUrlPattern, update: true, updateMode: 'minimal' }) - const button = page.getByTestId('select-onedrive-directory') await button.click() await dialog.getByRole('link').click() } else { await page.evaluate(setMockLocalStorage) await page.routeFromHAR(harPath, { url: harUrlPattern }) - const button = page.getByTestId('select-onedrive-directory') await button.click() } + const node = dialog.getByTestId('directory-tree-node') await node.filter({ hasText: 'games' }).click() await node.filter({ hasText: 'retro-game-roms-test' }).getByRole('button').click() diff --git a/tests/e2e/playwright.config.ts b/tests/e2e/playwright.config.ts index 9d2be3b..41ad93a 100644 --- a/tests/e2e/playwright.config.ts +++ b/tests/e2e/playwright.config.ts @@ -1,16 +1,13 @@ -import process from 'node:process' import { defineConfig } from '@playwright/test' export default defineConfig({ testDir: '.', snapshotDir: 'snapshots', snapshotPathTemplate: '{snapshotDir}/{testFilePath}/{testName}-{arg}{ext}', - timeout: 5 * 60 * 1000, use: { baseURL: 'http://localhost:5173', trace: 'on-first-retry', - headless: Boolean(process.env.CI), }, - webServer: { command: 'pnpm dev', url: 'http://localhost:5173', reuseExistingServer: true }, + webServer: { command: 'pnpm dev', url: 'http://localhost:5173', reuseExistingServer: !process.env.CI }, expect: { toHaveScreenshot: { maxDiffPixelRatio: 0.05 } }, })