Skip to content

Commit

Permalink
Update to svelte 5 mount (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
gauntface authored Nov 2, 2024
1 parent 9720393 commit 845581b
Show file tree
Hide file tree
Showing 26 changed files with 423 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NODE_ENV=development
BUILD_TYPE=development
1 change: 1 addition & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
VITE_SENTRY_DSN="https://0b9cdcee8d8040edb9cc9586ecb52a14@o1296550.ingest.sentry.io/6556279"
BUILD_TYPE="production"
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BUILD_TYPE=test
11 changes: 11 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,20 @@ jobs:
- name: Install NPM Deps
run: pnpm install

- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps

- name: Test
run: pnpm run test:ci

- name: Upload Playwright report
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30

- name: Build
env:
EXTENSION_VERSION: "v1.2.3"
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
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@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm install -g pnpm && pnpm install
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps
- name: Run Playwright tests
run: pnpm exec playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ dist-ssr

gauntface-pin-it-extension.zip
coverage/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["prettier-plugin-svelte"],
"plugins": ["prettier-plugin-svelte", "prettier-plugin-organize-imports"],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}
124 changes: 124 additions & 0 deletions e2e/options.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { test, expect, Page } from "@playwright/test";

test("Options page", async ({ page }) => {
await test.step("Navigate to options page", async () => {
await page.goto("/options-mock.html");
});

await test.step("Check useful UI elements", async () => {
await testUsefulUI(page);
});

await test.step("Test pinned tabs inputs", async () => {
await testPinnedTabsInputs(page);
});

await test.step("Test auto-open tabs toggle", async () => {
await testAutoOpenTabsToggle(page);
});
});

async function testUsefulUI(page: Page) {
await expect(page).toHaveTitle("Pin-It Extension Options");
await expect(page.getByRole("heading", { name: "Options" })).toBeVisible();
await expect(
page.getByRole("link", { name: "Learn more here" }),
).toBeVisible();
await expect(page.getByLabel("Buy me a coffee")).toBeVisible();
}

async function testPinnedTabsInputs(page: Page) {
const loading = await page.getByText("Loading");
await expect(loading).not.toBeVisible();

const firstInputElement = await page.getByPlaceholder("Enter a URL").nth(0);
await expect(firstInputElement).toBeVisible();
const firstDeleteButton = await page
.getByRole("button", { name: "Delete" })
.nth(0);
await expect(firstDeleteButton).toBeVisible();

const addURLButton = await page.getByRole("button", { name: "Add URL" });
await expect(addURLButton).toBeVisible();

// Check initial state
await expect(firstInputElement).toHaveValue("");
await expect(firstDeleteButton).toBeDisabled();

// Test adding some text to first input
await firstInputElement.fill("https://www.gaunt.dev");
await expect(firstInputElement).toHaveValue("https://www.gaunt.dev");
await expect(firstDeleteButton).toBeEnabled();

// Test deleting the text
await firstDeleteButton.click();
await expect(firstInputElement).toHaveValue("");

// Test adding some text and keeping it
await firstInputElement.fill("https://www.gaunt.dev");
await expect(firstInputElement).toHaveValue("https://www.gaunt.dev");
await expect(firstDeleteButton).toBeEnabled();
await expect(loading).toBeVisible();

// Test adding a second input
await addURLButton.click();

const secondInputElement = await page.getByPlaceholder("Enter a URL").nth(1);
await expect(secondInputElement).toBeVisible();

const secondDeleteButton = await page
.getByRole("button", { name: "Delete" })
.nth(1);
await expect(secondDeleteButton).toBeVisible();

// Test filling the second input
await secondInputElement.fill("https://www.gaunt.dev/projects/pin-it/");
await expect(loading).toBeHidden({ timeout: 5000 });

// Test deleting the first input
await firstDeleteButton.click();

// Only one input should be shown
await expect(firstInputElement).toBeVisible();
await expect(firstDeleteButton).toBeVisible();
await expect(secondInputElement).not.toBeVisible();
await expect(secondInputElement).not.toBeVisible();

await expect(firstInputElement).toHaveValue(
"https://www.gaunt.dev/projects/pin-it/",
);
await expect(firstDeleteButton).toBeEnabled();

// Test deleting the first input
await firstDeleteButton.click();
await expect(firstInputElement).toBeVisible();
await expect(firstDeleteButton).toBeVisible();
await expect(firstInputElement).toHaveValue("");
await expect(firstDeleteButton).toBeDisabled();
await expect(loading).toBeHidden({ timeout: 5000 });
}

async function testAutoOpenTabsToggle(page: Page) {
const loading = await page.getByText("Loading");
await expect(loading).not.toBeVisible();

const toggleLabel = await page.getByText(
"Automatically open tabs when a new window is opened",
);
await expect(toggleLabel).toBeVisible();

const checkbox = await page.getByTestId("auto-open-tabs-checkbox");
await expect(checkbox).not.toBeChecked();

await toggleLabel.click();
await expect(checkbox).toBeChecked();

await expect(loading).toBeVisible();
await expect(loading).toBeHidden({ timeout: 5000 });

await toggleLabel.click();
await expect(checkbox).not.toBeChecked();

await expect(loading).toBeVisible();
await expect(loading).toBeHidden({ timeout: 5000 });
}
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
"dev": "vite",
"build": "vite build",
"build:dev": "vite build --mode development",
"test": "npm run lint && npm run vitest",
"test:ci": "npm run lint:ci && npm run vitest:ci",
"test": "npm run lint && npm run vitest:ci && pnpm run test:e2e",
"test:ci": "npm run lint:ci && npm run vitest:ci && pnpm run test:e2e",
"test:e2e": "playwright test",
"test:e2e:debug": "playwright test --debug",
"test:e2e:ui": "playwright test --ui",
"test:server": "pnpm run dev --mode test --host 127.0.0.1 --port 3000",
"lint": "npm run eslint -- --fix && npm run prettier -- --write",
"lint:ci": "npm run eslint && npm run prettier -- --check",
"eslint": "eslint 'src/**/*.{js,ts,svelte}'",
Expand All @@ -22,13 +26,15 @@
"devDependencies": {
"@eslint/js": "^9.8.0",
"@gauntface/logger": "^3.0.115",
"@playwright/test": "^1.48.2",
"@sentry/browser": "^8.7.0",
"@sentry/cli": "^2.32.1",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"@tsconfig/svelte": "^5.0.4",
"@types/archiver": "^6.0.2",
"@types/eslint__js": "^8.42.3",
"@types/lodash-es": "^4.17.12",
"@types/node": "^22.8.6",
"@types/semver": "^7.5.8",
"@types/webextension-polyfill": "^0.12.0",
"@vitest/coverage-v8": "^2.0.5",
Expand All @@ -40,6 +46,7 @@
"globals": "^15.9.0",
"lodash-es": "^4.17.21",
"prettier": "^3.3.0",
"prettier-plugin-organize-imports": "^4.1.0",
"prettier-plugin-svelte": "^3.2.3",
"semver": "^7.6.2",
"svelte": "^5.0.0",
Expand Down
80 changes: 80 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { defineConfig, devices } from "@playwright/test";

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./e2e",
/* 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: "html",
/* 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://127.0.0.1:3000",

/* 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: "pnpm run test:server",
url: "http://127.0.0.1:3000",
reuseExistingServer: !process.env.CI,
timeout: 30 * 1000,
},
});
Loading

0 comments on commit 845581b

Please sign in to comment.