one
Version:
One is a new React Framework that makes Vite serve both native and web.
53 lines (52 loc) • 1.9 kB
JavaScript
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "fs";
import { tmpdir } from "os";
import { dirname, join } from "path";
import { afterEach, describe, expect, it } from "vitest";
import { createRouteIndex } from "./routeIndex.native.js";
var testDir;
function writeRoute(relativePath) {
testDir || (testDir = mkdtempSync(join(tmpdir(), "one-route-index-")));
var filePath = join(testDir, "app", relativePath);
mkdirSync(dirname(filePath), {
recursive: true
});
writeFileSync(filePath, "export default function Route() { return null }");
return filePath;
}
afterEach(function () {
if (testDir) {
rmSync(testDir, {
recursive: true,
force: true
});
testDir = void 0;
}
});
describe(createRouteIndex, function () {
it("scans and filters the route tree once", function () {
writeRoute("index.tsx");
writeRoute("nested/page.ts");
writeRoute("nested/page.test.tsx");
writeRoute("routes.d.ts");
var routeIndex = createRouteIndex({
routerRoot: join(testDir, "app"),
ignoredRouteFiles: ["**/*.test.*"]
});
expect(routeIndex.getPaths()).toEqual(["./index.tsx", "./nested/page.ts"]);
});
it("updates route membership from watcher events", function () {
writeRoute("index.tsx");
var routeIndex = createRouteIndex({
routerRoot: join(testDir, "app"),
ignoredRouteFiles: ["**/*.test.*"]
});
var addedRoute = writeRoute("nested/new.tsx");
var ignoredRoute = writeRoute("nested/new.test.tsx");
expect(routeIndex.update("add", addedRoute)).toBe(true);
expect(routeIndex.update("add", ignoredRoute)).toBe(false);
expect(routeIndex.getPaths()).toEqual(["./index.tsx", "./nested/new.tsx"]);
expect(routeIndex.update("unlink", addedRoute)).toBe(true);
expect(routeIndex.getPaths()).toEqual(["./index.tsx"]);
});
});
//# sourceMappingURL=routeIndex.test.native.js.map