Skip to content

Commit

Permalink
Action workflow updated to test only after deployment on vercel
Browse files Browse the repository at this point in the history
  • Loading branch information
ad956 committed May 7, 2024
1 parent 23d6f4a commit e427d55
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
35 changes: 12 additions & 23 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
name: Patient Fitness Tracker Tests

name: Playwright Tests
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

deployment_status:
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest

if: github.event.deployment_status.state == 'success'
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js environment
uses: actions/[email protected]
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"

node-version: 18
- name: Install dependencies
run: npm ci

- name: Install playwright browsers
- name: Install Playwright
run: npx playwright install --with-deps

- name: Run tests
run: npm run test
- name: Run Playwright tests
run: npx playwright test
env:
PLAYWRIGHT_TEST_BASE_URL: ${{ github.event.deployment_status.target_url }}
4 changes: 4 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export async function redirectMiddleware(request: NextRequest) {
if (isPublicRoute && token) {
return NextResponse.redirect(new URL(`/${userRole}`, request.url));
}

if (isPrivateRoute && path.split("/")[1] !== userRole) {
return NextResponse.redirect(new URL(`/${userRole}`, request.url));
}
}
if (isPrivateRoute && !token) {
return NextResponse.redirect(new URL(`/login`, request.url));
Expand Down
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default defineConfig({
/* 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: "https://patient-fitness-tracker.vercel.app",
// baseURL: "https://patient-fitness-tracker.vercel.app",

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
Expand Down
4 changes: 2 additions & 2 deletions tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from "@playwright/test";

test("Displays the landing page correctly", async ({ page }) => {
test("Displays the landing page correctly", async ({ page, baseURL }) => {
// Navigate to the home page
await page.goto("/");
await page.goto(`${baseURL}`);

// Expect the main heading to be visible
await expect(
Expand Down

0 comments on commit e427d55

Please sign in to comment.