Skip to content

Commit

Permalink
feat(integration): Add initial "integration tests" (#3121)
Browse files Browse the repository at this point in the history
* initial commit

* initial 2

* Update integration-tests.yml

* Update integration-tests.yml

* update

* disable webkit for now

* add principles

* add group ficture

* updates

* Delete integration-tests/tests/utils/test-helpers.ts

* rename authenticatedPage to pageWithACreatedUser

* Update README.md

* break test

* if that didn't break it, does this?

* update

* now it should pass again

* upda

* increase timeout

* Update playwright.config.ts

* Update registration.spec.ts

* code review

* fix

* update

* Update group.fixture.ts

* Update submission-flow.spec.ts

* Update playwright.config.ts

* tab

* fix baseurl

* add baseurl

* Update playwright.config.ts

* refactor

* refactor

* try deleting extra config file

* add type decl
  • Loading branch information
theosanderson authored Jan 15, 2025
1 parent a6e4084 commit 5567e12
Show file tree
Hide file tree
Showing 21 changed files with 646 additions and 0 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Integration tests
on:
workflow_dispatch:
pull_request:
paths:
- "backend/**"
- "keycloak/**"
- "kubernetes/**"
- "website/**"
- "deploy.py"
- "integration-tests/**"
- ".github/scripts/**"
- ".github/workflows/**"
push:
branches:
- main
jobs:
integration-tests:
permissions:
packages: read
contents: read
checks: read
actions: read # Required by workflow-telemetry-action
runs-on: ubuntu-latest
timeout-minutes: 45
env:
sha: ${{ github.event.pull_request.head.sha || github.sha }}
steps:
- name: Shorten sha
run: echo "sha=${sha::7}" >> $GITHUB_ENV
- name: Collect Workflow Telemetry
uses: catchpoint/workflow-telemetry-action@v2
- name: Checkout repository
uses: actions/checkout@v4
- name: Install k3d
run: |
curl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | bash
k3d version
- uses: azure/setup-helm@v4
- name: Create k3d cluster
run: |
./deploy.py --verbose cluster
- name: Deploy with helm
run: |
./deploy.py --verbose helm --branch ${{ github.ref_name }} --sha ${{ env.sha }} --for-e2e --enablePreprocessing
- uses: actions/setup-node@v4
with:
node-version-file: ./website/.nvmrc
- name: Cache .npm
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('integration-tests/**/package-lock.json') }}
- name: Install dependencies
run: cd integration-tests && npm i
- name: Get Installed Playwright Version
id: playwright-version
run: cd integration-tests && echo "PLAYWRIGHT_VERSION=$(node -e "console.log(require('./package-lock.json').packages['node_modules/@playwright/test'].version)")" >> $GITHUB_ENV
- name: Cache Playwright Browsers
uses: actions/cache@v4
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
- name: Install Playwright Browsers and System Dependencies
run: cd integration-tests && npx playwright install --with-deps
if: steps.playwright-cache.outputs.cache-hit != 'true'
- name: Install only System Dependencies
run: cd website && npx playwright install-deps
if: steps.playwright-cache.outputs.cache-hit == 'true'
- name: Wait for the pods to be ready
run: ./.github/scripts/wait_for_pods_to_be_ready.py --timeout 190
- name: Sleep for 10 secs
run: sleep 10
- name: Run Integration test
run: |
set -o pipefail
cd integration-tests && npx playwright test 2>&1 | tee output.txt
EXIT_CODE=$?
echo '```' >> $GITHUB_STEP_SUMMARY
sed -n '/Running [0-9]\+ tests/,$p' output.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
exit $EXIT_CODE
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: integration-tests/playwright-report/
retention-days: 30
- name: List running pods
if: ${{ !cancelled() }}
run: kubectl get pods --all-namespaces
- name: Describe pods
if: ${{ !cancelled() }}
run: kubectl describe pods -l app=loculus
- name: Show events
if: ${{ !cancelled() }}
run: kubectl get events
- name: Save logs from all containers to file
if: ${{ !cancelled() }}
run: ./.github/scripts/collect_kubernetes_logs.sh
- name: Upload Kubernetes logs
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: kubernetes-logs
path: kubernetes_logs/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ temp/

.aider*
.env

logs/
__pycache__/
5 changes: 5 additions & 0 deletions integration-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
15 changes: 15 additions & 0 deletions integration-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Integration tests

These are tests of the full Loculus system, following sequences through submission to preprocessing to release.

## Principles

Here are some current guiding principles for these tests:
- Only use facilities users could use (primarily browser interaction), rather than setting things up with backend calls. This makes it easy for others to understand the tests because they can follow them in the browser.
- All tests should be able to run in parallel. Mostly this can be carried out by creating a separate user/group for each test.


## Fixtures
There are some fixtures to help with the development of tests:
- `pageWithACreatedUser` creates a user account and logs into it
- `pageWithGroup` inherits from `pageWithACreatedUser` and in addition creates a group for the user
120 changes: 120 additions & 0 deletions integration-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions integration-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "integration_tests",
"version": "1.0.0",
"main": "index.js",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"@playwright/test": "^1.48.2",
"@types/node": "^22.8.3",
"@types/uuid": "^10.0.0",
"uuid": "^11.0.2"
}
}
45 changes: 45 additions & 0 deletions integration-tests/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://localhost:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
}
]
});
5 changes: 5 additions & 0 deletions integration-tests/start-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
../deploy.py cluster --delete
../deploy.py cluster
../deploy.py helm --for-e2e --enablePreprocessing
python ../.github/scripts/wait_for_pods_to_be_ready.py
31 changes: 31 additions & 0 deletions integration-tests/tests/fixtures/auth.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { test as base, Page } from '@playwright/test';

import { v4 as uuidv4 } from 'uuid';
import { AuthPage } from '../pages/auth.page';
import { TestAccount } from '../types/auth.types';

type TestFixtures = {
pageWithACreatedUser: Page;
testAccount: TestAccount;
};

export const test = base.extend<TestFixtures>({
testAccount: async ({}, use) => {
const testAccount : TestAccount = {
username: `test_user_${uuidv4().slice(0, 8)}`,
password: 'password',
email: `test_${uuidv4().slice(0, 8)}@test.com`,
firstName: 'Test',
lastName: 'User',
organization: 'Test University'
};
await use(testAccount);
},

pageWithACreatedUser: async ({ page, testAccount }, use) => {
const authPage = new AuthPage(page);
await authPage.createAccount(testAccount);
await use(page);
await authPage.logout();
},
});
Loading

0 comments on commit 5567e12

Please sign in to comment.