Skip to content

Commit b2be2d3

Browse files
committed
feat: update tanstack to use new test convention
1 parent c46e158 commit b2be2d3

23 files changed

+213
-108
lines changed

workbench/tanstack/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ count.txt
1111
.output
1212
.vinxi
1313
todos.json
14+
_workflows.ts

workbench/tanstack/_workflows.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

workbench/tanstack/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
"private": true,
44
"type": "module",
55
"scripts": {
6-
"dev": "vite dev --port 3000",
6+
"generate:workflows": "node ../scripts/generate-workflows-registry.js ./src/workflows ./src/lib/_workflows.ts",
7+
"predev": "pnpm generate:workflows",
8+
"prebuild": "pnpm generate:workflows",
9+
"dev": "vite dev",
710
"build": "vite build",
811
"serve": "vite preview",
912
"test": "vitest run",

workbench/tanstack/src/lib/.gitkeep

Whitespace-only changes.
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/* eslint-disable */
2+
3+
// @ts-nocheck
4+
5+
// noinspection JSUnusedGlobalSymbols
6+
7+
// This file was automatically generated by TanStack Router.
8+
// You should NOT make any changes in this file as it will be overwritten.
9+
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
10+
11+
import { Route as rootRouteImport } from './routes/__root';
12+
import { Route as IndexRouteImport } from './routes/index';
13+
import { Route as ApiTriggerRouteImport } from './routes/api/trigger';
14+
import { Route as ApiTestDirectStepCallRouteImport } from './routes/api/test-direct-step-call';
15+
import { Route as ApiHookRouteImport } from './routes/api/hook';
16+
import { Route as ApiChatRouteImport } from './routes/api/chat';
17+
18+
const IndexRoute = IndexRouteImport.update({
19+
id: '/',
20+
path: '/',
21+
getParentRoute: () => rootRouteImport,
22+
} as any);
23+
const ApiTriggerRoute = ApiTriggerRouteImport.update({
24+
id: '/api/trigger',
25+
path: '/api/trigger',
26+
getParentRoute: () => rootRouteImport,
27+
} as any);
28+
const ApiTestDirectStepCallRoute = ApiTestDirectStepCallRouteImport.update({
29+
id: '/api/test-direct-step-call',
30+
path: '/api/test-direct-step-call',
31+
getParentRoute: () => rootRouteImport,
32+
} as any);
33+
const ApiHookRoute = ApiHookRouteImport.update({
34+
id: '/api/hook',
35+
path: '/api/hook',
36+
getParentRoute: () => rootRouteImport,
37+
} as any);
38+
const ApiChatRoute = ApiChatRouteImport.update({
39+
id: '/api/chat',
40+
path: '/api/chat',
41+
getParentRoute: () => rootRouteImport,
42+
} as any);
43+
44+
export interface FileRoutesByFullPath {
45+
'/': typeof IndexRoute;
46+
'/api/chat': typeof ApiChatRoute;
47+
'/api/hook': typeof ApiHookRoute;
48+
'/api/test-direct-step-call': typeof ApiTestDirectStepCallRoute;
49+
'/api/trigger': typeof ApiTriggerRoute;
50+
}
51+
export interface FileRoutesByTo {
52+
'/': typeof IndexRoute;
53+
'/api/chat': typeof ApiChatRoute;
54+
'/api/hook': typeof ApiHookRoute;
55+
'/api/test-direct-step-call': typeof ApiTestDirectStepCallRoute;
56+
'/api/trigger': typeof ApiTriggerRoute;
57+
}
58+
export interface FileRoutesById {
59+
__root__: typeof rootRouteImport;
60+
'/': typeof IndexRoute;
61+
'/api/chat': typeof ApiChatRoute;
62+
'/api/hook': typeof ApiHookRoute;
63+
'/api/test-direct-step-call': typeof ApiTestDirectStepCallRoute;
64+
'/api/trigger': typeof ApiTriggerRoute;
65+
}
66+
export interface FileRouteTypes {
67+
fileRoutesByFullPath: FileRoutesByFullPath;
68+
fullPaths:
69+
| '/'
70+
| '/api/chat'
71+
| '/api/hook'
72+
| '/api/test-direct-step-call'
73+
| '/api/trigger';
74+
fileRoutesByTo: FileRoutesByTo;
75+
to:
76+
| '/'
77+
| '/api/chat'
78+
| '/api/hook'
79+
| '/api/test-direct-step-call'
80+
| '/api/trigger';
81+
id:
82+
| '__root__'
83+
| '/'
84+
| '/api/chat'
85+
| '/api/hook'
86+
| '/api/test-direct-step-call'
87+
| '/api/trigger';
88+
fileRoutesById: FileRoutesById;
89+
}
90+
export interface RootRouteChildren {
91+
IndexRoute: typeof IndexRoute;
92+
ApiChatRoute: typeof ApiChatRoute;
93+
ApiHookRoute: typeof ApiHookRoute;
94+
ApiTestDirectStepCallRoute: typeof ApiTestDirectStepCallRoute;
95+
ApiTriggerRoute: typeof ApiTriggerRoute;
96+
}
97+
98+
declare module '@tanstack/react-router' {
99+
interface FileRoutesByPath {
100+
'/': {
101+
id: '/';
102+
path: '/';
103+
fullPath: '/';
104+
preLoaderRoute: typeof IndexRouteImport;
105+
parentRoute: typeof rootRouteImport;
106+
};
107+
'/api/trigger': {
108+
id: '/api/trigger';
109+
path: '/api/trigger';
110+
fullPath: '/api/trigger';
111+
preLoaderRoute: typeof ApiTriggerRouteImport;
112+
parentRoute: typeof rootRouteImport;
113+
};
114+
'/api/test-direct-step-call': {
115+
id: '/api/test-direct-step-call';
116+
path: '/api/test-direct-step-call';
117+
fullPath: '/api/test-direct-step-call';
118+
preLoaderRoute: typeof ApiTestDirectStepCallRouteImport;
119+
parentRoute: typeof rootRouteImport;
120+
};
121+
'/api/hook': {
122+
id: '/api/hook';
123+
path: '/api/hook';
124+
fullPath: '/api/hook';
125+
preLoaderRoute: typeof ApiHookRouteImport;
126+
parentRoute: typeof rootRouteImport;
127+
};
128+
'/api/chat': {
129+
id: '/api/chat';
130+
path: '/api/chat';
131+
fullPath: '/api/chat';
132+
preLoaderRoute: typeof ApiChatRouteImport;
133+
parentRoute: typeof rootRouteImport;
134+
};
135+
}
136+
}
137+
138+
const rootRouteChildren: RootRouteChildren = {
139+
IndexRoute: IndexRoute,
140+
ApiChatRoute: ApiChatRoute,
141+
ApiHookRoute: ApiHookRoute,
142+
ApiTestDirectStepCallRoute: ApiTestDirectStepCallRoute,
143+
ApiTriggerRoute: ApiTriggerRoute,
144+
};
145+
export const routeTree = rootRouteImport
146+
._addFileChildren(rootRouteChildren)
147+
._addFileTypes<FileRouteTypes>();
148+
149+
import type { getRouter } from './router.tsx';
150+
import type { createStart } from '@tanstack/react-start';
151+
declare module '@tanstack/react-start' {
152+
interface Register {
153+
ssr: true;
154+
router: Awaited<ReturnType<typeof getRouter>>;
155+
}
156+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// THIS FILE IS JUST FOR TESTING HMR AS AN ENTRY NEEDS
2+
// TO IMPORT THE WORKFLOWS TO DISCOVER THEM AND WATCH
3+
4+
import { createFileRoute } from '@tanstack/react-router';
5+
import { json } from '@tanstack/react-start';
6+
import * as workflows from '../../workflows/3_streams.js';
7+
8+
export const Route = createFileRoute('/api/chat')({
9+
server: {
10+
handlers: {
11+
POST: async ({ request }) => {
12+
console.log(workflows);
13+
return json('hello world');
14+
},
15+
},
16+
},
17+
});

workbench/tanstack/src/routes/api/hook.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ export const Route = createFileRoute('/api/hook')({
1515
} catch (error) {
1616
console.log('error during getHookByToken', error);
1717
// TODO: `WorkflowAPIError` is not exported, so for now
18-
// we'll return 400 assuming it's the "invalid" token test case
19-
return json(null, { status: 400 });
18+
// we'll return 422 assuming it's the "invalid" token test case
19+
// NOTE: Need to return 422 because Nitro passes 404 requests to the dev server to handle.
20+
return json(null, { status: 422 });
2021
}
2122

2223
await resumeHook(hook.token, {

workbench/tanstack/src/routes/api/signup.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// This route tests calling step functions directly outside of any workflow context
2+
// After the SWC compiler changes, step functions in client mode have their directive removed
3+
// and keep their original implementation, allowing them to be called as regular async functions
4+
5+
import { createFileRoute } from '@tanstack/react-router';
6+
import { json } from '@tanstack/react-start';
7+
import { add } from '../../workflows/99_e2e.js';
8+
9+
export const Route = createFileRoute('/api/test-direct-step-call')({
10+
server: {
11+
handlers: {
12+
POST: async ({ request }) => {
13+
const body = await request.json();
14+
const { x, y } = body;
15+
16+
console.log(`Calling step function directly with x=${x}, y=${y}`);
17+
18+
// Call step function directly as a regular async function (no workflow context)
19+
const result = await add(x, y);
20+
console.log(`add(${x}, ${y}) = ${result}`);
21+
22+
return json({ result });
23+
},
24+
},
25+
},
26+
});

workbench/tanstack/src/routes/api/trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { createFileRoute } from '@tanstack/react-router';
22
import { json } from '@tanstack/react-start';
3-
import { allWorkflows } from '_workflows.js';
43
import { getRun, start } from 'workflow/api';
54
import { hydrateWorkflowArguments } from 'workflow/internal/serialization';
5+
import { allWorkflows } from '../../lib/_workflows.js';
66

77
export const Route = createFileRoute('/api/trigger')({
88
server: {

0 commit comments

Comments
 (0)