Migrate CI and web tests to vite-plus
- switch workspace checks and tests to `vp` - fold Vitest browser config into `vite.config.ts` - add `electron-builder` for desktop packaging
This commit is contained in:
1 parent
5abe2845ca
commit
e3404d1710
9 files changed
+540
-77
No files matched your search
@@ -43,22 +43,19 @@ jobs:
|
||||
- name: Install dependencies
|
||||
run: bun install --frozen-lockfile
|
||||
|
||||
- name: Format
|
||||
run: bun run fmt:check
|
||||
- name: Check workspace (lint & fmt)
|
||||
run: vp check
|
||||
|
||||
- name: Lint
|
||||
run: bun run lint
|
||||
|
||||
- name: Typecheck
|
||||
run: bun run typecheck
|
||||
- name: Check workspace (typecheck)
|
||||
run: vp run -r typecheck
|
||||
|
||||
- name: Test
|
||||
run: bun run test
|
||||
run: vp test
|
||||
|
||||
- name: Install browser test runtime
|
||||
run: |
|
||||
cd apps/web
|
||||
bunx playwright install --with-deps chromium
|
||||
vpx playwright install --with-deps chromium
|
||||
|
||||
- name: Browser test
|
||||
run: bun run --cwd apps/web test:browser
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
"@types/node": "catalog:",
|
||||
"electron-builder": "26.8.1",
|
||||
"typescript": "catalog:",
|
||||
"vite-plus": "catalog:"
|
||||
},
|
||||
|
||||
@@ -10,10 +10,7 @@ import {
|
||||
DEVELOPMENT_ICON_OVERRIDES,
|
||||
PUBLISH_ICON_OVERRIDES,
|
||||
} from "../../../scripts/lib/brand-assets.ts";
|
||||
import {
|
||||
getWorkspaceCatalog,
|
||||
resolveCatalogDependencies,
|
||||
} from "../../../scripts/lib/resolve-catalog.ts";
|
||||
import { resolveCatalogDependencies } from "../../../scripts/lib/resolve-catalog.ts";
|
||||
import rootPackageJson from "../../../package.json" with { type: "json" };
|
||||
import serverPackageJson from "../package.json" with { type: "json" };
|
||||
|
||||
@@ -25,7 +22,6 @@ class CliError extends Data.TaggedError("CliError")<{
|
||||
const RepoRoot = Effect.service(Path.Path).pipe(
|
||||
Effect.flatMap((path) => path.fromFileUrl(new URL("../../..", import.meta.url))),
|
||||
);
|
||||
const workspaceCatalog = getWorkspaceCatalog(rootPackageJson);
|
||||
|
||||
const runCommand = Effect.fn("runCommand")(function* (command: ChildProcess.Command) {
|
||||
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
@@ -209,7 +205,7 @@ const publishCmd = Command.make(
|
||||
|
||||
pkg.dependencies = resolveCatalogDependencies(
|
||||
pkg.dependencies,
|
||||
workspaceCatalog,
|
||||
rootPackageJson.catalog,
|
||||
"apps/server dependencies",
|
||||
);
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
"preview": "vp preview",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vp test run --passWithNoTests",
|
||||
"test:browser": "vp test run --config vitest.browser.config.ts",
|
||||
"test:browser": "vp test run --project browser",
|
||||
"test:unit": "vp test run --project unit",
|
||||
"test:browser:install": "playwright install --with-deps chromium"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as path from "node:path";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
import react, { reactCompilerPreset } from "@vitejs/plugin-react";
|
||||
import babel from "@rolldown/plugin-babel";
|
||||
import { playwright } from "vite-plus/test/browser-playwright";
|
||||
import { tanstackRouter } from "@tanstack/router-plugin/vite";
|
||||
import { defineConfig } from "vite-plus";
|
||||
import pkg from "./package.json" with { type: "json" };
|
||||
@@ -64,4 +65,29 @@ export default defineConfig({
|
||||
emptyOutDir: true,
|
||||
sourcemap: buildSourcemap,
|
||||
},
|
||||
test: {
|
||||
projects: [
|
||||
{
|
||||
extends: true,
|
||||
test: {
|
||||
include: ["**/*.test.ts", "**/*.test.tsx"],
|
||||
name: "unit",
|
||||
environment: "node",
|
||||
},
|
||||
},
|
||||
{
|
||||
extends: true,
|
||||
test: {
|
||||
include: ["**/*.browser.tsx"],
|
||||
name: "browser",
|
||||
browser: {
|
||||
enabled: true,
|
||||
provider: playwright(),
|
||||
instances: [{ browser: "chromium" }],
|
||||
headless: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
@@ -1,29 +0,0 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { playwright } from "vite-plus/test/browser-playwright";
|
||||
import { defineConfig, mergeConfig } from "vite-plus";
|
||||
|
||||
import viteConfig from "./vite.config";
|
||||
|
||||
const srcPath = fileURLToPath(new URL("./src", import.meta.url));
|
||||
|
||||
export default mergeConfig(
|
||||
viteConfig,
|
||||
defineConfig({
|
||||
resolve: {
|
||||
alias: {
|
||||
"~": srcPath,
|
||||
},
|
||||
},
|
||||
test: {
|
||||
include: ["src/components/**/*.browser.tsx"],
|
||||
browser: {
|
||||
enabled: true,
|
||||
provider: playwright(),
|
||||
instances: [{ browser: "chromium" }],
|
||||
headless: true,
|
||||
},
|
||||
testTimeout: 30_000,
|
||||
hookTimeout: 30_000,
|
||||
},
|
||||
}),
|
||||
);
|
||||
@@ -9,7 +9,7 @@ import desktopPackageJson from "../apps/desktop/package.json" with { type: "json
|
||||
import serverPackageJson from "../apps/server/package.json" with { type: "json" };
|
||||
|
||||
import { BRAND_ASSET_PATHS } from "./lib/brand-assets.ts";
|
||||
import { getWorkspaceCatalog, resolveCatalogDependencies } from "./lib/resolve-catalog.ts";
|
||||
import { resolveCatalogDependencies } from "./lib/resolve-catalog.ts";
|
||||
|
||||
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
@@ -39,7 +39,6 @@ const ProductionWindowsIconSource = Effect.zipWith(
|
||||
(repoRoot, path) => path.join(repoRoot, BRAND_ASSET_PATHS.productionWindowsIconIco),
|
||||
);
|
||||
const encodeJsonString = Schema.encodeEffect(Schema.UnknownFromJsonString);
|
||||
const workspaceCatalog = getWorkspaceCatalog(rootPackageJson);
|
||||
|
||||
interface PlatformConfig {
|
||||
readonly cliFlag: "--mac" | "--linux" | "--win";
|
||||
@@ -182,6 +181,7 @@ interface StagePackageJson {
|
||||
readonly dependencies: Record<string, unknown>;
|
||||
readonly devDependencies: {
|
||||
readonly electron: string;
|
||||
readonly "electron-builder": string;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -557,6 +557,7 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
|
||||
}
|
||||
|
||||
const electronVersion = desktopPackageJson.dependencies.electron;
|
||||
const electronBuilderVersion = desktopPackageJson.devDependencies["electron-builder"];
|
||||
|
||||
const serverDependencies = serverPackageJson.dependencies;
|
||||
if (!serverDependencies || Object.keys(serverDependencies).length === 0) {
|
||||
@@ -566,7 +567,8 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
|
||||
}
|
||||
|
||||
const resolvedServerDependencies = yield* Effect.try({
|
||||
try: () => resolveCatalogDependencies(serverDependencies, workspaceCatalog, "apps/server"),
|
||||
try: () =>
|
||||
resolveCatalogDependencies(serverDependencies, rootPackageJson.catalog, "apps/server"),
|
||||
catch: (cause) =>
|
||||
new BuildScriptError({
|
||||
message: "Could not resolve production dependencies from apps/server/package.json.",
|
||||
@@ -574,7 +576,8 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
|
||||
}),
|
||||
});
|
||||
const resolvedDesktopRuntimeDependencies = yield* Effect.try({
|
||||
try: () => resolveDesktopRuntimeDependencies(desktopPackageJson.dependencies, workspaceCatalog),
|
||||
try: () =>
|
||||
resolveDesktopRuntimeDependencies(desktopPackageJson.dependencies, rootPackageJson.catalog),
|
||||
catch: (cause) =>
|
||||
new BuildScriptError({
|
||||
message: "Could not resolve desktop runtime dependencies from apps/desktop/package.json.",
|
||||
@@ -662,20 +665,21 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
|
||||
},
|
||||
devDependencies: {
|
||||
electron: electronVersion,
|
||||
"electron-builder": electronBuilderVersion,
|
||||
},
|
||||
};
|
||||
|
||||
const stagePackageJsonString = yield* encodeJsonString(stagePackageJson);
|
||||
yield* fs.writeFileString(path.join(stageAppDir, "package.json"), `${stagePackageJsonString}\n`);
|
||||
|
||||
yield* Effect.log("[desktop-artifact] Installing staged production dependencies...");
|
||||
yield* Effect.log("[desktop-artifact] Installing staged build dependencies...");
|
||||
yield* runCommand(
|
||||
ChildProcess.make({
|
||||
cwd: stageAppDir,
|
||||
...commandOutputOptions(options.verbose),
|
||||
// Windows needs shell mode to resolve .cmd shims (e.g. bun.cmd).
|
||||
shell: process.platform === "win32",
|
||||
})`bun install --production`,
|
||||
})`vp install`,
|
||||
);
|
||||
|
||||
const buildEnv: NodeJS.ProcessEnv = {
|
||||
|
||||
@@ -1,25 +1,3 @@
|
||||
/**
|
||||
* Resolve `catalog:` dependency specs using the workspace catalog.
|
||||
*
|
||||
* Pure function: returns a new record with every `catalog:…` value replaced by
|
||||
* the concrete version string found in `catalog`. Throws on missing entries.
|
||||
*/
|
||||
export function getWorkspaceCatalog(rootPackageJson: {
|
||||
readonly catalog?: Record<string, unknown>;
|
||||
readonly workspaces?:
|
||||
| {
|
||||
readonly catalog?: Record<string, unknown>;
|
||||
}
|
||||
| ReadonlyArray<string>;
|
||||
}): Record<string, unknown> {
|
||||
const workspaceCatalog =
|
||||
rootPackageJson.workspaces && !Array.isArray(rootPackageJson.workspaces)
|
||||
? (rootPackageJson.workspaces as { readonly catalog?: Record<string, unknown> }).catalog
|
||||
: undefined;
|
||||
|
||||
return rootPackageJson.catalog ?? workspaceCatalog ?? {};
|
||||
}
|
||||
|
||||
export function resolveCatalogDependencies(
|
||||
dependencies: Record<string, unknown>,
|
||||
catalog: Record<string, unknown>,
|
||||
|
||||
Reference in new issue
Block a user