-
Notifications
You must be signed in to change notification settings - Fork 2.8k
tests: add jsconfig path mapping integration test #3252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,6 @@ | ||
| node_modules | ||
|
|
||
| /.cache | ||
| /build | ||
| /public/build | ||
| .env |
4 changes: 4 additions & 0 deletions
4
integration/helpers/node-javascript-template/app/entry.client.jsx
This file contains hidden or 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,4 @@ | ||
| import { RemixBrowser } from "@remix-run/react"; | ||
| import { hydrate } from "react-dom"; | ||
|
|
||
| hydrate(<RemixBrowser />, document); |
20 changes: 20 additions & 0 deletions
20
integration/helpers/node-javascript-template/app/entry.server.jsx
This file contains hidden or 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,20 @@ | ||
| import { RemixServer } from "@remix-run/react"; | ||
| import { renderToString } from "react-dom/server"; | ||
|
|
||
| export default function handleRequest( | ||
| request, | ||
| responseStatusCode, | ||
| responseHeaders, | ||
| remixContext | ||
| ) { | ||
| let markup = renderToString( | ||
| <RemixServer context={remixContext} url={request.url} /> | ||
| ); | ||
|
|
||
| responseHeaders.set("Content-Type", "text/html"); | ||
|
|
||
| return new Response("<!DOCTYPE html>" + markup, { | ||
| status: responseStatusCode, | ||
| headers: responseHeaders, | ||
| }); | ||
| } |
This file contains hidden or 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,31 @@ | ||
| import { | ||
| Links, | ||
| LiveReload, | ||
| Meta, | ||
| Outlet, | ||
| Scripts, | ||
| ScrollRestoration, | ||
| } from "@remix-run/react"; | ||
|
|
||
| export const meta = () => ({ | ||
| charset: "utf-8", | ||
| title: "New Remix App", | ||
| viewport: "width=device-width,initial-scale=1", | ||
| }); | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <html lang="en"> | ||
| <head> | ||
| <Meta /> | ||
| <Links /> | ||
| </head> | ||
| <body> | ||
| <Outlet /> | ||
| <ScrollRestoration /> | ||
| <Scripts /> | ||
| <LiveReload /> | ||
| </body> | ||
| </html> | ||
| ); | ||
| } |
This file contains hidden or 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,8 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "baseUrl": ".", | ||
| "paths": { | ||
| "~/*": ["./app/*"] | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,25 @@ | ||
| { | ||
| "name": "remix-template-node-javascript", | ||
| "private": true, | ||
| "description": "", | ||
| "license": "", | ||
| "sideEffects": false, | ||
| "scripts": { | ||
| "build": "node ../../../build/node_modules/@remix-run/dev/cli.js build", | ||
| "dev": "node ../../../build/node_modules/@remix-run/dev/cli.js dev", | ||
| "start": "node ../../../build/node_modules/@remix-run/serve/cli.js build" | ||
| }, | ||
| "dependencies": { | ||
| "@remix-run/node": "0.0.0-local-version", | ||
| "@remix-run/react": "0.0.0-local-version", | ||
| "@remix-run/serve": "0.0.0-local-version", | ||
| "react": "0.0.0-local-version", | ||
| "react-dom": "0.0.0-local-version" | ||
| }, | ||
| "devDependencies": { | ||
| "@remix-run/dev": "0.0.0-local-version" | ||
| }, | ||
| "engines": { | ||
| "node": ">=14" | ||
| } | ||
| } |
Binary file not shown.
10 changes: 10 additions & 0 deletions
10
integration/helpers/node-javascript-template/remix.config.js
This file contains hidden or 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,10 @@ | ||
| /** | ||
| * @type {import('@remix-run/dev').AppConfig} | ||
| */ | ||
| module.exports = { | ||
| ignoredRouteFiles: ["**/.*"], | ||
| // appDirectory: "app", | ||
| // assetsBuildDirectory: "public/build", | ||
| // serverBuildPath: "build/index.js", | ||
| // publicPath: "/build/", | ||
| }; |
This file contains hidden or 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,105 @@ | ||
| import { test, expect } from "@playwright/test"; | ||
|
|
||
| import { createFixture, js, json, mdx } from "./helpers/create-fixture"; | ||
| import type { Fixture } from "./helpers/create-fixture"; | ||
|
|
||
| let fixture: Fixture; | ||
|
|
||
| test.beforeAll(async () => { | ||
| fixture = await createFixture({ | ||
| template: 'node-javascript-template', | ||
| files: { | ||
| "app/components/my-lib/index.js": js` | ||
| export const pizza = "this is a pizza"; | ||
| `, | ||
|
|
||
| "app/routes/index.jsx": js` | ||
| import { pizza } from "@mylib"; | ||
| import { json } from "@remix-run/node"; | ||
| import { useLoaderData, Link } from "@remix-run/react"; | ||
|
|
||
| export function loader() { | ||
| return json(pizza); | ||
| } | ||
|
|
||
| export default function Index() { | ||
| let data = useLoaderData(); | ||
| return ( | ||
| <div> | ||
| {data} | ||
| </div> | ||
| ) | ||
| } | ||
| `, | ||
|
|
||
| "app/routes/tilde-alias.jsx": js` | ||
| import { pizza } from "~/components/my-lib"; | ||
| import { json } from "@remix-run/node"; | ||
| import { useLoaderData, Link } from "@remix-run/react"; | ||
|
|
||
| export function loader() { | ||
| return json(pizza); | ||
| } | ||
|
|
||
| export default function Index() { | ||
| let data = useLoaderData(); | ||
| return ( | ||
| <div> | ||
| {data} | ||
| </div> | ||
| ) | ||
| } | ||
| `, | ||
|
|
||
| "app/components/component.jsx": js` | ||
| export function PizzaComponent() { | ||
| return <span>this is a pizza</span> | ||
| } | ||
| `, | ||
|
|
||
| "app/routes/mdx.mdx": mdx` | ||
| --- | ||
| meta: | ||
| title: My First Post | ||
| description: Isn't this awesome? | ||
| headers: | ||
| Cache-Control: no-cache | ||
| --- | ||
|
|
||
| import { PizzaComponent } from "@component"; | ||
|
|
||
| # Hello MDX! | ||
|
|
||
| This is my first post. | ||
|
|
||
| <PizzaComponent /> | ||
| `, | ||
|
|
||
| "jsconfig.json": json({ | ||
| compilerOptions: { | ||
| baseUrl: ".", | ||
| paths: { | ||
| "~/*": ["./app/*"], | ||
| "@mylib": ["./app/components/my-lib/index"], | ||
| "@component": ["./app/components/component.jsx"], | ||
| }, | ||
| }, | ||
| }), | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| test("import internal library via ~ alias", async () => { | ||
| let response = await fixture.requestDocument("/tilde-alias"); | ||
| expect(await response.text()).toMatch("this is a pizza"); | ||
| }); | ||
|
|
||
| test("import internal library via alias other than ~", async () => { | ||
| let response = await fixture.requestDocument("/"); | ||
| expect(await response.text()).toMatch("this is a pizza"); | ||
| }); | ||
|
|
||
| test("works for mdx files", async () => { | ||
| let response = await fixture.requestDocument("/mdx"); | ||
| expect(await response.text()).toMatch("this is a pizza"); | ||
| }); |
File renamed without changes.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we want an extra template for this though. 🤔
Maybe we should wait for the
convert-to-javascriptmigration (see #3150) & call the migration before we do anything else in our tests?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm... I think I'd prefer to duplicate than make a dependency here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means we'll potentially have them double.
What about adding an extra (optional) key to
FixtureInitthat says if we want to use TypeScript or not.If not, the
createFixturefunction could run the migration automatically?That way we don't need double templates + we can choose to use JS in our tests if we want to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with that 👍