Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix(tests): normalize Windows paths in web contracts (#1696)

Bingxi Zhao (Frank)aa498ff7043b
diff --git a/web/tests/architecture-contracts.test.ts b/web/tests/architecture-contracts.test.ts
index c82653826..05603a8fb 100644
--- a/web/tests/architecture-contracts.test.ts
+++ b/web/tests/architecture-contracts.test.ts
@@ -5,6 +5,7 @@ import { execFileSync } from "node:child_process";
import test from "node:test";
const root = process.cwd();
+const portablePath = (value: string) => value.replaceAll("\\", "/");
const sourceRoots = [
"app",
"components",
@@ -33,14 +34,14 @@ const allSources = sourceRoots.flatMap(sourceFiles);
test("browser storage methods stay behind the shared boundary", () => {
const violations = allSources
- .filter((file) => !file.endsWith("components/ThemeScript.tsx"))
- .filter((file) => !file.includes("shared/storage/"))
+ .filter((file) => !portablePath(file).endsWith("components/ThemeScript.tsx"))
+ .filter((file) => !portablePath(file).includes("shared/storage/"))
.filter((file) =>
/(?:window\.)?(?:localStorage|sessionStorage)\.(?:getItem|setItem|removeItem)/.test(
fs.readFileSync(file, "utf8"),
),
)
- .map((file) => path.relative(root, file));
+ .map((file) => portablePath(path.relative(root, file)));
assert.deepEqual(violations, []);
});
@@ -51,7 +52,7 @@ test("raw fetch is limited to the shared API client and media preview", () => {
]);
const violations = allSources
.filter((file) => /\bfetch\(/.test(fs.readFileSync(file, "utf8")))
- .map((file) => path.relative(root, file))
+ .map((file) => portablePath(path.relative(root, file)))
.filter((file) => !allow.has(file));
assert.deepEqual(violations, []);
});
@@ -61,14 +62,14 @@ test("source modules cannot import Next route pages", () => {
.filter((file) =>
/from\s+["'][^"']*\/page["']/.test(fs.readFileSync(file, "utf8")),
)
- .map((file) => path.relative(root, file));
+ .map((file) => portablePath(path.relative(root, file)));
assert.deepEqual(violations, []);
});
test("the canonical tooltip owns every tooltip role and guards import paths", () => {
const roleOwners = allSources
.filter((file) => /role=["']tooltip["']/.test(fs.readFileSync(file, "utf8")))
- .map((file) => path.relative(root, file));
+ .map((file) => portablePath(path.relative(root, file)));
assert.deepEqual(roleOwners.sort(), [
"shared/ui/Tooltip.tsx",
"shared/ui/TooltipLayer.tsx",
@@ -82,7 +83,7 @@ test("the canonical tooltip owns every tooltip role and guards import paths", ()
fs.readFileSync(file, "utf8"),
),
)
- .map((file) => path.relative(root, file));
+ .map((file) => portablePath(path.relative(root, file)));
assert.deepEqual(legacyImports, []);
const eslintConfig = fs.readFileSync(path.join(root, "eslint.config.mjs"), "utf8");
diff --git a/web/tests/internal-route-contract.test.ts b/web/tests/internal-route-contract.test.ts
index 611a4f2dd..499ec54dc 100644
--- a/web/tests/internal-route-contract.test.ts
+++ b/web/tests/internal-route-contract.test.ts
@@ -35,7 +35,7 @@ function pagePattern(pageFile: string): RegExp {
}
const pagePatterns = walk(APP_ROOT)
- .filter((file) => /\/page\.(?:ts|tsx|js|jsx)$/.test(file))
+ .filter((file) => /^page\.(?:ts|tsx|js|jsx)$/.test(path.basename(file)))
.map(pagePattern);
function isPagePath(value: string): boolean {