Skip to content

Commit

Permalink
revert some changes; make test work; break app
Browse files Browse the repository at this point in the history
  • Loading branch information
frontendphil committed Jan 8, 2025
1 parent 68da90b commit e0667e6
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 24 deletions.
23 changes: 21 additions & 2 deletions deployables/app/app/routes/edit-route.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<TextInput label="Label" defaultValue={loaderData.route.label} />
</>
)
}

export default EditRoute
2 changes: 2 additions & 0 deletions deployables/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions deployables/app/tsconfig.cloudflare.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
6 changes: 1 addition & 5 deletions deployables/app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
9 changes: 5 additions & 4 deletions deployables/app/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
17 changes: 9 additions & 8 deletions deployables/app/vite.config.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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(),
],
Expand Down
10 changes: 8 additions & 2 deletions packages/test-utils/src/renderFramework.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -64,7 +65,7 @@ export type FrameworkRoute<
export async function renderFramework<Module extends RouteModule>(
currentPath: string,
route: FrameworkRoute<Module>,
{ inspectRoutes = [], ...options }: RenderOptions,
{ inspectRoutes = [], searchParams = {}, ...options }: RenderOptions,
): Promise<RenderResult> {
const Stub = createRoutesStub([
{
Expand All @@ -73,6 +74,8 @@ export async function renderFramework<Module extends RouteModule>(
children: [
{
path: route.path,
// @ts-expect-error
loader: route.loader,
Component() {
const loaderData = useLoaderData<typeof route.loader>()
const params = useParams()
Expand All @@ -92,7 +95,10 @@ export async function renderFramework<Module extends RouteModule>(
},
])

const result = render(<Stub initialEntries={[currentPath]} />, options)
const result = render(
<Stub initialEntries={[getCurrentPath(currentPath, searchParams)]} />,
options,
)

await waitForTestElement()
await sleepTillIdle()
Expand Down
12 changes: 9 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e0667e6

Please sign in to comment.