Skip to content

Commit

Permalink
tests: bring fixtures in line with templates
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Brophy <[email protected]>
  • Loading branch information
MichaelDeBoey and brophdawg11 committed Aug 23, 2023
1 parent 8cb33ce commit b94ee35
Show file tree
Hide file tree
Showing 37 changed files with 347 additions and 87 deletions.
4 changes: 1 addition & 3 deletions integration/cf-compiler-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ test.describe("cloudflare compiler", () => {
name: "remix-template-cloudflare-workers",
private: true,
sideEffects: false,
main: "build/index.js",
type: "module",
dependencies: {
"@cloudflare/kv-asset-handler": "0.0.0-local-version",
"@remix-run/cloudflare": "0.0.0-local-version",
"@remix-run/cloudflare-workers": "0.0.0-local-version",
"@remix-run/react": "0.0.0-local-version",
isbot: "0.0.0-local-version",
react: "0.0.0-local-version",
Expand All @@ -50,7 +49,6 @@ test.describe("cloudflare compiler", () => {
},
devDependencies: {
"@remix-run/dev": "0.0.0-local-version",
"@remix-run/eslint-config": "0.0.0-local-version",
},
}),
"app/routes/_index.tsx": js`
Expand Down
1 change: 1 addition & 0 deletions integration/deno-compiler-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ test.beforeAll(async () => {
template: "deno-template",
files: {
"package.json": json({
name: "remix-template-deno",
private: true,
sideEffects: false,
type: "module",
Expand Down
6 changes: 6 additions & 0 deletions integration/helpers/cf-template/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { LinksFunction } from "@remix-run/cloudflare";
import { cssBundleHref } from "@remix-run/css-bundle";
import {
Links,
LiveReload,
Expand All @@ -7,6 +9,10 @@ import {
ScrollRestoration,
} from "@remix-run/react";

export const links: LinksFunction = () => [
...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
];

export default function App() {
return (
<html lang="en">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import type { MetaFunction } from "@remix-run/cloudflare";

export const meta: MetaFunction = () => [
{ title: "New Remix App" },
{ name: "description", content: "Welcome to Remix!" },
];

export default function Index() {
return (
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.4" }}>
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>
<h1>Welcome to Remix</h1>
<ul>
<li>
Expand Down
13 changes: 9 additions & 4 deletions integration/helpers/cf-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
"name": "remix-template-cloudflare-workers",
"private": true,
"sideEffects": false,
"main": "build/index.js",
"type": "module",
"scripts": {},
"scripts": {
"build": "node ../../../build/node_modules/@remix-run/dev/dist/cli.js build",
"dev": "node ../../../build/node_modules/@remix-run/dev/dist/cli.js dev --manual -c \"npm start\"",
"start": "node ../../../node_modules/wrangler/bin/wrangler.js dev ./build/index.js"
},
"dependencies": {
"@cloudflare/kv-asset-handler": "0.0.0-local-version",
"@remix-run/cloudflare": "0.0.0-local-version",
"@remix-run/cloudflare-workers": "0.0.0-local-version",
"@remix-run/css-bundle": "0.0.0-local-version",
"@remix-run/react": "0.0.0-local-version",
"isbot": "0.0.0-local-version",
"react": "0.0.0-local-version",
Expand All @@ -18,7 +22,8 @@
"@remix-run/dev": "0.0.0-local-version",
"@types/react": "0.0.0-local-version",
"@types/react-dom": "0.0.0-local-version",
"typescript": "0.0.0-local-version"
"typescript": "0.0.0-local-version",
"wrangler": "0.0.0-local-version"
},
"engines": {
"node": ">=18.0.0"
Expand Down
9 changes: 6 additions & 3 deletions integration/helpers/cf-template/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
export default {
ignoredRouteFiles: ["**/.*"],
server: "./server.ts",
serverConditions: ["worker"],
serverDependenciesToBundle: "all",
serverConditions: ["workerd", "worker", "browser"],
serverDependenciesToBundle: [
// bundle everything except the virtual module for the static content manifest provided by wrangler
/^(?!.*\b__STATIC_CONTENT_MANIFEST\b).*$/,
],
serverMainFields: ["browser", "module", "main"],
serverMinify: true,
serverModuleFormat: "esm",
Expand All @@ -13,7 +16,7 @@ export default {
// serverBuildPath: "build/index.js",
// publicPath: "/build/",

// !!! Don't adust this without changing the code that overwrites this
// !!! Don't adjust this without changing the code that overwrites this
// in createFixtureProject()
...global.INJECTED_FIXTURE_REMIX_CONFIG,
};
7 changes: 6 additions & 1 deletion integration/helpers/cf-template/remix.env.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/// <reference types="@remix-run/dev" />
/// <reference types="@remix-run/cloudflare-workers/globals" />
/// <reference types="@remix-run/cloudflare" />
/// <reference types="@cloudflare/workers-types" />

declare module "__STATIC_CONTENT_MANIFEST" {
const manifest: string;
export default manifest;
}
53 changes: 51 additions & 2 deletions integration/helpers/cf-template/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@
import { createEventHandler } from "@remix-run/cloudflare-workers";
import { getAssetFromKV } from "@cloudflare/kv-asset-handler";
import type { AppLoadContext } from "@remix-run/cloudflare";
import { createRequestHandler, logDevReady } from "@remix-run/cloudflare";
import * as build from "@remix-run/dev/server-build";
import __STATIC_CONTENT_MANIFEST from "__STATIC_CONTENT_MANIFEST";

addEventListener("fetch", createEventHandler({ build, mode: build.mode }));
const MANIFEST = JSON.parse(__STATIC_CONTENT_MANIFEST);
const handleRemixRequest = createRequestHandler(build, process.env.NODE_ENV);

if (process.env.NODE_ENV === "development") {
logDevReady(build);
}

export default {
async fetch(
request: Request,
env: {
__STATIC_CONTENT: Fetcher;
},
ctx: ExecutionContext
): Promise<Response> {
try {
const url = new URL(request.url);
const ttl = url.pathname.startsWith("/build/")
? 60 * 60 * 24 * 365 // 1 year
: 60 * 5; // 5 minutes
return await getAssetFromKV(
{
request,
waitUntil: ctx.waitUntil.bind(ctx),
} as FetchEvent,
{
ASSET_NAMESPACE: env.__STATIC_CONTENT,
ASSET_MANIFEST: MANIFEST,
cacheControl: {
browserTTL: ttl,
edgeTTL: ttl,
},
}
);
} catch (error) {}

try {
const loadContext: AppLoadContext = {
env,
};
return await handleRemixRequest(request, loadContext);
} catch (error) {
console.log(error);
return new Response("An unexpected error occurred", { status: 500 });
}
},
};
18 changes: 4 additions & 14 deletions integration/helpers/cf-template/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
name = "remix-cloudflare-workers"
type = "javascript"
compatibility_date = "2022-04-05"
compatibility_flags = ["streams_enable_constructors"]

zone_id = ""
account_id = ""
route = ""
workers_dev = true
main = "./build/index.js"
# https://developers.cloudflare.com/workers/platform/compatibility-dates
compatibility_date = "2023-04-20"

[site]
bucket = "./public"
entry-point = "."

[build]
command = "npm run build"

[build.upload]
format="service-worker"
bucket = "./public"
8 changes: 7 additions & 1 deletion integration/helpers/deno-template/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { cssBundleHref } from "@remix-run/css-bundle";
import type { LinksFunction } from "@remix-run/deno";
import {
Links,
LiveReload,
Expand All @@ -8,12 +10,16 @@ import {
} from "@remix-run/react";
import * as React from "react";

export const links: LinksFunction = () => [
...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
];

export default function App() {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
Expand Down
40 changes: 40 additions & 0 deletions integration/helpers/deno-template/app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as React from "react";
import type { MetaFunction } from "@remix-run/deno";

export const meta: MetaFunction = () => [
{ title: "New Remix App" },
{ name: "description", content: "Welcome to Remix!" },
];

export default function Index() {
return (
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>
<h1>Welcome to Remix</h1>
<ul>
<li>
<a
target="_blank"
href="https://remix.run/tutorials/blog"
rel="noreferrer"
>
15m Quickstart Blog Tutorial
</a>
</li>
<li>
<a
target="_blank"
href="https://remix.run/tutorials/jokes"
rel="noreferrer"
>
Deep Dive Jokes App Tutorial
</a>
</li>
<li>
<a target="_blank" href="https://remix.run/docs" rel="noreferrer">
Remix Docs
</a>
</li>
</ul>
</div>
);
}
12 changes: 11 additions & 1 deletion integration/helpers/deno-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@
"private": true,
"sideEffects": false,
"type": "module",
"scripts": {
"build": "node ../../../build/node_modules/@remix-run/dev/dist/cli.js build",
"dev": "node ../../../node_modules/npm-run-all/bin/npm-run-all/index.js build --parallel \"dev:*\"",
"dev:deno": "node ../../../node_modules/cross-env/src/bin/cross-env.js NODE_ENV=development deno run --unstable --watch --allow-net --allow-read --allow-env ./build/index.js",
"dev:remix": "node ../../../build/node_modules/@remix-run/dev/dist/cli.js watch",
"start": "node ../../../node_modules/cross-env/src/bin/cross-env.js NODE_ENV=production deno run --unstable --allow-net --allow-read --allow-env ./build/index.js"
},
"dependencies": {
"@remix-run/css-bundle": "0.0.0-local-version",
"@remix-run/deno": "0.0.0-local-version",
"@remix-run/react": "0.0.0-local-version",
"isbot": "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"
"@remix-run/dev": "0.0.0-local-version",
"cross-env": "0.0.0-local-version",
"npm-run-all": "0.0.0-local-version"
},
"engines": {
"node": ">=18.0.0"
Expand Down
2 changes: 1 addition & 1 deletion integration/helpers/deno-template/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
// serverBuildPath: "build/index.js",
// publicPath: "/build/",

// !!! Don't adust this without changing the code that overwrites this
// !!! Don't adjust this without changing the code that overwrites this
// in createFixtureProject()
...global.INJECTED_FIXTURE_REMIX_CONFIG,
};
8 changes: 7 additions & 1 deletion integration/helpers/node-template/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { cssBundleHref } from "@remix-run/css-bundle";
import type { LinksFunction } from "@remix-run/node";
import {
Links,
LiveReload,
Expand All @@ -7,12 +9,16 @@ import {
ScrollRestoration,
} from "@remix-run/react";

export const links: LinksFunction = () => [
...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
];

export default function App() {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from "react";
import type { MetaFunction } from "@remix-run/node";

export const meta: MetaFunction = () => {
return [{ title: "New Remix App" }];
};
export const meta: MetaFunction = () => [
{ title: "New Remix App" },
{ name: "description", content: "Welcome to Remix!" },
];

export default function Index() {
return (
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.4" }}>
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>
<h1>Welcome to Remix</h1>
<ul>
<li>
Expand Down
1 change: 1 addition & 0 deletions integration/helpers/node-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"start": "node ../../../build/node_modules/@remix-run/serve/dist/cli.js build"
},
"dependencies": {
"@remix-run/css-bundle": "0.0.0-local-version",
"@remix-run/node": "0.0.0-local-version",
"@remix-run/react": "0.0.0-local-version",
"@remix-run/serve": "0.0.0-local-version",
Expand Down
2 changes: 1 addition & 1 deletion integration/helpers/node-template/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
// serverBuildPath: "build/index.js",
// publicPath: "/build/",

// !!! Don't adust this without changing the code that overwrites this
// !!! Don't adjust this without changing the code that overwrites this
// in createFixtureProject()
...global.INJECTED_FIXTURE_REMIX_CONFIG,
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.5",
"@changesets/cli": "^2.25.2",
"@cloudflare/kv-asset-handler": "^0.3.0",
"@mcansh/remark-definition-links": "2.4.1",
"@octokit/core": "^3.6.0",
"@octokit/graphql": "^4.8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ node_modules
/functions/\[\[path\]\].js
/functions/\[\[path\]\].js.map
/public/build
.env
.dev.vars
6 changes: 6 additions & 0 deletions packages/remix-dev/__tests__/fixtures/cloudflare/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { LinksFunction } from "@remix-run/cloudflare";
import { cssBundleHref } from "@remix-run/css-bundle";
import {
Links,
LiveReload,
Expand All @@ -7,6 +9,10 @@ import {
ScrollRestoration,
} from "@remix-run/react";

export const links: LinksFunction = () => [
...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
];

export default function App() {
return (
<html lang="en">
Expand Down
Loading

0 comments on commit b94ee35

Please sign in to comment.