Files
Reactive-Resume/packages/utils/src/monorepo.node.test.ts
T
Amruth Pillai 6a01207b6b test: add unit and component tests across the monorepo
Adds ~1000 tests to bring the previously-untested packages and apps
under coverage:

- packages/utils — string, color, date, file, level, locale, sanitize,
  field, html, network-icons, rate-limit, url, url-security, monorepo,
  resume/patch, resume/docx/link-utils, style helpers (~97% on the
  testable utility files)
- packages/ui — 28 component test files plus the use-controlled-state,
  use-mobile, use-confirm, use-prompt hooks (95% statements)
- packages/pdf — shared template helpers (filtering, columns, picture,
  metrics, section-links, page-size, rich-text-html, section-title)
- packages/schema — resumeDataSchema, page, templates, default
- packages/fonts — expanded coverage on font helpers
- packages/ai — resume sanitize and extraction template
- packages/api — resume-access-policy
- apps/web — error-message, locale, theme, pwa, dialogs/store, and
  the resume/move-item / section-actions / make-section-item helpers

Adds jsdom polyfills (ResizeObserver, IntersectionObserver,
scrollIntoView, matchMedia) and an explicit React Testing Library
cleanup hook to vitest.setup.ts so portal- and overlay-based components
work without per-test setup.
2026-05-10 20:00:07 +02:00

87 lines
3.0 KiB
TypeScript

import { existsSync, mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { findWorkspaceRoot, getLocalDataDirectory } from "./monorepo.node";
describe("findWorkspaceRoot", () => {
let tempDir: string;
beforeEach(() => {
// Resolve symlinks so comparisons match findWorkspaceRoot's realpathSync output.
tempDir = realpathSync(mkdtempSync(join(tmpdir(), "rr-monorepo-test-")));
});
afterEach(() => {
rmSync(tempDir, { recursive: true, force: true });
});
it("returns the directory containing pnpm-workspace.yaml", () => {
writeFileSync(join(tempDir, "pnpm-workspace.yaml"), "packages: ['*']");
expect(findWorkspaceRoot(tempDir)).toBe(tempDir);
});
it("walks up directories to find pnpm-workspace.yaml", () => {
const nested = join(tempDir, "apps", "web");
mkdirSync(nested, { recursive: true });
writeFileSync(join(tempDir, "pnpm-workspace.yaml"), "packages: ['*']");
expect(findWorkspaceRoot(nested)).toBe(tempDir);
});
it("returns null if no workspace manifest is found", () => {
// Use a temp dir that has no pnpm-workspace.yaml above it. Any descendant of /tmp
// either has the file or eventually hits /. We use a deep-enough sibling here:
const isolated = join(tempDir, "isolated");
mkdirSync(isolated, { recursive: true });
// Walk up from isolated; nothing in tempDir has a workspace manifest.
// findWorkspaceRoot will return null when it reaches the filesystem root.
// Verify behavior: at minimum, it should not return our tempDir.
const result = findWorkspaceRoot(isolated);
expect(result).not.toBe(tempDir);
});
});
describe("getLocalDataDirectory", () => {
let tempDir: string;
beforeEach(() => {
tempDir = realpathSync(mkdtempSync(join(tmpdir(), "rr-data-test-")));
});
afterEach(() => {
rmSync(tempDir, { recursive: true, force: true });
});
it("returns override when provided", () => {
expect(getLocalDataDirectory("/custom/path")).toBe("/custom/path");
});
it("returns workspaceRoot/data when manifest is found", () => {
writeFileSync(join(tempDir, "pnpm-workspace.yaml"), "packages: ['*']");
expect(getLocalDataDirectory(undefined, tempDir)).toBe(join(tempDir, "data"));
});
it("falls back to cwd/data when no manifest found", () => {
const isolated = join(tempDir, "isolated");
mkdirSync(isolated, { recursive: true });
const result = getLocalDataDirectory(undefined, isolated);
// Should end with /data and not be the manifest workspace path
expect(result.endsWith("data")).toBe(true);
});
it("override takes precedence even if workspace exists", () => {
writeFileSync(join(tempDir, "pnpm-workspace.yaml"), "packages: ['*']");
expect(getLocalDataDirectory("/elsewhere", tempDir)).toBe("/elsewhere");
});
it("manifest file actually exists for the test setup", () => {
writeFileSync(join(tempDir, "pnpm-workspace.yaml"), "packages: ['*']");
expect(existsSync(join(tempDir, "pnpm-workspace.yaml"))).toBe(true);
});
});