Skip to content

Commit f7fb0c6

Browse files
Test/e2e login auth (#19)
* Add basic test for login and auth state * Remove test file * Change login setup * Apply suggestions from code review Co-authored-by: Martin Braquet <[email protected]> * Change signin structure to use UI * Fix URL loading * Spin up backend server as well for E2E --------- Co-authored-by: Martin Braquet <[email protected]>
1 parent e5fc734 commit f7fb0c6

File tree

14 files changed

+97
-12
lines changed

14 files changed

+97
-12
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,15 @@ jobs:
6767
NEXT_PUBLIC_SUPABASE_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_KEY }}
6868
run: |
6969
npx nyc --reporter=lcov yarn --cwd=web serve &
70+
npx nyc --reporter=lcov yarn --cwd=backend/api dev &
7071
npx wait-on http://localhost:3000
7172
npx playwright test tests/e2e
7273
SERVER_PID=$(fuser -k 3000/tcp)
7374
echo $SERVER_PID
7475
kill $SERVER_PID
76+
SERVER_PID=$(fuser -k 8088/tcp)
77+
echo $SERVER_PID
78+
kill $SERVER_PID
7579
7680
- name: Upload coverage to Codecov
7781
uses: codecov/codecov-action@v5

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
# Playwright
1717
/tests/reports/playwright-report
18+
/tests/e2e/web/.auth/
1819

1920
# next.js
2021
/.next/

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"test:coverage": "yarn workspaces run test --coverage",
2525
"test:watch": "yarn workspaces run test --watch",
2626
"test:update": "yarn workspaces run test --updateSnapshot",
27+
"test:e2e": "./scripts/e2e.sh",
2728
"playwright": "playwright test",
2829
"playwright:ui": "playwright test --ui",
2930
"playwright:debug": "playwright test --debug",

playwright.config.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineConfig, devices } from '@playwright/test';
2+
import path from 'path';
23

34
export default defineConfig({
45
testDir: './tests/e2e',
@@ -13,8 +14,9 @@ export default defineConfig({
1314
},
1415
projects: [
1516
{
16-
name: 'chromium',
17-
use: { ...devices['Desktop Chrome'] },
17+
name: 'main',
18+
use: {
19+
...devices['Desktop Chrome'], },
1820
},
1921
// {
2022
// name: 'firefox',
@@ -25,4 +27,5 @@ export default defineConfig({
2527
// use: { ...devices['Desktop Safari'] },
2628
// },
2729
],
28-
});
30+
31+
});

scripts/e2e.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ export NEXT_PUBLIC_API_URL=localhost:8088
1010
export NEXT_PUBLIC_FIREBASE_ENV=DEV
1111

1212
npx nyc --reporter=lcov yarn --cwd=web serve &
13+
npx nyc --reporter=lcov yarn --cwd=backend/api dev &
1314
npx wait-on http://localhost:3000
1415
npx playwright test tests/e2e
1516
SERVER_PID=$(fuser -k 3000/tcp)
1617
echo $SERVER_PID
1718
kill $SERVER_PID
1819

20+
SERVER_PID=$(fuser -k 8088/tcp)
21+
echo $SERVER_PID
22+
kill $SERVER_PID

tests/e2e/web/.auth/.keep

Whitespace-only changes.

tests/e2e/web/TESTING_CONFIG.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const config = {
2+
BASE_URL: 'http://localhost:3000',
3+
DEFAULT_LOGIN: '[email protected]',
4+
DEFAULT_PASSWORD: 'defaultPassword',
5+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { test as base, Page, expect } from '@playwright/test';
2+
import { SignInPage } from '../pages/signInPage';
3+
import { config } from '../TESTING_CONFIG';
4+
5+
export const test = base.extend<{
6+
authenticatedPage: Page;
7+
}>({
8+
authenticatedPage: async ({ page }, use) => {
9+
const signInPage = new SignInPage(page);
10+
11+
await page.goto('/signin');
12+
await signInPage.fillEmailField(config.DEFAULT_LOGIN);
13+
await signInPage.fillPasswprdField(config.DEFAULT_PASSWORD);
14+
await signInPage.clickSignInWithEmailButton();
15+
16+
await page.waitForLoadState('networkidle');
17+
18+
await page.waitForURL('/');
19+
20+
expect(page.url()).not.toContain('/signin')
21+
22+
await use(page);
23+
},
24+
});

tests/e2e/web/pageManager/.keep

Whitespace-only changes.

tests/e2e/web/pages/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)