Skip to content

Commit

Permalink
feat: playwright tests (#136)
Browse files Browse the repository at this point in the history
* feat: playwright tests

* chore: commit package.lock

* fix: template tests

* chore: don't spam on telegram
  • Loading branch information
vincelwt authored Mar 11, 2024
1 parent d02385a commit 548c1b5
Show file tree
Hide file tree
Showing 21 changed files with 6,953 additions and 37 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: E2E Tests

on:
deployment_status:
jobs:
run-e2es:
if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: npm ci && npx playwright install --with-deps
- name: Run tests
run: npx playwright test
env:
BASE_URL: ${{ github.event.deployment_status.environment_url }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,12 @@ bun.lockb
*.Dockerfile
docker-compose*

package-lock.json

entrypoint.sh
packages/frontend/Frontend.code-workspace

/test-results/
/playwright-report/
/playwright/
/blob-report/
/playwright/.cache/
/e2e/.auth/
53 changes: 53 additions & 0 deletions e2e/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { test, expect } from "@playwright/test"

import { deleteOrg } from "./db-utils"

const authFile = "e2e/.auth/user.json"

test.beforeAll(async () => {
// Sometimes the teardown isn't called, so we need to clean up the database before running the tests
await deleteOrg()
})

test("signup flow", async ({ page }) => {
await page.goto("/")

await page.getByRole("link", { name: "Sign Up" }).click()

await page.waitForURL("**/signup")

await page.getByPlaceholder("Your email").click()
await page.getByPlaceholder("Your email").fill("[email protected]")

await page.getByPlaceholder("Your full name").click()
await page.getByPlaceholder("Your full name").fill("test test")

await page.getByPlaceholder("Your password").click()
await page.getByPlaceholder("Your password").fill("testtest")

await page.getByRole("button", { name: "Continue →" }).click()

await page.getByPlaceholder("Your project name").click()
await page.getByPlaceholder("Your project name").fill("TESTPROJECT")

await page.getByPlaceholder("Organization name").click()
await page.getByPlaceholder("Organization name").fill("TESTORG")

await page.getByLabel("-49").check()

await page.getByRole("button", { name: "Create account" }).click()

await page.waitForNavigation()

await expect(page.getByText("Are you free in the next days")).toBeVisible()

await page.getByRole("button", { name: "Skip to Dashboard" }).click()

await page.waitForURL("**/analytics")

await expect(
page.getByRole("heading", { name: "Waiting for data..." }),
).toBeVisible()

await page.context().storageState({ path: authFile })
})
13 changes: 13 additions & 0 deletions e2e/db-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sql from "../packages/backend/src/utils/db"

export async function setOrgPro() {
await sql`update org set plan = 'pro' where name = 'TESTORG'`

Check failure on line 4 in e2e/db-utils.ts

View workflow job for this annotation

GitHub Actions / run-e2es

[chromium] › templates.spec.ts:15:5 › create new template and test basic playground

2) [chromium] › templates.spec.ts:15:5 › create new template and test basic playground ─────────── Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: connect ECONNREFUSED 88.198.48.232:5432 at db-utils.ts:4 2 | 3 | export async function setOrgPro() { > 4 | await sql`update org set plan = 'pro' where name = 'TESTORG'` | ^ 5 | } 6 | 7 | export async function setOrgFree() { at cachedError (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/query.js:170:23) at Query (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/query.js:36:24) at sql (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/index.js:112:11) at setOrgPro (/home/runner/work/lunary/lunary/e2e/db-utils.ts:4:13)

Check failure on line 4 in e2e/db-utils.ts

View workflow job for this annotation

GitHub Actions / run-e2es

[chromium] › templates.spec.ts:15:5 › create new template and test basic playground

2) [chromium] › templates.spec.ts:15:5 › create new template and test basic playground ─────────── Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: connect ECONNREFUSED 88.198.48.232:5432 at db-utils.ts:4 2 | 3 | export async function setOrgPro() { > 4 | await sql`update org set plan = 'pro' where name = 'TESTORG'` | ^ 5 | } 6 | 7 | export async function setOrgFree() { at cachedError (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/query.js:170:23) at Query (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/query.js:36:24) at sql (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/index.js:112:11) at setOrgPro (/home/runner/work/lunary/lunary/e2e/db-utils.ts:4:13)
}

export async function setOrgFree() {
await sql`update org set plan = 'free' where name = 'TESTORG'`

Check failure on line 8 in e2e/db-utils.ts

View workflow job for this annotation

GitHub Actions / run-e2es

[chromium] › templates.spec.ts:34:5 › create new template and deploy

3) [chromium] › templates.spec.ts:34:5 › create new template and deploy ────────────────────────── Error: connect ECONNREFUSED 88.198.48.232:5432 at db-utils.ts:8 6 | 7 | export async function setOrgFree() { > 8 | await sql`update org set plan = 'free' where name = 'TESTORG'` | ^ 9 | } 10 | 11 | export async function deleteOrg() { at cachedError (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/query.js:170:23) at Query (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/query.js:36:24) at sql (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/index.js:112:11) at setOrgFree (/home/runner/work/lunary/lunary/e2e/db-utils.ts:8:13)
}

export async function deleteOrg() {
await sql`delete from org where name = 'TESTORG'`

Check failure on line 12 in e2e/db-utils.ts

View workflow job for this annotation

GitHub Actions / run-e2es

[teardown] › global.teardown.ts:4:5 › clean up database

1) [teardown] › global.teardown.ts:4:5 › clean up database ─────────────────────────────────────── Error: connect ECONNREFUSED 88.198.48.232:5432 at db-utils.ts:12 10 | 11 | export async function deleteOrg() { > 12 | await sql`delete from org where name = 'TESTORG'` | ^ 13 | } 14 | at cachedError (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/query.js:170:23) at Query (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/query.js:36:24) at sql (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/index.js:112:11) at deleteOrg (/home/runner/work/lunary/lunary/e2e/db-utils.ts:12:13)

Check failure on line 12 in e2e/db-utils.ts

View workflow job for this annotation

GitHub Actions / run-e2es

[teardown] › global.teardown.ts:4:5 › clean up database

1) [teardown] › global.teardown.ts:4:5 › clean up database ─────────────────────────────────────── Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: connect ECONNREFUSED 88.198.48.232:5432 at db-utils.ts:12 10 | 11 | export async function deleteOrg() { > 12 | await sql`delete from org where name = 'TESTORG'` | ^ 13 | } 14 | at cachedError (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/query.js:170:23) at Query (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/query.js:36:24) at sql (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/index.js:112:11) at deleteOrg (/home/runner/work/lunary/lunary/e2e/db-utils.ts:12:13)

Check failure on line 12 in e2e/db-utils.ts

View workflow job for this annotation

GitHub Actions / run-e2es

[teardown] › global.teardown.ts:4:5 › clean up database

1) [teardown] › global.teardown.ts:4:5 › clean up database ─────────────────────────────────────── Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: connect ECONNREFUSED 88.198.48.232:5432 at db-utils.ts:12 10 | 11 | export async function deleteOrg() { > 12 | await sql`delete from org where name = 'TESTORG'` | ^ 13 | } 14 | at cachedError (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/query.js:170:23) at Query (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/query.js:36:24) at sql (/home/runner/work/lunary/lunary/node_modules/postgres/cjs/src/index.js:112:11) at deleteOrg (/home/runner/work/lunary/lunary/e2e/db-utils.ts:12:13)
}
6 changes: 6 additions & 0 deletions e2e/global.teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { test } from "@playwright/test"
import { deleteOrg } from "./db-utils"

test("clean up database", async ({}) => {
await deleteOrg()
})
22 changes: 22 additions & 0 deletions e2e/login.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { test, expect } from "@playwright/test"

test("logout and login flow", async ({ page }) => {
await page.goto("/")

// logout
await page.getByTestId("account-sidebar-item").click()
await page.getByTestId("logout-button").click()

await page.waitForURL("**/login")

// log back in
await page.getByPlaceholder("Your email").click()
await page.getByPlaceholder("Your email").fill("[email protected]")

await page.getByPlaceholder("Your password").click()
await page.getByPlaceholder("Your password").fill("testtest")

await page.getByRole("button", { name: "Login" }).click()

await page.waitForURL("**/analytics")
})
30 changes: 30 additions & 0 deletions e2e/projects.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { test, expect } from "@playwright/test"
import { setOrgFree, setOrgPro } from "./db-utils"

test.beforeAll(async () => {
// need to be pro for multiple projects
await setOrgPro()
})

test.afterAll(async () => {
await setOrgFree()
})

test("create new project and rename it", async ({ page }) => {
await page.goto("/")

//wait for requests to finish
await page.waitForLoadState("networkidle")

await page.getByRole("button", { name: "TESTPROJECT" }).click()

await page.getByTestId("new-project").click()

await page.getByRole("heading", { name: "Project #" }).click()
await page.getByTestId("rename-input").fill("TESTPROJECT2")
await page.getByTestId("rename-input").press("Enter")

await expect(
page.getByRole("heading", { name: "TESTPROJECT2" }),
).toBeVisible()
})
54 changes: 54 additions & 0 deletions e2e/templates.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { test, expect } from "@playwright/test"
import { setOrgFree, setOrgPro } from "./db-utils"

test.beforeAll(async () => {
await setOrgPro()
})

test.afterAll(async () => {
await setOrgFree()
})

// run tests one after another
test.describe.configure({ mode: "serial" })

test("create new template and test basic playground", async ({ page }) => {
await page.goto("/prompts")

await page.waitForLoadState("networkidle")

await page.getByTestId("empty-action").click()

await page.getByTestId("rename-template-input").fill("first-template")
await page.getByTestId("rename-template-input").press("Enter")

await expect(page.getByText("first-template")).toBeVisible()

await page.getByTestId("run-playground").click()

// assistant's response
await expect(page.getByText("Hello!")).toBeVisible()
await expect(page.locator("#HERE").getByText("assistant")).toBeVisible()
})

test("create new template and deploy", async ({ page }) => {
await page.goto("/prompts")

await page.waitForLoadState("networkidle")

await page.getByTestId("create-template").click()

await page.getByTestId("rename-template-input").fill("test-template")
await page.getByTestId("rename-template-input").press("Enter")

await page.getByTestId("deploy-template").click()

await expect(page.getByText("Template deployed")).toBeVisible()

await page.getByText("Hi!").click()
await page.getByText("Hi!").fill("This is another test")

await page.getByTestId("save-template").click()

await expect(page.locator("a").filter({ hasText: "v2" })).toBeVisible()
})
Loading

0 comments on commit 548c1b5

Please sign in to comment.