From 57ee63d2db4d55396af690836b6d833d2e6b0ef3 Mon Sep 17 00:00:00 2001 From: Corentin Thomasset Date: Fri, 20 Sep 2024 23:05:17 +0200 Subject: [PATCH] chore(ci): run e2e after preview deploy --- .github/workflows/ci-test-e2e.yml | 23 ++++++++++++++----- .../e2e-tests/createand-view-note.e2e.test.ts | 4 ++++ packages/app-client/playwright.config.ts | 17 +++++++++++++- .../modules/notes/pages/create-note.page.tsx | 4 ++-- .../modules/notes/pages/view-note.page.tsx | 4 ++-- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci-test-e2e.yml b/.github/workflows/ci-test-e2e.yml index 697e35c5..10b772d7 100644 --- a/.github/workflows/ci-test-e2e.yml +++ b/.github/workflows/ci-test-e2e.yml @@ -1,11 +1,13 @@ -name: E2E Tests +name: CI - App Client E2E on: - deployment_status: + pull_request: + push: + branches: + - main jobs: run-e2es: - if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' runs-on: ubuntu-latest timeout-minutes: 60 defaults: @@ -14,19 +16,28 @@ jobs: steps: - uses: actions/checkout@v4 + - run: corepack enable - uses: actions/setup-node@v4 with: - node-version: 20 + node-version: 22 corepack: true cache: 'pnpm' - name: Get Playwright version id: playwright-version - run: echo "PLAYWRIGHT_VERSION=$(jq -r .dependencies.playwright package.json)" >> "$GITHUB_OUTPUT" + run: echo "PLAYWRIGHT_VERSION=$(jq -r .devDependencies.\"@playwright/test\" package.json)" >> "$GITHUB_OUTPUT" - name: Install dependencies run: pnpm i working-directory: ./ + + - name: Build iso-prod app + run: | + pnpm -F @enclosed/app-client build + pnpm -F @enclosed/app-server build:node + mkdir dist-app + cp -r dist dist-app/public + cp -r ../app-server/dist-node/index.cjs dist-app/index.cjs - name: Restore Playwright browsers from cache uses: actions/cache@v3 @@ -43,7 +54,7 @@ jobs: - name: Run e2e tests run: pnpm test:e2e env: - BASE_URL: ${{ github.event.deployment_status.environment_url }} + USE_PREVIEW_SERVER: true - uses: actions/upload-artifact@v4 if: always() diff --git a/packages/app-client/e2e-tests/createand-view-note.e2e.test.ts b/packages/app-client/e2e-tests/createand-view-note.e2e.test.ts index 8ecbbcad..37a44af5 100644 --- a/packages/app-client/e2e-tests/createand-view-note.e2e.test.ts +++ b/packages/app-client/e2e-tests/createand-view-note.e2e.test.ts @@ -1,5 +1,7 @@ import { expect, test } from '@playwright/test'; +const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); + test('Can create and view a note', async ({ page }) => { await page.goto('/'); @@ -11,6 +13,8 @@ test('Can create and view a note', async ({ page }) => { await page.getByTestId('delete-after-reading').click(); await page.getByTestId('create-note').click(); + await sleep(1000); + const noteUrl = await page.getByTestId('note-url').inputValue(); expect(noteUrl).toBeDefined(); diff --git a/packages/app-client/playwright.config.ts b/packages/app-client/playwright.config.ts index 3d48aa17..184d60d1 100644 --- a/packages/app-client/playwright.config.ts +++ b/packages/app-client/playwright.config.ts @@ -1,8 +1,10 @@ import process from 'node:process'; import { defineConfig, devices } from '@playwright/test'; -const baseURL = process.env.BASE_URL ?? 'http://localhost:3000/'; +const port = process.env.PORT ?? '3999'; +const baseURL = process.env.BASE_URL ?? `http://localhost:${port}/`; const isCI = Boolean(process.env.CI); +const startPreviewServer = Boolean(process.env.USE_PREVIEW_SERVER); /** * See https://playwright.dev/docs/test-configuration. @@ -49,4 +51,17 @@ export default defineConfig({ use: { ...devices['Desktop Safari'] }, }, ], + + ...(startPreviewServer + ? { + webServer: { + command: 'cd dist-app && node index.cjs', + reuseExistingServer: true, + env: { + PORT: port, + }, + }, + } + : {}), + }); diff --git a/packages/app-client/src/modules/notes/pages/create-note.page.tsx b/packages/app-client/src/modules/notes/pages/create-note.page.tsx index 9bcb2f08..55c24d7e 100644 --- a/packages/app-client/src/modules/notes/pages/create-note.page.tsx +++ b/packages/app-client/src/modules/notes/pages/create-note.page.tsx @@ -205,12 +205,12 @@ export const CreateNotePage: Component = () => {
- setUploadedFiles(prevFiles => [...prevFiles, ...files])} data-test-id="create-note"> + setUploadedFiles(prevFiles => [...prevFiles, ...files])}>
{t('create.settings.attach-files')}
- diff --git a/packages/app-client/src/modules/notes/pages/view-note.page.tsx b/packages/app-client/src/modules/notes/pages/view-note.page.tsx index bb57c3d0..d14313fd 100644 --- a/packages/app-client/src/modules/notes/pages/view-note.page.tsx +++ b/packages/app-client/src/modules/notes/pages/view-note.page.tsx @@ -262,7 +262,7 @@ export const ViewNotePage: Component = () => { {getDecryptedNote() && (
-
+
{t('view.note-content')}
@@ -270,7 +270,7 @@ export const ViewNotePage: Component = () => { -
{getDecryptedNote()}
+
{getDecryptedNote()}