Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

Add e2e tests (#242)

Marc Klingen74a877240977
diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml
index 25133fa4b4..6f67de1e53 100644
--- a/.github/workflows/pipeline.yml
+++ b/.github/workflows/pipeline.yml
@@ -56,10 +56,40 @@ jobs:
- name: run tests
run: npm run test
+ e2e-tests:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: 18
+ cache: "npm"
+ - name: install dependencies
+ run: |
+ npm ci
+
+ - name: Load default env
+ run: |
+ cp .env.dev.example .env
+
+ - name: Run, migrate, seed DB
+ run: |
+ docker-compose -f docker-compose.dev.yml up -d
+ npx --yes prisma migrate reset --force --skip-generate
+
+ - name: Build
+ run: npm run build
+
+ - name: Install playwright
+ run: npx playwright install --with-deps
+
+ - name: Run e2e tests
+ run: npm run test:e2e
+
all-ci-passed:
# This allows us to have a branch protection rule for tests and deploys with matrix
runs-on: ubuntu-latest
- needs: [lint, tests]
+ needs: [lint, tests, e2e-tests]
if: always()
steps:
- name: Successful deploy
diff --git a/package-lock.json b/package-lock.json
index 7edad1d75a..1f8f7ffea8 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -78,6 +78,7 @@
"zod": "^3.22.2"
},
"devDependencies": {
+ "@playwright/test": "^1.38.0",
"@testing-library/jest-dom": "^6.1.3",
"@types/bcryptjs": "^2.4.4",
"@types/cors": "^2.8.14",
@@ -2059,6 +2060,21 @@
"node": ">=14"
}
},
+ "node_modules/@playwright/test": {
+ "version": "1.38.0",
+ "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.38.0.tgz",
+ "integrity": "sha512-xis/RXXsLxwThKnlIXouxmIvvT3zvQj1JE39GsNieMUrMpb3/GySHDh2j8itCG22qKVD4MYLBp7xB73cUW/UUw==",
+ "dev": true,
+ "dependencies": {
+ "playwright": "1.38.0"
+ },
+ "bin": {
+ "playwright": "cli.js"
+ },
+ "engines": {
+ "node": ">=16"
+ }
+ },
"node_modules/@prisma/client": {
"version": "5.3.1",
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.3.1.tgz",
@@ -10787,6 +10803,50 @@
"node": ">=8"
}
},
+ "node_modules/playwright": {
+ "version": "1.38.0",
+ "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.38.0.tgz",
+ "integrity": "sha512-fJGw+HO0YY+fU/F1N57DMO+TmXHTrmr905J05zwAQE9xkuwP/QLDk63rVhmyxh03dYnEhnRbsdbH9B0UVVRB3A==",
+ "dev": true,
+ "dependencies": {
+ "playwright-core": "1.38.0"
+ },
+ "bin": {
+ "playwright": "cli.js"
+ },
+ "engines": {
+ "node": ">=16"
+ },
+ "optionalDependencies": {
+ "fsevents": "2.3.2"
+ }
+ },
+ "node_modules/playwright-core": {
+ "version": "1.38.0",
+ "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.38.0.tgz",
+ "integrity": "sha512-f8z1y8J9zvmHoEhKgspmCvOExF2XdcxMW8jNRuX4vkQFrzV4MlZ55iwb5QeyiFQgOFCUolXiRHgpjSEnqvO48g==",
+ "dev": true,
+ "bin": {
+ "playwright-core": "cli.js"
+ },
+ "engines": {
+ "node": ">=16"
+ }
+ },
+ "node_modules/playwright/node_modules/fsevents": {
+ "version": "2.3.2",
+ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
+ "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
+ "dev": true,
+ "hasInstallScript": true,
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
+ }
+ },
"node_modules/postcss": {
"version": "8.4.30",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.30.tgz",
diff --git a/package.json b/package.json
index 82b19ef833..8baa5665a1 100644
--- a/package.json
+++ b/package.json
@@ -13,6 +13,7 @@
"start": "next start",
"test": "jest --verbose=true --runInBand",
"test:watch": "jest --watch --runInBand",
+ "test:e2e": "playwright test",
"db:migrate": "npx prisma migrate dev",
"db:seed": "npx prisma db seed",
"db:seed:examples": "npx prisma db seed -- --environment examples"
@@ -90,6 +91,7 @@
"zod": "^3.22.2"
},
"devDependencies": {
+ "@playwright/test": "^1.38.0",
"@testing-library/jest-dom": "^6.1.3",
"@types/bcryptjs": "^2.4.4",
"@types/cors": "^2.8.14",
diff --git a/playwright.config.ts b/playwright.config.ts
new file mode 100644
index 0000000000..7de428adc5
--- /dev/null
+++ b/playwright.config.ts
@@ -0,0 +1,15 @@
+import { defineConfig } from "@playwright/test";
+
+export default defineConfig({
+ use: {
+ /* Base URL to use in actions like `await page.goto('/')`. */
+ baseURL: "http://localhost:3000",
+ },
+ webServer: {
+ command: process.env.CI ? "npm run start" : "npm run dev",
+ url: "http://127.0.0.1:3000",
+ reuseExistingServer: !process.env.CI,
+ stdout: "ignore",
+ stderr: "pipe",
+ },
+});
diff --git a/src/__e2e__/auth.spec.ts b/src/__e2e__/auth.spec.ts
new file mode 100644
index 0000000000..d796e086cd
--- /dev/null
+++ b/src/__e2e__/auth.spec.ts
@@ -0,0 +1,27 @@
+import { test, expect } from "@playwright/test";
+
+test("should redirect to sign-in if not signed in", async ({ page }) => {
+ await page.goto("/");
+ await expect(page).toHaveURL("/auth/sign-in");
+});
+
+test("should redirect to home if signed in", async ({ page }) => {
+ await page.goto("/auth/sign-in");
+ await page.fill('input[name="email"]', "[email protected]");
+ await page.fill('input[type="password"]', "password");
+ await page.click('button[type="submit"]');
+
+ // wait 2 seconds
+ await page.waitForTimeout(2000);
+
+ if (process.env.CI)
+ await expect(page).toHaveURL(
+ // project id from seed.ts
+ "/project/7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ );
+ else
+ console.log(
+ "Test skipped as redirect depends on db state, URL after signing in:",
+ page.url(),
+ );
+});