Skip to content

Commit

Permalink
tests: bring fixtures in line with templates (#7166)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Brophy <[email protected]>
  • Loading branch information
MichaelDeBoey and brophdawg11 authored Aug 26, 2023
1 parent f77588e commit c28c3cc
Show file tree
Hide file tree
Showing 61 changed files with 584 additions and 180 deletions.
7 changes: 4 additions & 3 deletions integration/cf-compiler-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,26 @@ 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",
"react-dom": "0.0.0-local-version",

"worker-pkg": "0.0.0-local-version",
"browser-pkg": "0.0.0-local-version",
"esm-only-pkg": "0.0.0-local-version",
"cjs-only-pkg": "0.0.0-local-version",
},
devDependencies: {
"@cloudflare/workers-types": "0.0.0-local-version",
"@remix-run/dev": "0.0.0-local-version",
"@remix-run/eslint-config": "0.0.0-local-version",
},
}),

"app/routes/_index.tsx": js`
import fake from "worker-pkg";
import { content as browserPackage } from "browser-pkg";
Expand Down
55 changes: 24 additions & 31 deletions integration/compiler-mjs-output-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test, expect } from "@playwright/test";
import * as fs from "node:fs";
import * as path from "node:path";

import { createFixtureProject, js } from "./helpers/create-fixture.js";
import { createFixtureProject, js, json } from "./helpers/create-fixture.js";

let projectDir: string;

Expand All @@ -16,36 +16,29 @@ test.beforeAll(async () => {
serverBuildPath: "build/index.mjs",
};
`,
"package.json": js`
{
"name": "remix-template-remix",
"private": true,
"sideEffects": false,
"type": "module",
"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",
"start": "node ../../../build/node_modules/@remix-run/serve/dist/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",
"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",
"@types/react": "0.0.0-local-version",
"@types/react-dom": "0.0.0-local-version",
"typescript": "0.0.0-local-version"
},
"engines": {
"node": ">=18.0.0"
}
}
`,
"package.json": json({
name: "remix-template-remix",
private: true,
sideEffects: false,
type: "module",
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",
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",
"@types/react": "0.0.0-local-version",
"@types/react-dom": "0.0.0-local-version",
typescript: "0.0.0-local-version",
},
engines: {
node: ">=18.0.0",
},
}),
"app/routes/_index.tsx": js`
import { json } from "@remix-run/node";
import { useLoaderData, Link } from "@remix-run/react";
Expand Down
4 changes: 3 additions & 1 deletion integration/deno-compiler-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,24 @@ test.beforeAll(async () => {
template: "deno-template",
files: {
"package.json": json({
name: "remix-template-deno",
private: true,
sideEffects: false,
type: "module",
dependencies: {
"@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",

component: "0.0.0-local-version",
"deno-pkg": "0.0.0-local-version",
},
devDependencies: {
"@remix-run/dev": "0.0.0-local-version",
},
}),

"app/routes/_index.tsx": js`
import fake from "deno-pkg";
import { urlComponent } from "https://deno.land/x/component.ts";
Expand Down
35 changes: 34 additions & 1 deletion integration/deterministic-build-output-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import fs from "node:fs";
import path from "node:path";

import type { FixtureInit } from "./helpers/create-fixture.js";
import { createFixtureProject, js, css } from "./helpers/create-fixture.js";
import {
createFixtureProject,
js,
css,
json,
} from "./helpers/create-fixture.js";

test("builds deterministically under different paths", async () => {
// This test validates various flavors of remix virtual modules to ensure
Expand All @@ -27,6 +32,34 @@ test("builds deterministically under different paths", async () => {
// * vanillaExtractPlugin (via app/routes/foo.tsx' .css.ts file import)
let init: FixtureInit = {
files: {
"package.json": json({
name: "remix-template-remix",
private: true,
sideEffects: false,
type: "module",
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",
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",
"@types/react": "0.0.0-local-version",
"@types/react-dom": "0.0.0-local-version",
typescript: "0.0.0-local-version",

"@vanilla-extract/css": "0.0.0-local-version",
"postcss-import": "0.0.0-local-version",
},
engines: {
node: ">=18.0.0",
},
}),

"postcss.config.js": js`
export default {
plugins: {
Expand Down
8 changes: 7 additions & 1 deletion 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,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,6 +1,15 @@
import type { MetaFunction } from "@remix-run/cloudflare";

export const meta: MetaFunction = () => {
return [
{ 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
11 changes: 7 additions & 4 deletions integration/helpers/cf-template/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
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",
serverPlatform: "neutral",
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
// serverBuildPath: "build/index.js",
// publicPath: "/build/",
// serverBuildPath: "build/index.js",

// !!! 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
Loading

0 comments on commit c28c3cc

Please sign in to comment.