Skip to content
Draft
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
100 changes: 100 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Test

on:
pull_request:
branches:
- main
- dev
workflow_dispatch:

permissions:
contents: read

jobs:
# -------------------------------------------------------------------------
# Unit tests — Jest, no display required
# -------------------------------------------------------------------------
unit-tests:
name: Unit Tests (Jest)
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install pnpm
run: npm install -g pnpm@10.18.3

- name: Install dependencies
run: pnpm install

- name: Run unit tests
run: pnpm run test:unit

- name: Upload coverage
if: always()
uses: actions/upload-artifact@v4
with:
name: unit-coverage
path: coverage/
retention-days: 7

# -------------------------------------------------------------------------
# E2E tests — Playwright + Electron, requires a virtual display (xvfb)
# -------------------------------------------------------------------------
e2e-tests:
name: E2E Tests (Playwright)
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install pnpm
run: npm install -g pnpm@10.18.3

- name: Install dependencies
run: pnpm install

- name: Install Electron binary
run: node ./node_modules/electron/install.js

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

- name: Install Linux display dependencies
run: sudo apt-get install -y xvfb libgtk-3-0 libnotify-dev libnss3 libxss1 libasound2t64

- name: Build application
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
APPINSIGHTS_CONNECTION_STRING: ${{ secrets.APPINSIGHTS_CONNECTION_STRING }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
run: pnpm run build

- name: Run e2e tests
run: xvfb-run --auto-servernum pnpm run test:e2e
env:
CI: true

- name: Upload Playwright report
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: test-results/
retention-days: 7
45 changes: 45 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { Config } from "jest";

const config: Config = {
// Test environment
testEnvironment: "node",

// TypeScript transformation via ts-jest
transform: {
"^.+\\.tsx?$": [
"ts-jest",
{
tsconfig: "tsconfig.test.json",
diagnostics: {
// Only report errors, not warnings, to keep output clean
warnOnly: false,
ignoreCodes: ["TS151001"],
},
},
],
},

// Test file discovery
testMatch: ["<rootDir>/tests/unit/**/*.test.ts"],

// Module name mapper — redirect Electron and electron-store to manual mocks
moduleNameMapper: {
"^electron$": "<rootDir>/tests/__mocks__/electron.ts",
"^electron-store$": "<rootDir>/tests/__mocks__/electron-store.ts",
},

// Coverage configuration
collectCoverageFrom: ["src/main/managers/**/*.ts", "src/common/**/*.ts", "src/renderer/utils/**/*.ts"],

coverageDirectory: "coverage",

coverageReporters: ["text", "lcov"],

// Ignore paths
testPathIgnorePatterns: ["/node_modules/", "/dist/", "/build/"],

// Verbose output for CI readability
verbose: true,
};

export default config;
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
"dev": "vite",
"watch": "vite build --watch",
"lint": "eslint src --ext .ts",
"test": "pnpm run test:unit && pnpm run test:e2e",
"test:unit": "jest --config jest.config.ts",
"test:unit:watch": "jest --config jest.config.ts --watch",
"test:unit:coverage": "jest --config jest.config.ts --coverage",
"test:e2e": "playwright test",
"test:e2e:ui": "playwright test --ui",
"start": "electron .",
"package": "node ./buildScripts/package.js",
"package:win": "node ./buildScripts/package.js --config=buildScripts/electron-builder-win.json",
Expand Down Expand Up @@ -39,6 +45,8 @@
"license": "GPL-3.0",
"devDependencies": {
"@electron/notarize": "^3.1.0",
"@playwright/test": "1.60.0",
"@types/jest": "29.5.14",
"@types/node": "^20.19.21",
"@typescript-eslint/eslint-plugin": "^6.13.0",
"@typescript-eslint/parser": "^6.13.0",
Expand All @@ -47,8 +55,11 @@
"electron": "^28.0.0",
"electron-builder": "^24.9.0",
"eslint": "^8.54.0",
"jest": "29.7.0",
"rollup-plugin-visualizer": "^6.0.5",
"sass": "^1.93.2",
"ts-jest": "29.4.10",
"ts-node": "10.9.2",
"typescript": "^5.3.0",
"vite": "^7.1.10",
"vite-plugin-electron": "^0.29.0",
Expand Down
47 changes: 47 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { defineConfig } from "@playwright/test";
import path from "path";

export default defineConfig({
// E2e test location
testDir: "./tests/e2e",

// Global timeout per test
timeout: 60_000,

// Run tests in parallel (one worker per test file keeps Electron instances isolated)
workers: 1,

// Retry on CI
retries: process.env.CI ? 1 : 0,

// Reporters
reporter: process.env.CI ? [["github"], ["list"]] : [["list"]],

use: {
// Screenshot on failure
screenshot: "only-on-failure",

// Path to the built Electron app (must be built before running e2e)
// Playwright's electron launch picks up dist/main/index.js
},

// Output folder for test artifacts
outputDir: "test-results",

// Project configuration — single "electron" project
projects: [
{
name: "electron",
use: {
// Electron main entry point (requires `pnpm run build` first)
// Passed via test fixture; see tests/e2e/fixtures.ts
},
},
],

// Shared metadata
metadata: {
app: "PowerPlatform ToolBox",
mainEntry: path.resolve(__dirname, "dist/main/index.js"),
},
});
Loading
Loading