diff --git a/.dockerignore b/.dockerignore index 4a1be89..2e0808a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -29,6 +29,7 @@ **/minio-storage **/vite.config.js.timestamp-* **/vite.config.ts.timestamp-* +tests .output .vercel .netlify diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml new file mode 100644 index 0000000..0b8320e --- /dev/null +++ b/.github/workflows/playwright.yml @@ -0,0 +1,64 @@ +name: Tests +on: [push, pull_request] + +jobs: + test: + name: Tests + runs-on: ubuntu-latest + services: + # Cassandra service container + cassandra: + image: cassandra:latest + ports: + - 9042:9042 + options: >- + --health-cmd="nodetool status" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + env: + CASSANDRA_USER: admin + CASSANDRA_PASSWORD: admin + # Minio service container + minio: + image: docker.io/bitnami/minio + ports: + - 9000:9000 + env: + MINIO_ROOT_USER: minioadmin + MINIO_ROOT_PASSWORD: minioadmin + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - name: Install dependencies + run: bun install + + - name: Install Playwright browsers + run: bunx playwright install --with-deps chromium + + - name: Set up users DB + run: bun run migrate + + - name: Setup environment + run: cp .env.example .env + + - name: Run Playwright tests + run: | + bun run dev --host & + bun run test + env: + NODE_ENV: testing + + - name: Upload test results + uses: actions/upload-artifact@v4 + if: ${{ !cancelled() }} + with: + name: test-results + path: test-results/ + retention-days: 30 diff --git a/.gitignore b/.gitignore index a0e84f5..2f0291d 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,9 @@ Thumbs.db !.env.example !.env.test +# Tests +test-results + # Vite vite.config.js.timestamp-* vite.config.ts.timestamp-* diff --git a/README.md b/README.md index 6d7d7ab..753a9f6 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ A simple chat app built with SvelteKit and Apache Cassandra
[![Prettier](https://github.com/arithefirst/sv-chat/actions/workflows/prettier.yml/badge.svg)](https://github.com/arithefirst/sv-chat/actions/workflows/prettier.yml) [![ESLint](https://github.com/arithefirst/sv-chat/actions/workflows/eslint.yml/badge.svg)](https://github.com/arithefirst/sv-chat/actions/workflows/eslint.yml) +[![Playwright](https://github.com/arithefirst/sv-chat/actions/workflows/playwright.yml/badge.svg)](https://github.com/arithefirst/sv-chat/actions/workflows/playwright.yml) ## 💻 Techstack diff --git a/bun.lockb b/bun.lockb index 8370767..87c3dab 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 2d4216c..dfc67e2 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,9 @@ "minio": "minio server minio-storage", "preview": "vite preview", "prepare": "svelte-kit sync || echo ''", - "production": "tsm ./prodServer.ts" + "production": "tsm ./prodServer.ts", + "test": "playwright test", + "test:head": "playwright test --headed" }, "devDependencies": { "@eslint/compat": "^1.2.5", @@ -37,6 +39,7 @@ "typescript-eslint": "^8.20.0" }, "dependencies": { + "@playwright/test": "^1.50.1", "@sveltejs/adapter-node": "^5.2.12", "@tailwindcss/typography": "^0.5.16", "@types/better-sqlite3": "^7.6.12", diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 0000000..16fc586 --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,29 @@ +import { defineConfig, devices } from '@playwright/test'; + +export default defineConfig({ + testDir: 'tests', + projects: [ + { + name: 'setup', + testMatch: /setup\.ts/, + use: { ...devices['Desktop Chrome'] }, + }, + + // Make all other tests depend on the signup, + // since they need user accounts to run + + { + name: 'test', + use: { ...devices['Desktop Chrome'] }, + dependencies: ['setup'], + testMatch: /(.+\.)?(test|spec)\.[jt]s/, + }, + ], + retries: process.env.CI ? 1 : 0, + reporter: 'list', + workers: 1, + use: { + baseURL: 'http://localhost:5173', + trace: 'on-first-retry', + }, +}); diff --git a/src/lib/components/mainLayout.svelte b/src/lib/components/mainLayout.svelte index d581f90..5003b06 100644 --- a/src/lib/components/mainLayout.svelte +++ b/src/lib/components/mainLayout.svelte @@ -18,7 +18,7 @@
-
+