Skip to content

Commit

Permalink
test(e2e): added playwright visual tests (#17)
Browse files Browse the repository at this point in the history
* setup: upgraded vite and vite-pwa to the latest version (#14)

* setup: upgraded react to the latest version (#15)

* setup: upgraded konva deps

* setup: upgraded tabler icons

* test: added playwright visual tests

* ci: changed playwright action to trigger for develop as well

* one linux image

* e2e to artifacts

* e2e to artifacts

* test: added linux images

* fixed screenshot
  • Loading branch information
The24thDS authored Jul 25, 2024
1 parent 926f090 commit 59121d6
Show file tree
Hide file tree
Showing 53 changed files with 1,094 additions and 614 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Playwright Tests
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
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 yarn && yarn
- name: Install Playwright Browsers
run: yarn playwright install --with-deps
- name: Run Playwright tests
run: yarn playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: |
playwright-report/
test-results/
e2e/
retention-days: 30
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ dev-dist

# Local Netlify folder
.netlify
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
9 changes: 9 additions & 0 deletions e2e/home.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test, expect } from "@playwright/test";

test("visual test", async ({ page }) => {
await page.goto("/");
// Wait for all network requests for images to complete
await page.waitForLoadState("networkidle");

await expect(page).toHaveScreenshot();
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions e2e/light-locators-generator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test, expect } from "@playwright/test";

test("visual test", async ({ page }) => {
await page.goto("/light-locators-generator");
// Wait for all network requests for images to complete
await page.waitForLoadState("networkidle");

await expect(page).toHaveScreenshot();
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions e2e/other-tools.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test, expect } from "@playwright/test";

test("visual test", async ({ page }) => {
await page.goto("/other-tools");
// Wait for all network requests for images to complete
await page.waitForLoadState("networkidle");

await expect(page).toHaveScreenshot();
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions e2e/privacy.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test, expect } from "@playwright/test";

test("visual test", async ({ page }) => {
await page.goto("/privacy");
// Wait for all network requests for images to complete
await page.waitForLoadState("networkidle");

await expect(page).toHaveScreenshot();
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions e2e/traits-builder.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test, expect } from "@playwright/test";

test("visual test", async ({ page }) => {
await page.goto("/traits-builder");
// Wait for all network requests for images to complete
await page.waitForLoadState("networkidle");

await expect(page).toHaveScreenshot();
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions e2e/unused-dds-finder.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test, expect } from "@playwright/test";

test("visual test", async ({ page }) => {
await page.goto("/unused-dds-finder");
// Wait for all network requests for images to complete
await page.waitForLoadState("networkidle");

await expect(page).toHaveScreenshot();
});
31 changes: 17 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
"name": "rmg-utils",
"private": true,
"version": "1.6.0",
"type": "module",
"scripts": {
"dev": "vite",
"prebuild": "cp magick.js public/assets/magick.js && cp magick.wasm public/assets/magick.wasm",
"build": "tsc && vite build",
"postbuild": "rm public/assets/magick.js public/assets/magick.wasm",
"preview": "vite preview",
"release": "npx standard-version",
"functions": "npx env-cmd -f ./.env.local netlify functions:serve"
"functions": "npx env-cmd -f ./.env.local netlify functions:serve",
"e2e": "playwright test"
},
"dependencies": {
"@emotion/react": "^11.9.3",
Expand All @@ -19,28 +21,29 @@
"@mantine/notifications": "^6.0.0",
"@netlify/functions": "^1.0.0",
"@sentry/browser": "^7.12.1",
"@tabler/icons": "^1.78.1",
"@tabler/icons-react": "^3.5.0",
"airtable": "^0.11.4",
"filesize": "^10.0.12",
"konva": "^8.3.14",
"random": "^3.0.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-konva": "^18.2.3",
"react-router-dom": "^6.3.0",
"tiny-invariant": "^1.2.0",
"use-image": "^1.1.0"
},
"devDependencies": {
"@types/node": "^18.6.3",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"@types/wicg-file-system-access": "^2020.9.6",
"@vitejs/plugin-react": "^3.1.0",
"typescript": "^4.7.4",
"vite": "^4.0.0",
"vite-plugin-pwa": "^0.14.4",
"workbox-build": "^6.5.4",
"workbox-window": "^6.5.4"
"@playwright/test": "^1.44.1",
"@types/node": "^20.12.8",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"@types/wicg-file-system-access": "^2023.10.5",
"@vitejs/plugin-react": "^4.2.1",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vite-plugin-pwa": "^0.20.0",
"workbox-build": "^7.1.0",
"workbox-window": "^7.1.0"
}
}
78 changes: 78 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { defineConfig, devices } from "@playwright/test";

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// 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 : 1,
/* 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", { open: "none", outputDir: "playwright-report" }]],
/* 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:5173/",

/* 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: "yarn dev",
url: "http://localhost:5173/",
reuseExistingServer: !process.env.CI,
},
});
2 changes: 1 addition & 1 deletion src/components/Header/ColorSchemeToggle.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMantineColorScheme, ActionIcon, Group } from "@mantine/core";
import { IconSun, IconMoonStars } from "@tabler/icons";
import { IconSun, IconMoonStars } from "@tabler/icons-react";

export default function ColorSchemeTogle() {
const { colorScheme, toggleColorScheme } = useMantineColorScheme();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function Header() {
<Stack sx={{ maxWidth: 1500 }} mx="auto">
<Group position="apart" px="sm">
<Group>
<Image src={rmgLogo} height={50} width={50} />
<Image src={rmgLogo} height={50} width={50} alt="RMG logo" />
<Text size="xl" weight={700}>
RMG Utils for Stellaris
</Text>
Expand Down
2 changes: 1 addition & 1 deletion src/components/UnusedDDSFinder/FileTree.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Accordion, Flex, List, Text } from "@mantine/core";
import { IconFolder, IconPhoto } from "@tabler/icons";
import { IconFolder, IconPhoto } from "@tabler/icons-react";
import { partial } from "filesize";

import { UDDSDirectoryDDSFileType } from "../../utils/UDDSDirectory";
Expand Down
2 changes: 1 addition & 1 deletion src/components/UnusedDDSFinder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Flex,
} from "@mantine/core";
import { showNotification } from "@mantine/notifications";
import { IconAlertTriangle } from "@tabler/icons";
import { IconAlertTriangle } from "@tabler/icons-react";

import { RequiresInstallation } from "../shared/RequiresInstallation";

Expand Down
2 changes: 1 addition & 1 deletion src/components/shared/DownloadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { notifications } from "@mantine/notifications";
import { Stage } from "konva/lib/Stage";
import { useState } from "react";
import * as Sentry from "@sentry/browser";
import { IconX } from "@tabler/icons";
import { IconX } from "@tabler/icons-react";

declare global {
interface Window {
Expand Down
2 changes: 1 addition & 1 deletion src/components/shared/InstallApplicationButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useContext } from "react";
import { Alert, Button } from "@mantine/core";
import { IconAlertCircle } from "@tabler/icons";
import { IconAlertCircle } from "@tabler/icons-react";

import { BeforeInstallPromptContext } from "../../hooks/useIsInstalled";
import { isAnalyticsEnabled } from "../../utils/general";
Expand Down
Loading

0 comments on commit 59121d6

Please sign in to comment.