From e0667e6ed70409f6eab34c1f686c7a9340a4daa4 Mon Sep 17 00:00:00 2001 From: Philipp Giese Date: Wed, 8 Jan 2025 16:42:50 +0100 Subject: [PATCH] revert some changes; make test work; break app --- deployables/app/app/routes/edit-route.tsx | 23 +++++++++++++++++++-- deployables/app/package.json | 2 ++ deployables/app/tsconfig.cloudflare.json | 4 ++++ deployables/app/tsconfig.json | 6 +----- deployables/app/tsconfig.node.json | 9 ++++---- deployables/app/vite.config.ts | 17 ++++++++------- packages/test-utils/src/renderFramework.tsx | 10 +++++++-- pnpm-lock.yaml | 12 ++++++++--- 8 files changed, 59 insertions(+), 24 deletions(-) diff --git a/deployables/app/app/routes/edit-route.tsx b/deployables/app/app/routes/edit-route.tsx index f5c504b11..54a6d39a4 100644 --- a/deployables/app/app/routes/edit-route.tsx +++ b/deployables/app/app/routes/edit-route.tsx @@ -1,13 +1,32 @@ +import { invariantResponse } from '@epic-web/invariant' +import { executionRouteSchema } from '@zodiac/schema' +import { TextInput } from '@zodiac/ui' import type { Route } from './+types/edit-route' export const loader = ({ request }: Route.LoaderArgs) => { const url = new URL(request.url) - return { url } + const routeData = url.searchParams.get('route') + + invariantResponse(routeData != null, 'Missing "route" parameter') + + const decodedData = Buffer.from(routeData, 'base64') + + try { + const rawJson = JSON.parse(decodedData.toString()) + + return { route: executionRouteSchema.parse(rawJson) } + } catch { + throw new Response(null, { status: 400 }) + } } const EditRoute = ({ loaderData }: Route.ComponentProps) => { - return null + return ( + <> + + + ) } export default EditRoute diff --git a/deployables/app/package.json b/deployables/app/package.json index a0f9eb4f8..863ba227f 100644 --- a/deployables/app/package.json +++ b/deployables/app/package.json @@ -10,8 +10,10 @@ "test": "vitest" }, "dependencies": { + "@epic-web/invariant": "^1.0.0", "@react-router/node": "^7.1.1", "@react-router/serve": "^7.1.1", + "@zodiac/ui": "workspace:*", "@zodiac/schema": "workspace:*", "isbot": "^5.1.17", "react": "^19.0.0", diff --git a/deployables/app/tsconfig.cloudflare.json b/deployables/app/tsconfig.cloudflare.json index fb92d99c4..15f2baaec 100644 --- a/deployables/app/tsconfig.cloudflare.json +++ b/deployables/app/tsconfig.cloudflare.json @@ -11,8 +11,12 @@ ], "compilerOptions": { "composite": true, + "strict": true, "lib": ["DOM", "DOM.Iterable", "ES2022"], "types": ["@cloudflare/workers-types", "vite/client"], + "target": "ES2022", + "module": "ES2022", + "moduleResolution": "bundler", "jsx": "react-jsx", "baseUrl": ".", "rootDirs": [".", "./.react-router/types"], diff --git a/deployables/app/tsconfig.json b/deployables/app/tsconfig.json index 262e8c6a4..d7ce9e49b 100644 --- a/deployables/app/tsconfig.json +++ b/deployables/app/tsconfig.json @@ -5,14 +5,10 @@ { "path": "./tsconfig.cloudflare.json" } ], "compilerOptions": { - "target": "ES2022", - "module": "ES2022", "checkJs": true, "verbatimModuleSyntax": true, "skipLibCheck": true, "strict": true, - "noEmit": true, - "moduleResolution": "bundler", - "types": ["@testing-library/jest-dom"] + "noEmit": true } } diff --git a/deployables/app/tsconfig.node.json b/deployables/app/tsconfig.node.json index 9ce26629c..8e3f1d347 100644 --- a/deployables/app/tsconfig.node.json +++ b/deployables/app/tsconfig.node.json @@ -1,12 +1,13 @@ { "extends": "./tsconfig.json", - "include": ["tailwind.config.ts", "vite.config.ts", "vitest.setup.ts"], + "include": ["tailwind.config.ts", "vite.config.ts"], "compilerOptions": { "composite": true, + "strict": true, "types": ["node"], "lib": ["ES2022"], - "paths": { - "@/test-utils": ["./test-utils/index.ts"] - } + "target": "ES2022", + "module": "ES2022", + "moduleResolution": "bundler" } } diff --git a/deployables/app/vite.config.ts b/deployables/app/vite.config.ts index 4980f60ee..3baa2b61f 100644 --- a/deployables/app/vite.config.ts +++ b/deployables/app/vite.config.ts @@ -1,5 +1,5 @@ -import { vitePluginViteNodeMiniflare } from '@hiogawa/vite-node-miniflare' import { reactRouter } from '@react-router/dev/vite' +import { cloudflareDevProxy } from '@react-router/dev/vite/cloudflare' import autoprefixer from 'autoprefixer' import tailwindcss from 'tailwindcss' import { defineConfig } from 'vite' @@ -36,13 +36,14 @@ export default defineConfig(({ isSsrBuild }) => ({ }, }, plugins: [ - vitePluginViteNodeMiniflare({ - entry: './workers/app.ts', - miniflareOptions: (options) => { - options.compatibilityDate = '2024-11-18' - options.compatibilityFlags = ['nodejs_compat'] - }, - }), + cloudflareDevProxy(), + // vitePluginViteNodeMiniflare({ + // entry: './workers/app.ts', + // miniflareOptions: (options) => { + // options.compatibilityDate = '2024-11-18' + // options.compatibilityFlags = ['nodejs_compat'] + // }, + // }), reactRouter(), tsconfigPaths(), ], diff --git a/packages/test-utils/src/renderFramework.tsx b/packages/test-utils/src/renderFramework.tsx index ff16528b4..07e3c0097 100644 --- a/packages/test-utils/src/renderFramework.tsx +++ b/packages/test-utils/src/renderFramework.tsx @@ -7,6 +7,7 @@ import type { CreateLoaderData, CreateServerLoaderArgs, } from 'react-router/route-module' +import { getCurrentPath } from './getCurrentPath' import { InspectRoute } from './InspectRoute' import type { RenderOptions } from './render' import { sleepTillIdle } from './sleepTillIdle' @@ -64,7 +65,7 @@ export type FrameworkRoute< export async function renderFramework( currentPath: string, route: FrameworkRoute, - { inspectRoutes = [], ...options }: RenderOptions, + { inspectRoutes = [], searchParams = {}, ...options }: RenderOptions, ): Promise { const Stub = createRoutesStub([ { @@ -73,6 +74,8 @@ export async function renderFramework( children: [ { path: route.path, + // @ts-expect-error + loader: route.loader, Component() { const loaderData = useLoaderData() const params = useParams() @@ -92,7 +95,10 @@ export async function renderFramework( }, ]) - const result = render(, options) + const result = render( + , + options, + ) await waitForTestElement() await sleepTillIdle() diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bcb9c9bee..904e497c1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -34,6 +34,9 @@ importers: deployables/app: dependencies: + '@epic-web/invariant': + specifier: ^1.0.0 + version: 1.0.0 '@react-router/node': specifier: ^7.1.1 version: 7.1.1(react-router@7.1.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0))(typescript@5.7.2) @@ -43,6 +46,9 @@ importers: '@zodiac/schema': specifier: workspace:* version: link:../../packages/schema + '@zodiac/ui': + specifier: workspace:* + version: link:../../packages/ui isbot: specifier: ^5.1.17 version: 5.1.20 @@ -10442,7 +10448,7 @@ snapshots: '@babel/plugin-syntax-typescript': 7.25.9(@babel/core@7.26.0) '@vanilla-extract/babel-plugin-debug-ids': 1.2.0 '@vanilla-extract/css': 1.17.0(babel-plugin-macros@3.1.0) - esbuild: 0.17.6 + esbuild: 0.17.19 eval: 0.1.8 find-up: 5.0.0 javascript-stringify: 2.1.0 @@ -13494,7 +13500,7 @@ snapshots: isomorphic-timers-promises@1.0.1: {} - isows@1.0.6(ws@8.18.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)): + isows@1.0.6(ws@8.18.0): dependencies: ws: 8.18.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) @@ -16255,7 +16261,7 @@ snapshots: '@scure/bip32': 1.6.0 '@scure/bip39': 1.5.0 abitype: 1.0.7(typescript@5.7.2)(zod@3.24.1) - isows: 1.0.6(ws@8.18.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)) + isows: 1.0.6(ws@8.18.0) ox: 0.6.0(typescript@5.7.2)(zod@3.24.1) webauthn-p256: 0.0.10 ws: 8.18.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)