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

test: setup Playwright #3

Merged
merged 7 commits into from
May 1, 2024
Merged
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
34 changes: 34 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,37 @@ jobs:

- name: 🛠️ Generate static site
run: pnpm generate

# run Playwright tests in parallel job to speed up workflow speed
playwright:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v3

- name: Setup Node.js
uses: actions/setup-node@v4
with:
cache: pnpm

- name: 📦 Install dependencies
run: pnpm install

# install system dependencies for Playwright
# see: https://playwright.dev/docs/browsers#install-system-dependencies
- name: 📦 Install Playwright system dependencies
run: pnpm exec playwright install-deps

- name: 🧪 Run tests
run: pnpm test:playwright

# upload report if tests failed for debugging
- uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: playwright-report
path: |
playwright-report/
test-results/
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ logs
.env
.env.*
!.env.example

# Tests
playwright-report
test-results
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Additional features:

- [nuxt i18n](https://nuxt.com/modules/i18n)
- [eslint](https://nuxt.com/modules/eslint) and [prettier](https://prettier.io/) setup (also runs pre-commit)
- [Playwright](https://playwright.dev) for testing
- [Docker](https://www.docker.com) setup
- GitHub action to check and build code in CI

Expand Down
5 changes: 5 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// @ts-check
import playwright from "eslint-plugin-playwright";
import withNuxt from "./.nuxt/eslint.config.mjs";

export default withNuxt([
// Your custom configs here
{
...playwright.configs["flat/recommended"],
files: ["tests/**"],
},
]);
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"test:playwright": "playwright install && playwright test",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier --write .",
Expand All @@ -23,6 +24,9 @@
},
"devDependencies": {
"@nuxt/eslint": "~0.3.10",
"@nuxt/test-utils": "^3.12.1",
"@playwright/test": "~1.43.1",
"eslint-plugin-playwright": "^1.6.0",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"sass": "^1.76.0",
Expand Down
27 changes: 27 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { ConfigOptions } from "@nuxt/test-utils/playwright";
import { defineConfig, devices } from "@playwright/test";
import { fileURLToPath } from "node:url";

/**
* Global Playwright configuration.
*
* @see https://playwright.dev/docs/test-configuration.
*/
export default defineConfig<ConfigOptions>({
testDir: "./tests",
fullyParallel: true,
forbidOnly: !!process.env.CI,
reporter: [["html", { open: "never" }]],
use: {
trace: process.env.CI ? "retain-on-failure" : "off",
video: process.env.CI ? "retain-on-failure" : "off",
nuxt: {
rootDir: fileURLToPath(new URL(".", import.meta.url)),
},
},
projects: [
{ name: "chromium", use: { ...devices["Desktop Chrome"] } },
{ name: "firefox", use: { ...devices["Desktop Firefox"] } },
{ name: "webkit", use: { ...devices["Desktop Safari"] } },
],
});
165 changes: 165 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { expect, test } from "@nuxt/test-utils/playwright";

test("example test", async ({ page, goto }) => {
await goto("/", { waitUntil: "hydration" });
await expect(page.getByRole("heading", { name: "Welcome to Nuxt!" })).toBeVisible();
});