Skip to content

Commit

Permalink
chore: update imports to @remix-run/server-runtime/dist/router
Browse files Browse the repository at this point in the history
Signed-off-by: Logan McAnsh <logan@mcan.sh>
  • Loading branch information
mcansh committed Nov 4, 2022
1 parent 76d710f commit b61c363
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
44 changes: 20 additions & 24 deletions packages/remix-testing/create-remix-stub.tsx
Expand Up @@ -2,32 +2,33 @@ 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 {
CatchBoundaryComponent,
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
Expand Down Expand Up @@ -76,28 +77,28 @@ 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;

/**
* 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;
};
Expand Down Expand Up @@ -210,7 +211,7 @@ function createRouteModules(
routes: MockRouteObject[],
routeModules?: RouteModules
): RouteModules {
return routes.reduce((modules, route) => {
return routes.reduce<RouteModules>((modules, route) => {
if (route.children) {
createRouteModules(route.children, modules);
}
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions packages/remix-testing/package.json
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Expand Up @@ -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==
Expand Down

0 comments on commit b61c363

Please sign in to comment.