From 87c7a8a13cfdef923229b04948fccc052eb6eeb2 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 31 Aug 2023 11:47:12 +0100 Subject: [PATCH] test: test deploy previews with e2e suite --- .e2e/tests/advanced/config-extends.spec.ts | 3 ++- .e2e/tests/advanced/error-handling.spec.ts | 3 ++- .e2e/tests/advanced/jsx.spec.ts | 3 ++- .e2e/tests/advanced/locale.spec.ts | 3 ++- .e2e/tests/advanced/module-extend-pages.spec.ts | 3 ++- .e2e/tests/advanced/use-cookie.spec.ts | 3 ++- .e2e/tests/experimental/wasm.spec.ts | 3 ++- .e2e/tests/features/auto-imports.spec.ts | 3 ++- .e2e/tests/features/data-fetching.spec.ts | 3 ++- .e2e/tests/features/meta-tags.spec.ts | 3 ++- .e2e/tests/features/state-management.spec.ts | 1 + .e2e/tests/hello-world.spec.ts | 3 ++- .e2e/tests/routing/middleware.spec.ts | 4 ++-- .e2e/tests/routing/pages.spec.ts | 3 ++- .e2e/tests/routing/universal-router.spec.ts | 3 ++- .e2e/tests/ui/daisyui.spec.ts | 3 ++- .e2e/tests/ui/sass.spec.ts | 3 ++- .e2e/tests/ui/tailwindcss.spec.ts | 3 ++- .e2e/tests/ui/vuetify.spec.ts | 3 ++- .e2e/utils/index.ts | 3 +++ .github/workflows/playwright.yml | 16 +++++++++++++++- 21 files changed, 55 insertions(+), 20 deletions(-) diff --git a/.e2e/tests/advanced/config-extends.spec.ts b/.e2e/tests/advanced/config-extends.spec.ts index aba87886..15fcf62d 100644 --- a/.e2e/tests/advanced/config-extends.spec.ts +++ b/.e2e/tests/advanced/config-extends.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://config-extends.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('config-extends') }) test("App config merged", async ({ page }) => { // TODO need a unique locator diff --git a/.e2e/tests/advanced/error-handling.spec.ts b/.e2e/tests/advanced/error-handling.spec.ts index 67712b75..735ff51c 100644 --- a/.e2e/tests/advanced/error-handling.spec.ts +++ b/.e2e/tests/advanced/error-handling.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect, Page } from "@playwright/test" -test.use({ baseURL: "https://error-handling.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('error-handling') }) test("Home page loads without any errors", async ({ page }) => { await page.goto("/") diff --git a/.e2e/tests/advanced/jsx.spec.ts b/.e2e/tests/advanced/jsx.spec.ts index 87e8bcb8..f05c2785 100644 --- a/.e2e/tests/advanced/jsx.spec.ts +++ b/.e2e/tests/advanced/jsx.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://jsx.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('jsx') }) test.beforeEach(async ({ page }) => { await page.goto("/") }) diff --git a/.e2e/tests/advanced/locale.spec.ts b/.e2e/tests/advanced/locale.spec.ts index df83552b..428d7a84 100644 --- a/.e2e/tests/advanced/locale.spec.ts +++ b/.e2e/tests/advanced/locale.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://locale.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('locale') }) test.beforeEach(async ({ page }) => { await page.goto("/") }) diff --git a/.e2e/tests/advanced/module-extend-pages.spec.ts b/.e2e/tests/advanced/module-extend-pages.spec.ts index dc84ff64..8cfa0b5e 100644 --- a/.e2e/tests/advanced/module-extend-pages.spec.ts +++ b/.e2e/tests/advanced/module-extend-pages.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://module-extend-pages.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('module-extend-pages') }) test.beforeEach(async ({ page }) => { await page.goto("/") }) diff --git a/.e2e/tests/advanced/use-cookie.spec.ts b/.e2e/tests/advanced/use-cookie.spec.ts index cbde0421..4314df7b 100644 --- a/.e2e/tests/advanced/use-cookie.spec.ts +++ b/.e2e/tests/advanced/use-cookie.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://use-cookie.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('use-cookie') }) test("Login screen shows by default", async ({ page }) => { await page.goto("/") diff --git a/.e2e/tests/experimental/wasm.spec.ts b/.e2e/tests/experimental/wasm.spec.ts index 273b57f9..d56d6290 100644 --- a/.e2e/tests/experimental/wasm.spec.ts +++ b/.e2e/tests/experimental/wasm.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://wasm.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('wasm') }) test.beforeEach(async ({ page }) => { await page.goto("/") }) diff --git a/.e2e/tests/features/auto-imports.spec.ts b/.e2e/tests/features/auto-imports.spec.ts index 966b376d..b530f82e 100644 --- a/.e2e/tests/features/auto-imports.spec.ts +++ b/.e2e/tests/features/auto-imports.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://auto-imports.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('auto-imports') }) test.beforeEach(async ({ page }) => { await page.goto("/") }) diff --git a/.e2e/tests/features/data-fetching.spec.ts b/.e2e/tests/features/data-fetching.spec.ts index d8a99548..9eac76fc 100644 --- a/.e2e/tests/features/data-fetching.spec.ts +++ b/.e2e/tests/features/data-fetching.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://data-fetching.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('data-fetching') }) test.describe("Index page", () => { test("Hello world is shown on the index page", async ({ page }) => { diff --git a/.e2e/tests/features/meta-tags.spec.ts b/.e2e/tests/features/meta-tags.spec.ts index 2525fadd..1ef44b80 100644 --- a/.e2e/tests/features/meta-tags.spec.ts +++ b/.e2e/tests/features/meta-tags.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://meta-tags.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('meta-tags') }) const INDEX_LANG = "en" const INDEX_DEFAULT_TITLE = "Lucky number: 1 - Meta Tags Example" diff --git a/.e2e/tests/features/state-management.spec.ts b/.e2e/tests/features/state-management.spec.ts index bb891a9b..4e561676 100644 --- a/.e2e/tests/features/state-management.spec.ts +++ b/.e2e/tests/features/state-management.spec.ts @@ -1,3 +1,4 @@ +import { getURLForDeployment } from "@/utils" import { test, expect, type Page } from "@playwright/test" test.use({ baseURL: "https://state-management.example.nuxt.space//" }) diff --git a/.e2e/tests/hello-world.spec.ts b/.e2e/tests/hello-world.spec.ts index 3fc6b464..d477f51a 100644 --- a/.e2e/tests/hello-world.spec.ts +++ b/.e2e/tests/hello-world.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://hello-world.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('hello-world') }) test.beforeEach(async ({ page }) => { await page.goto("/") }) diff --git a/.e2e/tests/routing/middleware.spec.ts b/.e2e/tests/routing/middleware.spec.ts index d2ae32c4..e1e6a580 100644 --- a/.e2e/tests/routing/middleware.spec.ts +++ b/.e2e/tests/routing/middleware.spec.ts @@ -1,7 +1,7 @@ -import { wait } from "@/utils" +import { getURLForDeployment, wait } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://middleware.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('middleware') }) test("Global middleware is being registered", async ({ page }) => { const globalMiddlewareMessageLoggedPromise = page.waitForEvent("console", { diff --git a/.e2e/tests/routing/pages.spec.ts b/.e2e/tests/routing/pages.spec.ts index 56ccf662..8b883388 100644 --- a/.e2e/tests/routing/pages.spec.ts +++ b/.e2e/tests/routing/pages.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://pages.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('pages') }) test.describe("Linked pages", () => { test.beforeEach(async ({ page }) => { diff --git a/.e2e/tests/routing/universal-router.spec.ts b/.e2e/tests/routing/universal-router.spec.ts index a975239e..6280864b 100644 --- a/.e2e/tests/routing/universal-router.spec.ts +++ b/.e2e/tests/routing/universal-router.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://universal-router.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('universal-router') }) test("Global middleware is being registered", async ({ page }) => { const globalMiddlewareMessageLoggedPromise = page.waitForEvent("console", { diff --git a/.e2e/tests/ui/daisyui.spec.ts b/.e2e/tests/ui/daisyui.spec.ts index e9ba992d..2e1b6f8c 100644 --- a/.e2e/tests/ui/daisyui.spec.ts +++ b/.e2e/tests/ui/daisyui.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://daisyui.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('daisyui') }) test.beforeEach(async ({ page }) => { await page.goto("/") }) diff --git a/.e2e/tests/ui/sass.spec.ts b/.e2e/tests/ui/sass.spec.ts index fa00ed9e..4a46912d 100644 --- a/.e2e/tests/ui/sass.spec.ts +++ b/.e2e/tests/ui/sass.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://sass.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('sass') }) test.beforeEach(async ({ page }) => { await page.goto("/") }) diff --git a/.e2e/tests/ui/tailwindcss.spec.ts b/.e2e/tests/ui/tailwindcss.spec.ts index 175f498c..b9ed2949 100644 --- a/.e2e/tests/ui/tailwindcss.spec.ts +++ b/.e2e/tests/ui/tailwindcss.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://tailwindcss.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('tailwindcss') }) test.beforeEach(async ({ page }) => { await page.goto("/") }) diff --git a/.e2e/tests/ui/vuetify.spec.ts b/.e2e/tests/ui/vuetify.spec.ts index dc00d4f7..ee1062bc 100644 --- a/.e2e/tests/ui/vuetify.spec.ts +++ b/.e2e/tests/ui/vuetify.spec.ts @@ -1,6 +1,7 @@ +import { getURLForDeployment } from "@/utils" import { test, expect } from "@playwright/test" -test.use({ baseURL: "https://vuetify.example.nuxt.space/" }) +test.use({ baseURL: getURLForDeployment('vuetify') }) test.beforeEach(async ({ page }) => { await page.goto("/") }) diff --git a/.e2e/utils/index.ts b/.e2e/utils/index.ts index fd47489d..e3a3cceb 100644 --- a/.e2e/utils/index.ts +++ b/.e2e/utils/index.ts @@ -1,2 +1,5 @@ export const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) + +export const getURLForDeployment = (slug: string) => + process.env.DEPLOY_URL ? `${process.env.DEPLOY_URL}?force=${slug}` : `https://${slug}.example.nuxt.space/` diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 5aa80829..9f6aa65a 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -1,6 +1,18 @@ name: Playwright Tests -on: workflow_dispatch +on: + workflow_dispatch: + inputs: + url: + required: false + description: The URL to run the test suite against. If omitted, it runs against all. + type: string + push: + branches: + - main + pull_request: + branches: + - main jobs: test: @@ -22,6 +34,8 @@ jobs: - name: Run Playwright tests run: pnpm --filter e2e test:all + env: + DEPLOY_URL: ${{ github.event.inputs.url || github.event.deployment.payload.web_url || github.event.deployment_status.target_url }} - uses: actions/upload-artifact@v3 if: always()