-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tests w/ Playwright * ..
- Loading branch information
Showing
6 changed files
with
199 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Playwright Tests | ||
on: | ||
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Install Playwright Browsers | ||
run: npx playwright install --with-deps | ||
- name: Run Playwright tests | ||
run: npx playwright test | ||
- uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
package-lock.json | ||
.vercel | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// @ts-check | ||
const { defineConfig, devices } = require("@playwright/test"); | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* @see https://playwright.dev/docs/test-configuration | ||
*/ | ||
module.exports = defineConfig({ | ||
testDir: "./tests", | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: process.env.CI ? "github" : "list", | ||
/* 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: "http://localhost:3030/tests", | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: "on-first-retry", | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: "chromium", | ||
use: { ...devices["Desktop Chrome"] }, | ||
}, | ||
|
||
// { | ||
// name: "firefox", | ||
// use: { ...devices["Desktop Firefox"] }, | ||
// }, | ||
|
||
{ | ||
name: "webkit", | ||
use: { ...devices["Desktop Safari"] }, | ||
}, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { ...devices['Pixel 5'] }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { ...devices['iPhone 12'] }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
webServer: { | ||
command: "npm run test:serve", | ||
url: "http://localhost:3030/tests", | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Sourdough Test</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<style> | ||
body { | ||
background: #eee; | ||
} | ||
</style> | ||
<link rel="stylesheet" href="../src/sourdough-toast.css" /> | ||
<script type="module"> | ||
import { Sourdough, toast } from "../src/sourdough-toast.js"; | ||
|
||
const sourdough = new Sourdough(); | ||
|
||
window.addEventListener("DOMContentLoaded", () => { | ||
sourdough.boot(); | ||
}); | ||
|
||
window.toast = toast; | ||
</script> | ||
</head> | ||
<body> | ||
<button onclick="toast('Basic toast')">Basic</button> | ||
<button onclick="toast.success('Success toast')">Success</button> | ||
<button onclick="toast.info('Info toast')">Info</button> | ||
<button onclick="toast.warning('Warning toast')">Warning</button> | ||
<button onclick="toast.error('Error toast')">Error</button> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// @ts-check | ||
const { test, expect } = require("@playwright/test"); | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto("/tests"); | ||
}); | ||
|
||
test("has title", async ({ page }) => { | ||
await expect(page).toHaveTitle("Sourdough Test"); | ||
}); | ||
|
||
test("a basic toast can render and then disappear after duration", async ({ | ||
page, | ||
}) => { | ||
await page.getByRole("button", { name: "Basic" }).click(); | ||
|
||
await expect(page.locator("[data-sourdough-toast]")).toHaveCount(1); | ||
await expect(page.locator("[data-sourdough-toast]")).toHaveCount(0); | ||
}); | ||
|
||
test("only renders max toasts", async ({ page }) => { | ||
await page.getByRole("button", { name: "Basic" }).click(); | ||
await page.getByRole("button", { name: "Basic" }).click(); | ||
await page.getByRole("button", { name: "Basic" }).click(); | ||
await page.getByRole("button", { name: "Basic" }).click(); | ||
|
||
await expect(page.locator("[data-sourdough-toast]")).toHaveCount(3); | ||
}); | ||
|
||
test("toast have types", async ({ page }) => { | ||
await page.getByRole("button", { name: "Success" }).click(); | ||
await expect(page.getByText("Success toast", { exact: true })).toHaveCount(1); | ||
|
||
await page.getByRole("button", { name: "Error" }).click(); | ||
await expect(page.getByText("Error toast", { exact: true })).toHaveCount(1); | ||
|
||
await page.getByRole("button", { name: "Warning" }).click(); | ||
await expect(page.getByText("Warning toast", { exact: true })).toHaveCount(1); | ||
|
||
await page.getByRole("button", { name: "Info" }).click(); | ||
await expect(page.getByText("Info toast", { exact: true })).toHaveCount(1); | ||
}); | ||
|
||
test("toasts don't dismiss when hovered", async ({ page }) => { | ||
await page.getByRole("button", { name: "Basic" }).click(); | ||
|
||
await page.hover("[data-sourdough-toast]"); | ||
await new Promise((resolve) => setTimeout(resolve, 5000)); | ||
|
||
await expect(page.locator("[data-sourdough-toast]")).toHaveCount(1); | ||
}); |