-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
182 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/remix-dev/__tests__/transform-replaceRemixMagicImports-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import replaceRemixMagicImports from "../codemod/replace-remix-magic-imports/transform"; | ||
|
||
it("replaces single-specifier imports", async () => { | ||
let code = [ | ||
'import { json } from "remix"', | ||
'import type { GetLoadContextFunction } from "remix"', | ||
'import { type LinkProps } from "remix"', | ||
].join("\n"); | ||
let transform = replaceRemixMagicImports({ | ||
runtime: "node", | ||
adapter: "express", | ||
}); | ||
let result = transform(code, "fake.tsx"); | ||
expect(result).toBe( | ||
[ | ||
'import { type GetLoadContextFunction } from "@remix-run/express";', | ||
'import { json } from "@remix-run/node";', | ||
'import { type LinkProps } from "@remix-run/react";', | ||
].join("\n") | ||
); | ||
}); | ||
|
||
it("replaces single-kind, multi-specifier imports", async () => { | ||
let code = [ | ||
'import { json, createRequestHandler, Form } from "remix"', | ||
'import type { ActionFunction, GetLoadContextFunction, LinkProps } from "remix"', | ||
'import { type Cookie, type RequestHandler, type NavLinkProps } from "remix"', | ||
].join("\n"); | ||
let transform = replaceRemixMagicImports({ | ||
runtime: "node", | ||
adapter: "express", | ||
}); | ||
let result = transform(code, "fake.tsx"); | ||
expect(result).toBe( | ||
[ | ||
'import { type GetLoadContextFunction, type RequestHandler, createRequestHandler } from "@remix-run/express";', | ||
'import { type ActionFunction, type Cookie, json } from "@remix-run/node";', | ||
'import { type LinkProps, type NavLinkProps, Form } from "@remix-run/react";', | ||
].join("\n") | ||
); | ||
}); | ||
|
||
it("replaces multi-kind, multi-specifier imports", async () => { | ||
let code = [ | ||
'import { json, type ActionFunction, createRequestHandler, type GetLoadContextFunction, Form, type LinkProps } from "remix"', | ||
].join("\n"); | ||
let transform = replaceRemixMagicImports({ | ||
runtime: "node", | ||
adapter: "express", | ||
}); | ||
let result = transform(code, "fake.tsx"); | ||
expect(result).toBe( | ||
[ | ||
'import { type GetLoadContextFunction, createRequestHandler } from "@remix-run/express";', | ||
'import { type ActionFunction, json } from "@remix-run/node";', | ||
'import { type LinkProps, Form } from "@remix-run/react";', | ||
].join("\n") | ||
); | ||
}); | ||
|
||
it("replaces runtime-specific and adapter-specific imports", async () => { | ||
let code = [ | ||
'import { json, createCloudflareKVSessionStorage, createRequestHandler, createPagesFunctionHandler, Form } from "remix"', | ||
'import type { ActionFunction, GetLoadContextFunction, createPagesFunctionHandlerParams, LinkProps } from "remix"', | ||
].join("\n"); | ||
let transform = replaceRemixMagicImports({ | ||
runtime: "cloudflare", | ||
adapter: "cloudflare-pages", | ||
}); | ||
let result = transform(code, "fake.tsx"); | ||
expect(result).toBe( | ||
[ | ||
'import { type ActionFunction, createCloudflareKVSessionStorage, json } from "@remix-run/cloudflare";', | ||
"", // TODO why is this newline here? | ||
"import {", | ||
" type GetLoadContextFunction,", | ||
" type createPagesFunctionHandlerParams,", | ||
" createPagesFunctionHandler,", | ||
" createRequestHandler,", | ||
'} from "@remix-run/cloudflare-pages";', | ||
"", // TODO why is this newline here? | ||
'import { type LinkProps, Form } from "@remix-run/react";', | ||
].join("\n") | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters