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: run e2e tests during deployment #186

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 22 additions & 1 deletion .github/workflows/pr-frontend-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ concurrency:
on:
pull_request:
branches:
- "*"
- '*'
paths:
- apps/web/**
jobs:
Expand Down Expand Up @@ -74,3 +74,24 @@ jobs:

- name: Run Vite tests
run: pnpm test

e2e:
name: Playwright Tests
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v1.45.3-jammy
defaults:
run:
working-directory: ./apps/web/
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20.15.0
- name: Install dependencies
run: pnpm install
- name: Run your tests
run: pnpm playwright test
env:
HOME: /root
34 changes: 18 additions & 16 deletions apps/web/e2e/register.spec.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
import { test, expect } from "@playwright/test";
import { test, expect } from '@playwright/test';

test.describe("register page", () => {
test.describe('register page', () => {
test.beforeEach(async ({ page }) => {
await page.goto("/auth/register");
await page.goto('/auth/register');
});

test("register user", async ({ page }) => {
await page.getByLabel("email").fill("[email protected]");
await page.getByLabel("password").fill("password");
test('register user', async ({ page }) => {
await page.getByLabel('email').fill('[email protected]');
await page.getByLabel('password').fill('password');
await page.getByLabel('first name').fill('John');
await page.getByLabel('last name').fill('Student');

await page.route("**/auth/register", async (route) => {
await page.route('**/auth/register', async (route) => {
await route.fulfill({
status: 201,
contentType: "application/json",
json: { data: { email: "", id: "", createdAt: "", updatedAt: "" } },
contentType: 'application/json',
json: { data: { email: '', id: '', createdAt: '', updatedAt: '' } },
});
});

await page.getByRole("button", { name: /create/i }).click();
await page.getByRole('button', { name: /create/i }).click();

await expect(page).toHaveURL(/login/);
});

test("fail on invalid credentials", async ({ page }) => {
await page.getByLabel("email").fill("user@example");
await page.getByLabel("password").fill("pass");
test('fail on invalid credentials', async ({ page }) => {
await page.getByLabel('email').fill('user@example');
await page.getByLabel('password').fill('pass');

await page.getByRole("button", { name: /create/i }).click();
await page.getByRole('button', { name: /create/i }).click();

await expect(page.getByText("Invalid email")).toBeVisible();
await expect(page.getByText('Invalid email')).toBeVisible();
await expect(
page.getByText("Password must be at least 8 characters")
page.getByText('Password must be at least 8 characters')
).toBeVisible();
});
});
16 changes: 8 additions & 8 deletions apps/web/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { defineConfig, devices } from "@playwright/test";
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
testDir: "./e2e",
testDir: './e2e',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
use: {
baseURL: process.env.CI
? "https://staging-url.example.com"
: "https://app.lms.localhost",
? 'https://lms.beta.selleo.app'
: 'https://app.lms.localhost',
ignoreHTTPSErrors: true,
// launchOptions: {
// args: [
Expand All @@ -25,12 +25,12 @@ export default defineConfig({

projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
{
name: "firefox",
use: { ...devices["Desktop Firefox"] },
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
],
});
Loading