one
Version:
One is a new React Framework that makes Vite serve both native and web.
43 lines (42 loc) • 2.67 kB
JavaScript
import { describe, expect, it } from "vitest";
import { getSourceInspectorPath, injectSourceToJsx, resolveEditorFilePath } from "./sourceInspectorPlugin.native.js";
describe("sourceInspectorPlugin helpers", function () {
describe("getSourceInspectorPath", function () {
it("keeps project files relative to the current cwd", function () {
expect(getSourceInspectorPath("/repo/packages/one/src/App.tsx", "/repo")).toBe("/packages/one/src/App.tsx");
});
it("does not strip matching path prefixes from files outside cwd", function () {
expect(getSourceInspectorPath("/repo-other/packages/one/src/App.tsx", "/repo")).toBe("/repo-other/packages/one/src/App.tsx");
});
});
describe("resolveEditorFilePath", function () {
it("resolves project-relative source paths against cwd", function () {
var fileExists = function (filePath) {
return filePath === "/repo/packages/one/src/App.tsx";
};
expect(resolveEditorFilePath("/packages/one/src/App.tsx", "/repo", fileExists)).toBe("/repo/packages/one/src/App.tsx");
});
it("preserves absolute source paths for files outside cwd", function () {
expect(resolveEditorFilePath("/Users/n8/shared/ui/Button.tsx", "/repo/apps/site", function () {
return false;
})).toBe("/Users/n8/shared/ui/Button.tsx");
});
});
describe("injectSourceToJsx", function () {
it("tags dom elements and components but leaves custom reconciler tags alone", async function () {
var _ref;
var out = await injectSourceToJsx(["export const Scene = () => (", " <div>", " <Canvas>", " <mesh position={[0, 1, 0]}>", " <boxGeometry />", ' <meshStandardMaterial color="red" />', " </mesh>", " <instancedMesh args={[geometry, material, 4]} />", " </Canvas>", ' <svg><linearGradient id="g" /></svg>', " </div>", ")"].join("\n"), `${process.cwd()}/src/Scene.tsx`);
var code = (_ref = out === null || out === void 0 ? void 0 : out.code) !== null && _ref !== void 0 ? _ref : "";
expect(code).toContain("<div data-one-source=");
expect(code).toContain("<Canvas data-one-source=");
expect(code).toContain("<svg data-one-source=");
expect(code).toContain("<linearGradient data-one-source=");
expect(code).toContain("<mesh position=");
expect(code).toContain("<boxGeometry />");
expect(code).toContain("<meshStandardMaterial color=");
expect(code).toContain("<instancedMesh args=");
expect(code).not.toMatch(/<(mesh|boxGeometry|meshStandardMaterial|instancedMesh) data-one-source/);
});
});
});
//# sourceMappingURL=sourceInspectorPlugin.test.native.js.map