From b61c363e8e94ca03ad169109fddcf170132da6b5 Mon Sep 17 00:00:00 2001 From: Logan McAnsh Date: Fri, 4 Nov 2022 15:29:18 -0400 Subject: [PATCH] chore: update imports to @remix-run/server-runtime/dist/router Signed-off-by: Logan McAnsh --- packages/remix-testing/create-remix-stub.tsx | 44 +++++++++----------- packages/remix-testing/package.json | 2 - yarn.lock | 2 +- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/packages/remix-testing/create-remix-stub.tsx b/packages/remix-testing/create-remix-stub.tsx index 3ae9140e8fa..30b24dc0272 100644 --- a/packages/remix-testing/create-remix-stub.tsx +++ b/packages/remix-testing/create-remix-stub.tsx @@ -2,24 +2,26 @@ import * as React from "react"; import { unstable_createStaticHandler as createStaticHandler, matchRoutes, -} from "@remix-run/router"; -import { createMemoryHistory } from "history"; + createMemoryHistory, +} from "@remix-run/server-runtime/dist/router"; +import type { + InitialEntry, + StaticHandler, + LoaderFunction, + ActionFunction, + Location, + AgnosticRouteMatch, + MemoryHistory, +} from "@remix-run/server-runtime/dist/router"; +import type { Update } from "@remix-run/server-runtime/dist/router/history"; import { RemixEntry } from "@remix-run/react/dist/components"; -import type { MemoryHistory, Update } from "history"; import type { ShouldReloadFunction } from "@remix-run/react"; +import { json } from "@remix-run/server-runtime"; import type { ErrorBoundaryComponent, LinksFunction, MetaFunction, } from "@remix-run/server-runtime"; -import { json } from "@remix-run/server-runtime"; -import type { - InitialEntry, - StaticHandler, - LoaderFunction, - ActionFunction, - Location, -} from "@remix-run/router"; import type { AssetsManifest, EntryContext } from "@remix-run/react/dist/entry"; import type { RouteData } from "@remix-run/react/dist/routeData"; import type { @@ -27,7 +29,6 @@ import type { RouteModules, } from "@remix-run/react/dist/routeModules"; import type { EntryRoute, RouteManifest } from "@remix-run/react/dist/routes"; -import type { AgnosticRouteMatch } from "@remix-run/router/dist/utils"; /** * Base RouteObject with common props shared by all types of mock routes @@ -76,19 +77,19 @@ type RemixStubOptions = { * The initial entries in the history stack. This allows you to start a test with * multiple locations already in the history stack (for testing a back navigation, etc.) * The test will default to the last entry in initialEntries if no initialIndex is provided. - * e.g. initialEntries-(["/home", "/about", "/contact"]} + * e.g. initialEntries={["/home", "/about", "/contact"]} */ initialEntries?: InitialEntry[]; /** * Used to set the route's initial loader data. - * e.g. initialLoaderData={("/contact": {locale: "en-US" }} + * e.g. initialLoaderData={{ "/contact": { locale: "en-US" } } */ initialLoaderData?: RouteData; /** * Used to set the route's initial action data. - * e.g. initialActionData={("/login": { errors: { email: "invalid email" } }} + * e.g. initialActionData={{ "/login": { errors: { email: "invalid email" } } } */ initialActionData?: RouteData; @@ -96,8 +97,8 @@ type RemixStubOptions = { * The initial index in the history stack to render. This allows you to start a test at a specific entry. * It defaults to the last entry in initialEntries. * e.g. - * initialEntries: ["/", "/events/123"] - * initialIndex: 1 // start at "/events/123" + * initialEntries={["/", "/events/123"]} + * initialIndex={1} // start at "/events/123" */ initialIndex?: number; }; @@ -210,7 +211,7 @@ function createRouteModules( routes: MockRouteObject[], routeModules?: RouteModules ): RouteModules { - return routes.reduce((modules, route) => { + return routes.reduce((modules, route) => { if (route.children) { createRouteModules(route.children, modules); } @@ -251,12 +252,7 @@ function monkeyPatchFetch( let matches = matchRoutes(dataRoutes, url); if (matches && matchRoutes.length > 0) { let response = await queryRoute(request); - - if (response instanceof Response) { - return response; - } - - return json(response); + return response instanceof Response ? response : json(response); } // if no matches, passthrough to the original fetch as mock routes couldn't handle the request. diff --git a/packages/remix-testing/package.json b/packages/remix-testing/package.json index 0228072559b..61336e1f957 100644 --- a/packages/remix-testing/package.json +++ b/packages/remix-testing/package.json @@ -17,9 +17,7 @@ "module": "./dist/esm/index.js", "dependencies": { "@remix-run/react": "v0.0.0-experimental-96f235c51", - "@remix-run/router": "^1.0.3", "@remix-run/server-runtime": "v0.0.0-experimental-96f235c51", - "history": "^5.3.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.4.3" diff --git a/yarn.lock b/yarn.lock index b4b1f058686..b0ff6ceb136 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2489,7 +2489,7 @@ history "^5.3.0" react-router-dom "6.3.0" -"@remix-run/router@1.0.3", "@remix-run/router@^1.0.3": +"@remix-run/router@1.0.3": version "1.0.3" resolved "https://registry.npmjs.org/@remix-run/router/-/router-1.0.3.tgz#953b88c20ea00d0eddaffdc1b115c08474aa295d" integrity sha512-ceuyTSs7PZ/tQqi19YZNBc5X7kj1f8p+4DIyrcIYFY9h+hd1OKm4RqtiWldR9eGEvIiJfsqwM4BsuCtRIuEw6Q==