From 04239749201ebdff46d85c50b57effe56ebecd7b Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 21:20:12 +0100 Subject: [PATCH 01/13] chore: update Jest configuration Modified Jest configuration to use automatic runtime transformation for React and JSdom as test environment. Additionally, adjusted moduleNameMapper to correctly map the project structure. --- jest.config.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/jest.config.ts b/jest.config.ts index f9107b7e7..0f0f04cfa 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -7,10 +7,22 @@ const jestConfig = { testMatch: ["**/?(*.)test.ts?(x)"], testPathIgnorePatterns: [".e2e."], transform: { - "^.+\\.(t|j)sx?$": "@swc/jest", + "^.+\\.(t|j)sx?$": [ + "@swc/jest", + { + jsc: { + transform: { + react: { + runtime: "automatic", + }, + }, + }, + }, + ], }, moduleNameMapper: { - "@/(.*)": "/src/electron/future/$1", + "@/(.*)": "/src/client/$1", + "$/(.*)": "/src/electron/future/$1", "#/(.*)": "/src/shared/$1", }, collectCoverage: true, @@ -22,6 +34,7 @@ const jestConfig = { lines: 80, }, }, + testEnvironment: "jsdom", transformIgnorePatterns: ["/node_modules/"], extensionsToTreatAsEsm: [".ts", ".tsx"], setupFilesAfterEnv: ["/jest.setup.ts"], From 810f9fc801b8f440cef27a634aeff86f6ec7db07 Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 21:20:39 +0100 Subject: [PATCH 02/13] refactor: refactor keyboard navigation hook Simplified the implementation of Keyboard navigation hooks by reducing redundancy in callback functions. Also, renamed from .tsx to .ts since it contains no JSX syntax. Additionally, modified import statement to import useAtom directly from 'jotai' instead of 'jotai/index'. --- ... keyboard-controlled-images-navigation.ts} | 44 ++++++++----------- 1 file changed, 18 insertions(+), 26 deletions(-) rename src/client/ions/hooks/{keyboard-controlled-images-navigation.tsx => keyboard-controlled-images-navigation.ts} (60%) diff --git a/src/client/ions/hooks/keyboard-controlled-images-navigation.tsx b/src/client/ions/hooks/keyboard-controlled-images-navigation.ts similarity index 60% rename from src/client/ions/hooks/keyboard-controlled-images-navigation.tsx rename to src/client/ions/hooks/keyboard-controlled-images-navigation.ts index d6b9bde62..abfe97232 100644 --- a/src/client/ions/hooks/keyboard-controlled-images-navigation.tsx +++ b/src/client/ions/hooks/keyboard-controlled-images-navigation.ts @@ -1,4 +1,4 @@ -import { useAtom } from "jotai/index"; +import { useAtom } from "jotai"; import { useCallback, useEffect } from "react"; import { imagesAtom, selectedImageAtom } from "@/ions/atoms"; @@ -10,40 +10,32 @@ export function useKeyboardControlledImagesNavigation({ onBeforeChange(): Promise | void; }) { const [images] = useAtom(imagesAtom); - const [selectedImage, setSelectedImage] = useAtom(selectedImageAtom); + const [, setSelectedImage] = useAtom(selectedImageAtom); const columnCount = useColumns({ xs: 2, sm: 3, md: 4, lg: 6 }); const { length: imagesLength } = images; const goRowUp = useCallback(() => { - if (selectedImage > columnCount - 1) { - setSelectedImage(selectedImage - columnCount); - } else { - setSelectedImage(imagesLength - 1); - } - }, [selectedImage, columnCount, setSelectedImage, imagesLength]); + setSelectedImage(previousState => + previousState > columnCount - 1 ? previousState - columnCount : imagesLength - 1 + ); + }, [columnCount, setSelectedImage, imagesLength]); const goRowDown = useCallback(() => { - if (selectedImage < imagesLength - columnCount) { - setSelectedImage(selectedImage + columnCount); - } else { - setSelectedImage(0); - } - }, [selectedImage, imagesLength, columnCount, setSelectedImage]); + setSelectedImage(previousState => + previousState < imagesLength - columnCount ? previousState + columnCount : 0 + ); + }, [imagesLength, columnCount, setSelectedImage]); const goToPrevious = useCallback(() => { - if (selectedImage > 0) { - setSelectedImage(selectedImage - 1); - } else { - setSelectedImage(imagesLength - 1); - } - }, [selectedImage, setSelectedImage, imagesLength]); + setSelectedImage(previousState => + previousState > 0 ? previousState - 1 : imagesLength - 1 + ); + }, [setSelectedImage, imagesLength]); const goToNext = useCallback(() => { - if (selectedImage < imagesLength - 1) { - setSelectedImage(selectedImage + 1); - } else { - setSelectedImage(0); - } - }, [selectedImage, imagesLength, setSelectedImage]); + setSelectedImage(previousState => + previousState < imagesLength - 1 ? previousState + 1 : 0 + ); + }, [imagesLength, setSelectedImage]); useEffect(() => { async function handleKeyDown(event: KeyboardEvent) { From 8156dd46f4401220a0396c752674532f49683a5e Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 21:21:12 +0100 Subject: [PATCH 03/13] test: add test files for various hooks Introduced test files for the 'useSsrColorScheme', 'useColumns', 'useKeyboardControlledImagesNavigation', and 'useScrollPosition' hooks. These tests cover functionalities such as initial mode setting, mode changing, keyboard navigation, and scroll position detection. --- .../ions/hooks/__test__/color-scheme.test.tsx | 38 ++++++++ .../ions/hooks/__test__/columns.test.tsx | 30 ++++++ ...oard-controlled-images-navigation.test.tsx | 94 +++++++++++++++++++ .../hooks/__test__/scroll-position.test.tsx | 77 +++++++++++++++ 4 files changed, 239 insertions(+) create mode 100644 src/client/ions/hooks/__test__/color-scheme.test.tsx create mode 100644 src/client/ions/hooks/__test__/columns.test.tsx create mode 100644 src/client/ions/hooks/__test__/keyboard-controlled-images-navigation.test.tsx create mode 100644 src/client/ions/hooks/__test__/scroll-position.test.tsx diff --git a/src/client/ions/hooks/__test__/color-scheme.test.tsx b/src/client/ions/hooks/__test__/color-scheme.test.tsx new file mode 100644 index 000000000..bc7a6b903 --- /dev/null +++ b/src/client/ions/hooks/__test__/color-scheme.test.tsx @@ -0,0 +1,38 @@ +import type { Mode } from "@mui/system/cssVars/useCurrentColorScheme"; +import { renderHook, act } from "@testing-library/react"; + +import { useSsrColorScheme } from "../color-scheme"; + +function createMockUseColorScheme(initialMode = "system") { + let internalMode = initialMode; + + return jest.fn().mockImplementation(() => ({ + mode: internalMode, + setMode(newMode: Mode) { + internalMode = newMode; + }, + })); +} + +jest.mock("@mui/joy/styles", () => ({ + useColorScheme: createMockUseColorScheme(), +})); + +describe("useSsrColorScheme", () => { + it("should set initial mode to 'system'", () => { + const { result } = renderHook(() => useSsrColorScheme()); + expect(result.current.mode).toBe("system"); + }); + + it("should change mode when setMode is called", () => { + const { result, rerender } = renderHook(() => useSsrColorScheme()); // Get the rerender function + + act(() => { + result.current.setMode("light"); + }); + + rerender(); + + expect(result.current.mode).toBe("light"); + }); +}); diff --git a/src/client/ions/hooks/__test__/columns.test.tsx b/src/client/ions/hooks/__test__/columns.test.tsx new file mode 100644 index 000000000..2ae78ed8b --- /dev/null +++ b/src/client/ions/hooks/__test__/columns.test.tsx @@ -0,0 +1,30 @@ +// UseColumns.test.tsx +import { extendTheme, ThemeProvider } from "@mui/joy/styles"; +import { render } from "@testing-library/react"; +import React from "react"; +import "@testing-library/jest-dom"; + +import { useColumns } from "../columns"; // Adjust the import path as necessary + +// Mock component to utilize the useColumns hook +function MockComponent({ xs, sm, md, lg }: { xs: number; sm: number; md: number; lg: number }) { + const columns = useColumns({ xs, sm, md, lg }); + return
{columns}
; +} + +describe("useColumns", () => { + const theme = extendTheme(); // Use your custom theme if you have one + + function renderWithTheme(properties: { xs: number; sm: number; md: number; lg: number }) { + return render( + + + + ); + } + + it("should return xs value for initial render", () => { + const { getByTestId } = renderWithTheme({ xs: 2, sm: 4, md: 6, lg: 8 }); + expect(getByTestId("column-count")).toHaveTextContent("2"); + }); +}); diff --git a/src/client/ions/hooks/__test__/keyboard-controlled-images-navigation.test.tsx b/src/client/ions/hooks/__test__/keyboard-controlled-images-navigation.test.tsx new file mode 100644 index 000000000..9127de13b --- /dev/null +++ b/src/client/ions/hooks/__test__/keyboard-controlled-images-navigation.test.tsx @@ -0,0 +1,94 @@ +import { fireEvent, waitFor } from "@testing-library/react"; +import { renderHook, act } from "@testing-library/react"; +import { Provider } from "jotai"; + +import { useKeyboardControlledImagesNavigation } from "../keyboard-controlled-images-navigation"; + +describe("useKeyboardControlledImagesNavigation", () => { + it("should handle keyboard navigation correctly", async () => { + const onBeforeChangeMock = jest.fn(); + // Render the hook that we are testing + renderHook( + () => useKeyboardControlledImagesNavigation({ onBeforeChange: onBeforeChangeMock }), + { + wrapper: Provider, + } + ); + + // Set initial state for images and selectedImage + act(() => { + fireEvent.keyDown(window, { key: "ArrowRight", altKey: true }); + }); + + // Assertions + await waitFor(() => { + expect(onBeforeChangeMock).toHaveBeenCalledTimes(1); + }); + act(() => { + fireEvent.keyDown(window, { key: "ArrowLeft", altKey: true }); + }); + + // Assertions + await waitFor(() => { + expect(onBeforeChangeMock).toHaveBeenCalledTimes(2); + }); + act(() => { + fireEvent.keyDown(window, { key: "ArrowUp", altKey: true }); + }); + + // Assertions + await waitFor(() => { + expect(onBeforeChangeMock).toHaveBeenCalledTimes(3); + }); + act(() => { + fireEvent.keyDown(window, { key: "ArrowDown", altKey: true }); + }); + + // Assertions + await waitFor(() => { + expect(onBeforeChangeMock).toHaveBeenCalledTimes(4); + }); + }); + it("should not respond with alt key", async () => { + const onBeforeChangeMock = jest.fn(); + + // Render the hook that we are testing + renderHook( + () => useKeyboardControlledImagesNavigation({ onBeforeChange: onBeforeChangeMock }), + { + wrapper: Provider, + } + ); + + // Set initial state for images and selectedImage + act(() => { + fireEvent.keyDown(window, { key: "ArrowRight" }); + }); + + // Assertions + await waitFor(() => { + expect(onBeforeChangeMock).not.toHaveBeenCalled(); + }); + }); + it("should not respond to other keys", async () => { + const onBeforeChangeMock = jest.fn(); + + // Render the hook that we are testing + renderHook( + () => useKeyboardControlledImagesNavigation({ onBeforeChange: onBeforeChangeMock }), + { + wrapper: Provider, + } + ); + + // Set initial state for images and selectedImage + act(() => { + fireEvent.keyDown(window, { key: "Enter", altKey: true }); + }); + + // Assertions + await waitFor(() => { + expect(onBeforeChangeMock).not.toHaveBeenCalled(); + }); + }); +}); diff --git a/src/client/ions/hooks/__test__/scroll-position.test.tsx b/src/client/ions/hooks/__test__/scroll-position.test.tsx new file mode 100644 index 000000000..e3914b1bc --- /dev/null +++ b/src/client/ions/hooks/__test__/scroll-position.test.tsx @@ -0,0 +1,77 @@ +import { act, fireEvent, render } from "@testing-library/react"; +import React, { useRef } from "react"; + +import { useScrollPosition } from "../scroll-position"; // Adjust your import path +import "@testing-library/jest-dom"; + +class ResizeObserver { + observe() {} + unobserve() {} + disconnect() {} +} + +global.ResizeObserver = ResizeObserver; +// Test component that uses your hook +function TestComponent() { + const reference = useRef(null); + const scroll = useScrollPosition(reference); + + return ( +
+
+
Scroll me
+
+

{scroll.scrollable ? "true" : "false"}

+

{scroll.start ? "true" : "false"}

+

{scroll.end ? "true" : "false"}

+
+ ); +} + +describe("useScrollPosition", () => { + beforeEach(() => { + // Mock properties before each test + Object.defineProperty(HTMLElement.prototype, "scrollWidth", { + configurable: true, + value: 300, + }); + Object.defineProperty(HTMLElement.prototype, "clientWidth", { + configurable: true, + value: 100, + }); + }); + + it("should correctly detect scroll positions", async () => { + const { getByTestId } = render(); + + expect(getByTestId("scrollable")).toHaveTextContent("true"); + expect(getByTestId("start")).toHaveTextContent("true"); + expect(getByTestId("end")).toHaveTextContent("false"); + }); + + it("should update scroll position on scroll event", async () => { + const { getByTestId } = render(); + const scrollableDiv = getByTestId("scrollable-div"); // Add this data-testid to your scrollable div + + // Check initial state + expect(getByTestId("scrollable")).toHaveTextContent("true"); + expect(getByTestId("start")).toHaveTextContent("true"); + expect(getByTestId("end")).toHaveTextContent("false"); + + // Simulate scrolling + act(() => { + // Manually set the scroll position + scrollableDiv.scrollLeft = 150; // Halfway scrolled + // Dispatch the scroll event on the scrollable div + fireEvent.scroll(scrollableDiv); + }); + + // Check the updated state after scrolling + expect(getByTestId("start")).toHaveTextContent("false"); + expect(getByTestId("end")).toHaveTextContent("false"); // Still not at the end + }); +}); From 1383d6ef885165286e94d610b11f05d6e869f7d2 Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 21:40:48 +0100 Subject: [PATCH 04/13] chore: split Jest configuration for Client and Electron The Jest configuration and setup files have been split into separate ones for client and Electron app testing. This will allow distinct test configuration and match patterns for the two different environments. Furthermore, corresponding changes are made in the package.json file to add different test scripts for running these new configuration files. --- jest.config.ts => jest.config.client.ts | 4 +--- jest.config.electron.ts | 31 +++++++++++++++++++++++++ jest.setup.ts => jest.setup.electron.ts | 16 ++++++------- package.json | 3 ++- 4 files changed, 41 insertions(+), 13 deletions(-) rename jest.config.ts => jest.config.client.ts (85%) create mode 100644 jest.config.electron.ts rename jest.setup.ts => jest.setup.electron.ts (88%) diff --git a/jest.config.ts b/jest.config.client.ts similarity index 85% rename from jest.config.ts rename to jest.config.client.ts index 0f0f04cfa..3487af15e 100644 --- a/jest.config.ts +++ b/jest.config.client.ts @@ -4,8 +4,8 @@ import { defaults } from "jest-config"; const jestConfig = { ...defaults, + roots: ["/src/client"], testMatch: ["**/?(*.)test.ts?(x)"], - testPathIgnorePatterns: [".e2e."], transform: { "^.+\\.(t|j)sx?$": [ "@swc/jest", @@ -22,7 +22,6 @@ const jestConfig = { }, moduleNameMapper: { "@/(.*)": "/src/client/$1", - "$/(.*)": "/src/electron/future/$1", "#/(.*)": "/src/shared/$1", }, collectCoverage: true, @@ -37,7 +36,6 @@ const jestConfig = { testEnvironment: "jsdom", transformIgnorePatterns: ["/node_modules/"], extensionsToTreatAsEsm: [".ts", ".tsx"], - setupFilesAfterEnv: ["/jest.setup.ts"], }; export default jestConfig; diff --git a/jest.config.electron.ts b/jest.config.electron.ts new file mode 100644 index 000000000..ae6b30719 --- /dev/null +++ b/jest.config.electron.ts @@ -0,0 +1,31 @@ +import { defaults } from "jest-config"; + +// Adjust the import path to your tsconfig.json file + +const jestConfig = { + ...defaults, + roots: ["/src/electron"], + testMatch: ["**/?(*.)test.ts"], + testPathIgnorePatterns: [".e2e."], + transform: { + "^.+\\.ts$": ["@swc/jest"], + }, + moduleNameMapper: { + "@/(.*)": "/src/electron/future/$1", + "#/(.*)": "/src/shared/$1", + }, + collectCoverage: true, + coverageDirectory: "./coverage", + coverageProvider: "v8", + coverageReporters: ["lcov", "text", "json"], + coverageThreshold: { + global: { + lines: 80, + }, + }, + transformIgnorePatterns: ["/node_modules/"], + extensionsToTreatAsEsm: [".ts"], + setupFilesAfterEnv: ["/jest.setup.electron.ts"], +}; + +export default jestConfig; diff --git a/jest.setup.ts b/jest.setup.electron.ts similarity index 88% rename from jest.setup.ts rename to jest.setup.electron.ts index d787f1429..a338e4589 100644 --- a/jest.setup.ts +++ b/jest.setup.electron.ts @@ -1,11 +1,4 @@ jest.mock("electron", () => { - const mockBrowserWindow = jest.fn().mockImplementation(() => ({ - loadURL: jest.fn(), - on: jest.fn(), - once: jest.fn(), - close: jest.fn(), - })); - const mockWebContents = { send: jest.fn(), }; @@ -17,8 +10,13 @@ jest.mock("electron", () => { close: jest.fn(), webContents: mockWebContents, }; - - mockBrowserWindow.getFocusedWindow = jest.fn(() => mockFocusedWindow); + const mockBrowserWindow = jest.fn().mockImplementation(() => ({ + loadURL: jest.fn(), + on: jest.fn(), + once: jest.fn(), + close: jest.fn(), + getFocusedWindow: jest.fn(() => mockFocusedWindow), + })); return { BrowserWindow: mockBrowserWindow, diff --git a/package.json b/package.json index 0b74e92de..a35f8f2db 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "toc": "npx markdown-toc README.md -i", "tsc:noEmit": "tsc --noEmit", "caption:test": "ts-node-esm main/captions/misc.ts", - "test:unit": "jest --runInBand --config jest.config.ts --verbose", + "test:electron": "jest --runInBand --config jest.config.electron.ts --verbose", + "test:client": "jest --runInBand --config jest.config.client.ts --verbose", "pretest:e2e": "nextron build --no-pack", "test:e2e": "npx playwright test" }, From 4cb10df5a8043e8beee4b411ef09062a3d437316 Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 21:41:20 +0100 Subject: [PATCH 05/13] test: correct test directory naming in client hooks Renamed all test directories in src/client/ions/hooks path from "__test__" to "__tests__" to follow naming conventions. This change ensures a consistent file structure, which might have been causing issues in identifying and running test files. --- .../ions/hooks/{__test__ => __tests__}/color-scheme.test.tsx | 0 src/client/ions/hooks/{__test__ => __tests__}/columns.test.tsx | 0 .../keyboard-controlled-images-navigation.test.tsx | 0 .../ions/hooks/{__test__ => __tests__}/scroll-position.test.tsx | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename src/client/ions/hooks/{__test__ => __tests__}/color-scheme.test.tsx (100%) rename src/client/ions/hooks/{__test__ => __tests__}/columns.test.tsx (100%) rename src/client/ions/hooks/{__test__ => __tests__}/keyboard-controlled-images-navigation.test.tsx (100%) rename src/client/ions/hooks/{__test__ => __tests__}/scroll-position.test.tsx (100%) diff --git a/src/client/ions/hooks/__test__/color-scheme.test.tsx b/src/client/ions/hooks/__tests__/color-scheme.test.tsx similarity index 100% rename from src/client/ions/hooks/__test__/color-scheme.test.tsx rename to src/client/ions/hooks/__tests__/color-scheme.test.tsx diff --git a/src/client/ions/hooks/__test__/columns.test.tsx b/src/client/ions/hooks/__tests__/columns.test.tsx similarity index 100% rename from src/client/ions/hooks/__test__/columns.test.tsx rename to src/client/ions/hooks/__tests__/columns.test.tsx diff --git a/src/client/ions/hooks/__test__/keyboard-controlled-images-navigation.test.tsx b/src/client/ions/hooks/__tests__/keyboard-controlled-images-navigation.test.tsx similarity index 100% rename from src/client/ions/hooks/__test__/keyboard-controlled-images-navigation.test.tsx rename to src/client/ions/hooks/__tests__/keyboard-controlled-images-navigation.test.tsx diff --git a/src/client/ions/hooks/__test__/scroll-position.test.tsx b/src/client/ions/hooks/__tests__/scroll-position.test.tsx similarity index 100% rename from src/client/ions/hooks/__test__/scroll-position.test.tsx rename to src/client/ions/hooks/__tests__/scroll-position.test.tsx From c845a6ce8e6e70a00d723aafd90ad35d6a98e645 Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 21:58:13 +0100 Subject: [PATCH 06/13] chore: remove report --- playwright-report/index.html | 69 ------------------------------------ 1 file changed, 69 deletions(-) delete mode 100644 playwright-report/index.html diff --git a/playwright-report/index.html b/playwright-report/index.html deleted file mode 100644 index 76188316c..000000000 --- a/playwright-report/index.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - Playwright Test Report - - - - -
- - - - \ No newline at end of file From ad7f26f33e4f4e037e34dffc9e7733e7ee50290f Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 21:59:45 +0100 Subject: [PATCH 07/13] chore: ignore report --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4c550eb18..7ea0fa76a 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ live-canvas-generate-image-output.png.tmp.png # test coverage +playwright-report From 007b4bd8aba811968141f5f1641aebac13074dad Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 22:07:17 +0100 Subject: [PATCH 08/13] chore: adjust test config --- jest.config.electron.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/jest.config.electron.ts b/jest.config.electron.ts index ae6b30719..ecbe0b06b 100644 --- a/jest.config.electron.ts +++ b/jest.config.electron.ts @@ -6,7 +6,6 @@ const jestConfig = { ...defaults, roots: ["/src/electron"], testMatch: ["**/?(*.)test.ts"], - testPathIgnorePatterns: [".e2e."], transform: { "^.+\\.ts$": ["@swc/jest"], }, From d40b68ca574782dd64705e452c08034afb3ea606 Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 22:14:28 +0100 Subject: [PATCH 09/13] Add GitHub Actions workflows for testing Three new workflows have been added for GitHub Actions to run client, e2e, and electron tests. They are configured to trigger on push events to alpha, beta, rc, and main branches or on pull requests to those same branches. All workflows run on the latest version of Ubuntu and use Node.js version 18.x. --- .github/workflows/test-client.yml | 25 +++++++++++++++++++++++++ .github/workflows/test-e2e.yml | 25 +++++++++++++++++++++++++ .github/workflows/test-electron.yml | 25 +++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 .github/workflows/test-client.yml create mode 100644 .github/workflows/test-e2e.yml create mode 100644 .github/workflows/test-electron.yml diff --git a/.github/workflows/test-client.yml b/.github/workflows/test-client.yml new file mode 100644 index 000000000..09a864160 --- /dev/null +++ b/.github/workflows/test-client.yml @@ -0,0 +1,25 @@ +name: Client Tests + +on: + push: + branches: [ alpha, beta, rc, main ] + pull_request: + branches: [ alpha, beta, rc, main ] + +jobs: + test-client: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18.x] + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: npm install + - name: Run Client tests + run: npm run test:client diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml new file mode 100644 index 000000000..ce94ba28b --- /dev/null +++ b/.github/workflows/test-e2e.yml @@ -0,0 +1,25 @@ +name: e2e Tests + +on: + push: + branches: [ alpha, beta, rc, main ] + pull_request: + branches: [ alpha, beta, rc, main ] + +jobs: + test-e2e: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18.x] + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: npm install + - name: Run e2e tests + run: npm run test:e2e diff --git a/.github/workflows/test-electron.yml b/.github/workflows/test-electron.yml new file mode 100644 index 000000000..6d1f50bc6 --- /dev/null +++ b/.github/workflows/test-electron.yml @@ -0,0 +1,25 @@ +name: Electron Tests + +on: + push: + branches: [ alpha, beta, rc, main ] + pull_request: + branches: [ alpha, beta, rc, main ] + +jobs: + test-electron: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18.x] + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: npm install + - name: Run Electron tests + run: npm run test:electron From 612a1e2b9fcfbd35739859265fa589047e6d5ecd Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 22:17:58 +0100 Subject: [PATCH 10/13] chore: add workflows --- .github/workflows/set-pr-title.yml | 30 ----------------------------- .github/workflows/test-client.yml | 1 + .github/workflows/test-e2e.yml | 1 + .github/workflows/test-electron.yml | 1 + 4 files changed, 3 insertions(+), 30 deletions(-) delete mode 100644 .github/workflows/set-pr-title.yml diff --git a/.github/workflows/set-pr-title.yml b/.github/workflows/set-pr-title.yml deleted file mode 100644 index 6e9b5b05a..000000000 --- a/.github/workflows/set-pr-title.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Set PR Title to First Commit Message - -on: - pull_request: - types: [opened, synchronize] - -jobs: - set-pr-title: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - with: - # Fetches the entire commit history so that we can access the first commit - fetch-depth: 0 - - - name: Get first commit message - run: | - # Get the SHA of the first commit in the PR - FIRST_COMMIT_SHA=$(git log --reverse --format="%H" "${{ github.event.pull_request.base.sha }}..HEAD" | head -n 1) - # Get the message of the first commit in the PR - FIRST_COMMIT_MESSAGE=$(git log -n 1 --format=%B "$FIRST_COMMIT_SHA") - echo "FIRST_COMMIT_MESSAGE=$FIRST_COMMIT_MESSAGE" >> $GITHUB_ENV - - - name: Update PR title - run: gh pr edit "$PR_NUMBER" --title "$FIRST_COMMIT_MESSAGE" - env: - FIRST_COMMIT_MESSAGE: ${{ env.FIRST_COMMIT_MESSAGE }} - GITHUB_TOKEN: ${{ secrets.PIXELASS_PAT_BLIBLA }} - PR_NUMBER: ${{ github.event.pull_request.number }} diff --git a/.github/workflows/test-client.yml b/.github/workflows/test-client.yml index 09a864160..afb36357e 100644 --- a/.github/workflows/test-client.yml +++ b/.github/workflows/test-client.yml @@ -4,6 +4,7 @@ on: push: branches: [ alpha, beta, rc, main ] pull_request: + types: [ opened, synchronize ] branches: [ alpha, beta, rc, main ] jobs: diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index ce94ba28b..2581fd81e 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -4,6 +4,7 @@ on: push: branches: [ alpha, beta, rc, main ] pull_request: + types: [opened, synchronize] branches: [ alpha, beta, rc, main ] jobs: diff --git a/.github/workflows/test-electron.yml b/.github/workflows/test-electron.yml index 6d1f50bc6..d0a813889 100644 --- a/.github/workflows/test-electron.yml +++ b/.github/workflows/test-electron.yml @@ -4,6 +4,7 @@ on: push: branches: [ alpha, beta, rc, main ] pull_request: + types: [opened, synchronize] branches: [ alpha, beta, rc, main ] jobs: From f75f7684b1bc08f172479287dae5f63830c9da85 Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 22:29:51 +0100 Subject: [PATCH 11/13] test: adjust playwright see https://github.com/microsoft/playwright/issues/11932#issuecomment-1200164702 --- playwright/index.test.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/playwright/index.test.ts b/playwright/index.test.ts index b8e9357e6..50958b07d 100644 --- a/playwright/index.test.ts +++ b/playwright/index.test.ts @@ -1,3 +1,5 @@ +import process from "process"; + import type { ElectronApplication, Page } from "@playwright/test"; import { test, expect } from "@playwright/test"; import { _electron as electron } from "playwright"; @@ -7,7 +9,13 @@ let page: Page; test.beforeAll(async () => { // Use package.main - electronApp = await electron.launch({ args: ["."] }); + electronApp = await electron.launch({ + args: ["."], + env: { + ...process.env, + NODE_ENV: "development", + }, + }); const isPackaged = await electronApp.evaluate(async ({ app }) => app.isPackaged); expect(isPackaged).toBe(false); From 37aba4be7b3cd6833a28a3a1b084c39bc1360f2c Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 22:36:07 +0100 Subject: [PATCH 12/13] revert: revert change --- playwright/index.test.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/playwright/index.test.ts b/playwright/index.test.ts index 50958b07d..55adf008a 100644 --- a/playwright/index.test.ts +++ b/playwright/index.test.ts @@ -1,5 +1,3 @@ -import process from "process"; - import type { ElectronApplication, Page } from "@playwright/test"; import { test, expect } from "@playwright/test"; import { _electron as electron } from "playwright"; @@ -11,10 +9,6 @@ test.beforeAll(async () => { // Use package.main electronApp = await electron.launch({ args: ["."], - env: { - ...process.env, - NODE_ENV: "development", - }, }); const isPackaged = await electronApp.evaluate(async ({ app }) => app.isPackaged); From d099b1c8409cc8d524c1f0a52fa98d30021adf00 Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 22:40:34 +0100 Subject: [PATCH 13/13] chore: adjust test script --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a35f8f2db..1f38e1554 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "test:electron": "jest --runInBand --config jest.config.electron.ts --verbose", "test:client": "jest --runInBand --config jest.config.client.ts --verbose", "pretest:e2e": "nextron build --no-pack", - "test:e2e": "npx playwright test" + "test:e2e:local": "npx playwright test", + "test:e2e": "xvfb-run --auto-servernum --server-args=\"-screen 0 1280x960x24\" -- npx playwright test" }, "dependencies": { "electron-context-menu": "3.6.1",