Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration/helpers/create-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface FixtureInit {
buildStdio?: Writable;
sourcemap?: boolean;
files: { [filename: string]: string };
template?: "cf-template" | "deno-template" | "node-template";
template?: "cf-template" | "deno-template" | "node-template" | "node-javascript-template";
Copy link
Copy Markdown
Member

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-javascript migration (see #3150) & call the migration before we do anything else in our tests?

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

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 FixtureInit that says if we want to use TypeScript or not.
If not, the createFixture function 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.

Copy link
Copy Markdown
Member

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 👍

setup?: "node" | "cloudflare";
}

Expand Down
6 changes: 6 additions & 0 deletions integration/helpers/node-javascript-template/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules

/.cache
/build
/public/build
.env
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 integration/helpers/node-javascript-template/app/entry.server.jsx
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,
});
}
31 changes: 31 additions & 0 deletions integration/helpers/node-javascript-template/app/root.jsx
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>
);
}
8 changes: 8 additions & 0 deletions integration/helpers/node-javascript-template/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
}
}
}
25 changes: 25 additions & 0 deletions integration/helpers/node-javascript-template/package.json
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 integration/helpers/node-javascript-template/remix.config.js
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/",
};
105 changes: 105 additions & 0 deletions integration/jsconfig-paths-test.ts
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.