UNPKG

one

Version:

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

34 lines (33 loc) 1.19 kB
import path from "node:path"; import { getReactNavigationConfig } from "./getReactNavigationConfig"; import { getRoutes } from "./router/getRoutes"; const validExtensions = [".js", ".jsx", ".ts", ".tsx"]; function inMemoryContext(context) { return Object.assign( (id) => (id = id.replace(/^\.\//, "").replace(/\.\w*$/, ""), typeof context[id] == "function" ? { default: context[id] } : context[id]), { resolve: (key) => key, id: "0", keys: () => Object.keys(context).map((key) => { const ext = path.extname(key); return key = key.replace(/^\.\//, ""), key = key.startsWith("/") ? key : `./${key}`, key = validExtensions.includes(ext) ? key : `${key}.js`, key; }) } ); } function getMockContext(context) { if (Array.isArray(context)) return inMemoryContext( Object.fromEntries(context.map((filename) => [filename, { default: () => null }])) ); throw new Error("Invalid context"); } function getMockConfig(context, metaOnly = !0) { return getReactNavigationConfig(getRoutes(getMockContext(context)), metaOnly); } export { getMockConfig, getMockContext, inMemoryContext }; //# sourceMappingURL=testing-utils.js.map