mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-11 05:11:49 +01:00
Ignore UI test files in Vite dev watch
(cherry picked from commit c3d4e78e6f2038fd17cdd3f1cebb64a66489272b)
This commit is contained in:
1 parent
9c231d925a
commit
42189e1bf9
3 files changed
+60
-2
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createUiDevWatchOptions, shouldIgnoreUiDevWatchPath } from "./vite-watch";
|
||||
|
||||
describe("shouldIgnoreUiDevWatchPath", () => {
|
||||
it("ignores test-only files and folders", () => {
|
||||
expect(shouldIgnoreUiDevWatchPath("/repo/ui/src/components/IssuesList.test.tsx")).toBe(true);
|
||||
expect(shouldIgnoreUiDevWatchPath("/repo/ui/src/lib/issue-tree.spec.ts")).toBe(true);
|
||||
expect(shouldIgnoreUiDevWatchPath("/repo/ui/src/__tests__/helpers.ts")).toBe(true);
|
||||
expect(shouldIgnoreUiDevWatchPath("/repo/ui/tests/helpers.ts")).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps runtime source files watchable", () => {
|
||||
expect(shouldIgnoreUiDevWatchPath("/repo/ui/src/components/IssuesList.tsx")).toBe(false);
|
||||
expect(shouldIgnoreUiDevWatchPath("/repo/ui/src/pages/IssueDetail.tsx")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("createUiDevWatchOptions", () => {
|
||||
it("preserves the WSL /mnt polling fallback", () => {
|
||||
expect(createUiDevWatchOptions("/mnt/c/paperclip")).toMatchObject({
|
||||
usePolling: true,
|
||||
interval: 1000,
|
||||
});
|
||||
});
|
||||
|
||||
it("always includes the ignored-path predicate", () => {
|
||||
expect(createUiDevWatchOptions("/Users/dotta/paperclip")).toHaveProperty("ignored");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
const TEST_DIRECTORY_NAMES = new Set([
|
||||
"__tests__",
|
||||
"_tests",
|
||||
"test",
|
||||
"tests",
|
||||
]);
|
||||
|
||||
const TEST_FILE_BASENAME_RE = /\.(test|spec)\.[^/]+$/i;
|
||||
|
||||
export function shouldIgnoreUiDevWatchPath(watchedPath: string): boolean {
|
||||
const normalizedPath = String(watchedPath).replaceAll("\\", "/");
|
||||
if (normalizedPath.length === 0) return false;
|
||||
|
||||
const segments = normalizedPath.split("/");
|
||||
const basename = segments.at(-1) ?? normalizedPath;
|
||||
|
||||
return segments.some((segment) => TEST_DIRECTORY_NAMES.has(segment))
|
||||
|| TEST_FILE_BASENAME_RE.test(basename);
|
||||
}
|
||||
|
||||
export function createUiDevWatchOptions(currentWorkingDirectory: string) {
|
||||
return {
|
||||
ignored: shouldIgnoreUiDevWatchPath,
|
||||
// WSL2 /mnt/ drives don't support inotify — fall back to polling so HMR works.
|
||||
...(currentWorkingDirectory.startsWith("/mnt/")
|
||||
? { usePolling: true, interval: 1000 }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
+2
-2
@@ -2,6 +2,7 @@ import path from "path";
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
import { createUiDevWatchOptions } from "./src/lib/vite-watch";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react(), tailwindcss()],
|
||||
@@ -13,8 +14,7 @@ export default defineConfig({
|
||||
},
|
||||
server: {
|
||||
port: 5173,
|
||||
// WSL2 /mnt/ drives don't support inotify — fall back to polling so HMR works
|
||||
watch: process.cwd().startsWith("/mnt/") ? { usePolling: true, interval: 1000 } : undefined,
|
||||
watch: createUiDevWatchOptions(process.cwd()),
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: "http://localhost:3100",
|
||||
|
||||
Reference in new issue
Block a user