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:
@@ -48,7 +48,7 @@
|
||||
"build:doc": "nx typedoc",
|
||||
"lint": "pnpm lint:types && pnpm lint:js",
|
||||
"lint:js": "eslint --max-warnings 0 src",
|
||||
"lint:types": "tsc --noEmit && tsc --noEmit -p tsconfig.node.json"
|
||||
"lint:types": "nx lint:types"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-hq/element-web-module-api": "workspace:*",
|
||||
@@ -71,6 +71,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@element-hq/element-web-playwright-common": "workspace:*",
|
||||
"@element-hq/vite-common": "workspace:*",
|
||||
"@fetch-mock/vitest": "^0.2.18",
|
||||
"@fontsource/inter": "catalog:",
|
||||
"@matrix-org/react-sdk-module-api": "^2.5.0",
|
||||
@@ -94,7 +95,7 @@
|
||||
"@typescript-eslint/parser": "^8.53.1",
|
||||
"@vector-im/compound-web": "catalog:",
|
||||
"@vitest/browser-playwright": "^4.0.17",
|
||||
"@vitest/coverage-v8": "^4.0.17",
|
||||
"@vitest/coverage-v8": "catalog:",
|
||||
"eslint": "8",
|
||||
"eslint-config-google": "^0.14.0",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
@@ -115,10 +116,10 @@
|
||||
"typedoc-plugin-missing-exports": "^4.1.2",
|
||||
"typescript": "catalog:",
|
||||
"unplugin-dts": "1.0.0-beta.6",
|
||||
"vite": "^8.0.0",
|
||||
"vite": "catalog:",
|
||||
"vite-plugin-node-polyfills": "^0.26.0",
|
||||
"vitest": "^4.0.18",
|
||||
"vitest-sonar-reporter": "^3.0.0"
|
||||
"vitest": "catalog:",
|
||||
"vitest-sonar-reporter": "catalog:"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
|
||||
@@ -54,6 +54,14 @@
|
||||
"cwd": "packages/shared-components"
|
||||
},
|
||||
"dependsOn": ["typedoc", "^build:playwright"]
|
||||
},
|
||||
"lint:types": {
|
||||
"executor": "nx:run-commands",
|
||||
"options": {
|
||||
"commands": ["tsc --noEmit", "tsc --noEmit -p tsconfig.node.json"],
|
||||
"cwd": "packages/shared-components"
|
||||
},
|
||||
"dependsOn": ["^build"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,58 +5,18 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { defineConfig, ViteUserConfig } from "vitest/config";
|
||||
import { defineConfig, mergeConfig } from "vitest/config";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { storybookTest } from "@storybook/addon-vitest/vitest-plugin";
|
||||
import { storybookVis } from "storybook-addon-vis/vitest-plugin";
|
||||
import { playwright, PlaywrightProviderOptions } from "@vitest/browser-playwright";
|
||||
import { nodePolyfills } from "vite-plugin-node-polyfills";
|
||||
import { Reporter } from "vitest/reporters";
|
||||
import { env } from "process";
|
||||
|
||||
import baseConfig from "@element-hq/vite-common/vite.config";
|
||||
|
||||
const dirname = typeof __dirname !== "undefined" ? __dirname : path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const reporters: NonNullable<ViteUserConfig["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) => `packages/shared-components/${path}`,
|
||||
},
|
||||
]);
|
||||
|
||||
// if we're running against the develop branch, also enable the slow test reporter
|
||||
if (env["GITHUB_REF"] == "refs/heads/develop") {
|
||||
reporters.push(slowTestReporter);
|
||||
}
|
||||
}
|
||||
|
||||
const commonContextOptions: PlaywrightProviderOptions["contextOptions"] = {
|
||||
reducedMotion: "reduce",
|
||||
// Force consistent font rendering
|
||||
@@ -70,95 +30,93 @@ const commonLaunchOptions = {
|
||||
args: ["--font-render-hinting=none", "--disable-font-subpixel-positioning", "--disable-lcd-text"],
|
||||
};
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
coverage: {
|
||||
provider: "v8",
|
||||
include: ["src/**/*.{ts,tsx}"],
|
||||
exclude: ["src/**/*.stories.tsx"],
|
||||
reporter: [["lcov", { projectRoot: "../../" }]],
|
||||
},
|
||||
reporters,
|
||||
globals: false,
|
||||
pool: "threads",
|
||||
projects: [
|
||||
{
|
||||
extends: true,
|
||||
plugins: [
|
||||
// The plugin will run tests for the stories defined in your Storybook config
|
||||
// See options at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon#storybooktest
|
||||
storybookTest({
|
||||
configDir: path.join(dirname, ".storybook"),
|
||||
storybookScript: "storybook --ci",
|
||||
tags: {
|
||||
exclude: ["skip-test"],
|
||||
export default mergeConfig(
|
||||
baseConfig,
|
||||
defineConfig({
|
||||
test: {
|
||||
coverage: {
|
||||
exclude: ["src/**/*.stories.tsx"],
|
||||
},
|
||||
projects: [
|
||||
{
|
||||
extends: true,
|
||||
plugins: [
|
||||
// The plugin will run tests for the stories defined in your Storybook config
|
||||
// See options at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon#storybooktest
|
||||
storybookTest({
|
||||
configDir: path.join(dirname, ".storybook"),
|
||||
storybookScript: "storybook --ci",
|
||||
tags: {
|
||||
exclude: ["skip-test"],
|
||||
},
|
||||
}),
|
||||
storybookVis({
|
||||
// 3px of difference allowed before marking as failed
|
||||
failureThreshold: 3,
|
||||
// When running in CI=1 mode, set the platform to `linux` as that is the platform where the browser-in-docker is running
|
||||
snapshotRootDir: ({ ci, platform }) => `__vis__/${ci ? "linux" : platform}`,
|
||||
}),
|
||||
],
|
||||
test: {
|
||||
name: "storybook",
|
||||
browser: {
|
||||
enabled: true,
|
||||
headless: true,
|
||||
provider: playwright({
|
||||
contextOptions: commonContextOptions,
|
||||
launchOptions: commonLaunchOptions,
|
||||
connectOptions: process.env.PW_TEST_CONNECT_WS_ENDPOINT
|
||||
? {
|
||||
wsEndpoint: process.env.PW_TEST_CONNECT_WS_ENDPOINT,
|
||||
exposeNetwork: "<loopback>",
|
||||
}
|
||||
: undefined,
|
||||
}),
|
||||
instances: [{ browser: "chromium" }],
|
||||
},
|
||||
}),
|
||||
storybookVis({
|
||||
// 3px of difference allowed before marking as failed
|
||||
failureThreshold: 3,
|
||||
// When running in CI=1 mode, set the platform to `linux` as that is the platform where the browser-in-docker is running
|
||||
snapshotRootDir: ({ ci, platform }) => `__vis__/${ci ? "linux" : platform}`,
|
||||
}),
|
||||
],
|
||||
test: {
|
||||
name: "storybook",
|
||||
browser: {
|
||||
enabled: true,
|
||||
headless: true,
|
||||
provider: playwright({
|
||||
contextOptions: commonContextOptions,
|
||||
launchOptions: commonLaunchOptions,
|
||||
connectOptions: process.env.PW_TEST_CONNECT_WS_ENDPOINT
|
||||
? {
|
||||
wsEndpoint: process.env.PW_TEST_CONNECT_WS_ENDPOINT,
|
||||
exposeNetwork: "<loopback>",
|
||||
}
|
||||
: undefined,
|
||||
}),
|
||||
instances: [{ browser: "chromium" }],
|
||||
},
|
||||
setupFiles: [".storybook/vitest.setup.ts"],
|
||||
},
|
||||
},
|
||||
{
|
||||
extends: true,
|
||||
// as any is workaround for https://github.com/davidmyersdev/vite-plugin-node-polyfills/issues/150
|
||||
plugins: [nodePolyfills({ include: ["util"], globals: { global: false } }) as any],
|
||||
test: {
|
||||
name: "unit",
|
||||
browser: {
|
||||
enabled: true,
|
||||
headless: true,
|
||||
provider: playwright({
|
||||
// These tests don't actually take screenshots (at least at time of writing)
|
||||
// but let's pass these options everywhere for consistency
|
||||
contextOptions: commonContextOptions,
|
||||
launchOptions: commonLaunchOptions,
|
||||
}),
|
||||
instances: [{ browser: "chromium" }],
|
||||
},
|
||||
setupFiles: ["src/test/setupTests.ts"],
|
||||
},
|
||||
css: {
|
||||
modules: {
|
||||
// Stabilise snapshots while keeping names distinct across CSS modules.
|
||||
generateScopedName: "[name]_[local]",
|
||||
setupFiles: [".storybook/vitest.setup.ts"],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
optimizeDeps: {
|
||||
include: [
|
||||
"vite-plugin-node-polyfills/shims/buffer",
|
||||
"vite-plugin-node-polyfills/shims/process",
|
||||
"@vector-im/compound-design-tokens/assets/web/icons",
|
||||
],
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
"@test-utils": path.resolve(__dirname, "./src/test/utils/index.tsx"),
|
||||
{
|
||||
extends: true,
|
||||
// as any is workaround for https://github.com/davidmyersdev/vite-plugin-node-polyfills/issues/150
|
||||
plugins: [nodePolyfills({ include: ["util"], globals: { global: false } }) as any],
|
||||
test: {
|
||||
name: "unit",
|
||||
browser: {
|
||||
enabled: true,
|
||||
headless: true,
|
||||
provider: playwright({
|
||||
// These tests don't actually take screenshots (at least at time of writing)
|
||||
// but let's pass these options everywhere for consistency
|
||||
contextOptions: commonContextOptions,
|
||||
launchOptions: commonLaunchOptions,
|
||||
}),
|
||||
instances: [{ browser: "chromium" }],
|
||||
},
|
||||
setupFiles: ["src/test/setupTests.ts"],
|
||||
},
|
||||
css: {
|
||||
modules: {
|
||||
// Stabilise snapshots while keeping names distinct across CSS modules.
|
||||
generateScopedName: "[name]_[local]",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
optimizeDeps: {
|
||||
include: [
|
||||
"vite-plugin-node-polyfills/shims/buffer",
|
||||
"vite-plugin-node-polyfills/shims/process",
|
||||
"@vector-im/compound-design-tokens/assets/web/icons",
|
||||
],
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
"@test-utils": path.resolve(__dirname, "./src/test/utils/index.tsx"),
|
||||
},
|
||||
},
|
||||
}),
|
||||
true,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user