UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

72 lines (71 loc) 2.37 kB
import path from "node:path"; import { transformSync } from "@babel/core"; import { describe, expect, it } from "vitest"; import oneBabelPreset from "./index.mjs"; const projectRoot = path.resolve(__dirname, "../../"); describe("one/babel-preset integration", () => { const presetWithOpts = [oneBabelPreset, { projectRoot, includeExpoPreset: false }]; it("runs against a route file without throwing", () => { const code = ` import { useLoader } from 'one' export default function Page() { return null } `; const result = transformSync(code, { filename: path.join(projectRoot, "app/index.tsx"), cwd: projectRoot, presets: [presetWithOpts], parserOpts: { sourceType: "module", plugins: ["jsx"] } }); expect(result?.code).toBeTruthy(); expect(result?.code).toContain("useLoader"); }); it("substitutes ONE_ROUTER_* process.env placeholders in metro-entry", () => { const code = ` const ctx = require.context( process.env.ONE_ROUTER_APP_ROOT_RELATIVE_TO_ENTRY, true, process.env.ONE_ROUTER_REQUIRE_CONTEXT_REGEX_STRING ) const folder = process.env.ONE_ROUTER_ROOT_FOLDER_NAME module.exports = { ctx, folder } `; const result = transformSync(code, { filename: path.join(projectRoot, "metro-entry-ctx.js"), cwd: projectRoot, presets: [presetWithOpts], parserOpts: { sourceType: "module" } }); expect(result?.code).toBeTruthy(); expect(result?.code).not.toContain("process.env.ONE_ROUTER_APP_ROOT_RELATIVE_TO_ENTRY"); expect(result?.code).not.toContain("process.env.ONE_ROUTER_ROOT_FOLDER_NAME"); expect(result?.code).not.toContain("process.env.ONE_ROUTER_REQUIRE_CONTEXT_REGEX_STRING"); expect(result?.code).toContain('"app"'); expect(result?.code).toMatch(/\/\^.*\.tsx\?\$\//); }); it("keeps client code intact in non-route files", () => { const code = ` const x = 1 export default x `; const result = transformSync(code, { filename: path.join(projectRoot, "src/utils/x.ts"), cwd: projectRoot, presets: [presetWithOpts], parserOpts: { sourceType: "module" } }); expect(result?.code).toContain("const x = 1"); }); }); //# sourceMappingURL=integration.test.mjs.map