DRY vite configs using a shared config (#33334)

* Fix OIDC login callback handling on Element Desktop

* Add unit tests

* Iterate

* Fix lcov reporter

* DRY vite configs using a shared config

* Iterate

* Revert change to electron-builder.ts

* Iterate
This commit is contained in:
Michael Telatynski
2026-04-30 07:44:29 +00:00
committed by GitHub
parent 98b56a3d2f
commit 30484ef126
12 changed files with 434 additions and 543 deletions
+4 -4
View File
@@ -72,6 +72,7 @@
"@babel/preset-typescript": "^7.18.6",
"@electron/asar": "4.2.0",
"@electron/fuses": "^2.1.1",
"@element-hq/vite-common": "workspace:*",
"@playwright/test": "catalog:",
"@stylistic/eslint-plugin": "^5.0.0",
"@types/auto-launch": "^5.0.1",
@@ -81,7 +82,7 @@
"@types/pacote": "^11.1.1",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"@vitest/coverage-v8": "^4.1.5",
"@vitest/coverage-v8": "catalog:",
"app-builder-lib": "26.9.0",
"chokidar": "^5.0.0",
"detect-libc": "^2.0.0",
@@ -105,9 +106,8 @@
"rimraf": "^6.0.0",
"tar": "^7.5.8",
"typescript": "6.0.3",
"vite": "^8.0.9",
"vitest": "^4.1.5",
"vitest-sonar-reporter": "^3.0.0"
"vitest": "catalog:",
"vitest-sonar-reporter": "catalog:"
},
"hakDependencies": {
"matrix-seshat": "4.2.0"
+14 -55
View File
@@ -5,60 +5,19 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { defineConfig } from "vitest/config";
import { type UserConfig } from "vite";
import { type Reporter } from "vitest/reporters";
import { env } from "node:process";
import { defineConfig, mergeConfig } from "vitest/config";
import baseConfig from "@element-hq/vite-common/vite.config.js";
const reporters: NonNullable<UserConfig["test"]>["reporters"] = [["default"]];
const slowTestReporter: Reporter = {
onTestRunEnd(testModules, unhandledErrors, reason) {
const tests = testModules
.flatMap((m) => Array.from(m.children.allTests()))
.filter((test) => test.diagnostic()?.slow);
tests.sort((x, y) => x.diagnostic()!.duration! - y.diagnostic()!.duration!);
tests.reverse();
if (tests.length > 0) {
console.warn("Slowest 10 tests:");
}
for (const t of tests.slice(0, 10)) {
console.warn(`${t.module.moduleId} > ${t.fullName}: ${t.diagnostic()?.duration.toFixed(0)}ms`);
}
},
};
// if we're running under GHA, enable the GHA & Sonar reporters
if (env["GITHUB_ACTIONS"] !== undefined) {
reporters.push(["github-actions", { silent: false }]);
reporters.push([
"vitest-sonar-reporter",
{
outputFile: "coverage/sonar-report.xml",
onWritePath: (path): string => `apps/desktop/${path}`,
export default mergeConfig(
baseConfig,
defineConfig({
test: {
coverage: {
// The coverage report currently chokes on this file as it doesn't process it as TypeScript
exclude: ["src/preload.cts"],
},
include: ["src/**/*.test.ts"],
},
]);
// if we're running against the develop branch, also enable the slow test reporter
if (env["GITHUB_REF"] == "refs/heads/develop") {
reporters.push(slowTestReporter);
}
}
export default defineConfig({
test: {
coverage: {
provider: "v8",
include: ["src/**/*"],
// The coverage report currently chokes on this file as it doesn't process it as TypeScript
exclude: ["src/preload.cts"],
reporter: [["lcov", { projectRoot: "../../" }]],
},
environment: "node",
reporters,
globals: true,
pool: "threads",
include: ["src/**/*.test.ts"],
},
});
}),
true,
);