Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): run e2e after preview deploy #204

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions .github/workflows/ci-test-e2e.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions packages/app-client/e2e-tests/createand-view-note.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -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('/');

Expand All @@ -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();
Expand Down
17 changes: 16 additions & 1 deletion packages/app-client/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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,
},
},
}
: {}),

});
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ export const CreateNotePage: Component = () => {
</TextFieldRoot>

<div>
<FileUploaderButton variant="secondary" class="mt-2 w-full" multiple onFilesUpload={({ files }) => setUploadedFiles(prevFiles => [...prevFiles, ...files])} data-test-id="create-note">
<FileUploaderButton variant="secondary" class="mt-2 w-full" multiple onFilesUpload={({ files }) => setUploadedFiles(prevFiles => [...prevFiles, ...files])}>
<div class="i-tabler-upload mr-2 text-lg text-muted-foreground"></div>
{t('create.settings.attach-files')}
</FileUploaderButton>

<Button class="mt-2 w-full" onClick={createNote} disabled={getIsNoteCreating()}>
<Button class="mt-2 w-full" onClick={createNote} disabled={getIsNoteCreating()} data-test-id="create-note">
<div class={cn('mr-2 text-lg text-muted-foreground', getIsNoteCreating() ? 'i-tabler-loader-2 animate-spin' : 'i-tabler-plus')}></div>
{getIsNoteCreating() ? t('create.settings.creating') : t('create.settings.create')}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,15 @@ export const ViewNotePage: Component = () => {
{getDecryptedNote() && (
<div class="flex-1 mb-4">
<div class="flex items-center gap-2 mb-4 justify-between">
<div class="text-muted-foreground" data-test-id="note-content-display">
<div class="text-muted-foreground">
{t('view.note-content')}
</div>
<CopyButton text={getDecryptedNote()!} variant="secondary" />
</div>

<Card class="w-full rounded-md shadow-sm mb-2">
<CardContent class="p-6">
<div class="break-all">{getDecryptedNote()}</div>
<div class="break-all" data-test-id="note-content-display">{getDecryptedNote()}</div>
</CardContent>
</Card>

Expand Down
Loading