@tanstack-router-testing/react-start-testing 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +100 -0
- package/dist/index.d.mts +399 -0
- package/dist/index.mjs +337 -0
- package/dist/index.mjs.map +1 -0
- package/dist/shim-DR16QaLL.mjs +486 -0
- package/dist/shim-DR16QaLL.mjs.map +1 -0
- package/dist/shim.d.mts +19 -0
- package/dist/shim.mjs +3 -0
- package/dist/vite.d.mts +40 -0
- package/dist/vite.mjs +61 -0
- package/dist/vite.mjs.map +1 -0
- package/package.json +79 -0
package/dist/vite.mjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { tanstackRouter } from "@tanstack/router-plugin/vite";
|
|
2
|
+
//#region src/vite.ts
|
|
3
|
+
/**
|
|
4
|
+
* Vite/Vitest plugins for TanStack Start tests.
|
|
5
|
+
*
|
|
6
|
+
* This keeps route-tree generation on the real TanStack router plugin path
|
|
7
|
+
* while swapping the Start runtime to the in-process testing shim.
|
|
8
|
+
*/
|
|
9
|
+
const tanstackStartTesting = (options = {}) => {
|
|
10
|
+
const routerPlugins = tanstackRouter({
|
|
11
|
+
routesDirectory: options.routesDirectory ?? "src/routes",
|
|
12
|
+
generatedRouteTree: options.generatedRouteTree ?? "src/routeTree.gen.ts",
|
|
13
|
+
target: "react"
|
|
14
|
+
});
|
|
15
|
+
return [
|
|
16
|
+
...Array.isArray(routerPlugins) ? routerPlugins : [routerPlugins],
|
|
17
|
+
...options.rsc === true ? [tanstackStartRscTestingRuntime()] : [],
|
|
18
|
+
{
|
|
19
|
+
name: "@tanstack/react-start/testing",
|
|
20
|
+
config() {
|
|
21
|
+
const genPath = options.generatedRouteTree ?? "src/routeTree.gen.ts";
|
|
22
|
+
return {
|
|
23
|
+
...options.aliasReactStart !== false ? { resolve: { alias: [{
|
|
24
|
+
find: /^@tanstack\/react-start$/,
|
|
25
|
+
replacement: "@tanstack-router-testing/react-start-testing/shim"
|
|
26
|
+
}] } } : {},
|
|
27
|
+
test: { setupFiles: [genPath] }
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
];
|
|
32
|
+
};
|
|
33
|
+
const VIRTUAL_RSC_RUNTIME = "virtual:tanstack-rsc-runtime";
|
|
34
|
+
const RESOLVED_VIRTUAL_RSC_RUNTIME = "\0@tanstack/react-start/testing/rsc-runtime";
|
|
35
|
+
const tanstackStartRscTestingRuntime = () => ({
|
|
36
|
+
name: "@tanstack/react-start/testing-rsc-runtime",
|
|
37
|
+
resolveId(id) {
|
|
38
|
+
return id === VIRTUAL_RSC_RUNTIME ? RESOLVED_VIRTUAL_RSC_RUNTIME : void 0;
|
|
39
|
+
},
|
|
40
|
+
load(id) {
|
|
41
|
+
if (id !== RESOLVED_VIRTUAL_RSC_RUNTIME) return;
|
|
42
|
+
return `
|
|
43
|
+
import ReactDOMServer from 'react-dom/server';
|
|
44
|
+
|
|
45
|
+
export function renderToReadableStream(node) {
|
|
46
|
+
const html = ReactDOMServer.renderToString(node);
|
|
47
|
+
const encoder = new TextEncoder();
|
|
48
|
+
return new ReadableStream({
|
|
49
|
+
start(controller) {
|
|
50
|
+
controller.enqueue(encoder.encode(html));
|
|
51
|
+
controller.close();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
`;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
//#endregion
|
|
59
|
+
export { tanstackStartTesting };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=vite.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.mjs","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import type { Plugin, UserConfig } from 'vite';\n\nimport { tanstackRouter } from '@tanstack/router-plugin/vite';\n\nexport interface TanstackStartTestingOptions {\n /**\n * Directory holding file-based routes, relative to the Vite root.\n *\n * @defaultValue `'src/routes'`\n */\n readonly routesDirectory?: string;\n /**\n * Output path for the generated route tree, relative to the Vite root.\n *\n * @defaultValue `'src/routeTree.gen.ts'`\n */\n readonly generatedRouteTree?: string;\n /**\n * Whether to alias `@tanstack/react-start` to the test runtime shim.\n *\n * @defaultValue `true`\n */\n readonly aliasReactStart?: boolean;\n /**\n * Install a small test runtime module for TanStack Start RSC imports that\n * need `virtual:tanstack-rsc-runtime` under Vitest.\n *\n * @defaultValue `false`\n */\n readonly rsc?: boolean;\n}\n\n/**\n * Vite/Vitest plugins for TanStack Start tests.\n *\n * This keeps route-tree generation on the real TanStack router plugin path\n * while swapping the Start runtime to the in-process testing shim.\n */\nexport const tanstackStartTesting = (options: TanstackStartTestingOptions = {}): readonly Plugin[] => {\n const routerPluginOptions = {\n routesDirectory: options.routesDirectory ?? 'src/routes',\n generatedRouteTree: options.generatedRouteTree ?? 'src/routeTree.gen.ts',\n target: 'react' as const,\n };\n const routerPlugins = tanstackRouter(routerPluginOptions);\n const plugins: Plugin[] = [\n ...(Array.isArray(routerPlugins) ? routerPlugins : [routerPlugins]),\n ...(options.rsc === true ? [tanstackStartRscTestingRuntime()] : []),\n {\n name: '@tanstack/react-start/testing',\n config(): UserConfig & { test: { setupFiles: readonly string[] } } {\n const genPath = options.generatedRouteTree ?? 'src/routeTree.gen.ts';\n return {\n ...(options.aliasReactStart !== false\n ? {\n resolve: {\n alias: [\n {\n find: /^@tanstack\\/react-start$/,\n replacement: '@tanstack-router-testing/react-start-testing/shim',\n },\n ],\n },\n }\n : {}),\n test: {\n setupFiles: [genPath],\n },\n };\n },\n },\n ];\n return plugins;\n};\n\nconst VIRTUAL_RSC_RUNTIME = 'virtual:tanstack-rsc-runtime';\nconst RESOLVED_VIRTUAL_RSC_RUNTIME = '\\0@tanstack/react-start/testing/rsc-runtime';\n\nconst tanstackStartRscTestingRuntime = (): Plugin => ({\n name: '@tanstack/react-start/testing-rsc-runtime',\n resolveId(id) {\n return id === VIRTUAL_RSC_RUNTIME ? RESOLVED_VIRTUAL_RSC_RUNTIME : undefined;\n },\n load(id) {\n if (id !== RESOLVED_VIRTUAL_RSC_RUNTIME) return;\n return `\n import ReactDOMServer from 'react-dom/server';\n\n export function renderToReadableStream(node) {\n const html = ReactDOMServer.renderToString(node);\n const encoder = new TextEncoder();\n return new ReadableStream({\n start(controller) {\n controller.enqueue(encoder.encode(html));\n controller.close();\n }\n });\n }\n `;\n },\n});\n"],"mappings":";;;;;;;;AAsCA,MAAa,wBAAwB,UAAuC,EAAE,KAAwB;CAMpG,MAAM,gBAAgB,eAAe;EAJnC,iBAAiB,QAAQ,mBAAmB;EAC5C,oBAAoB,QAAQ,sBAAsB;EAClD,QAAQ;EAE8C,CAAC;AA4BzD,QAAO;EA1BL,GAAI,MAAM,QAAQ,cAAc,GAAG,gBAAgB,CAAC,cAAc;EAClE,GAAI,QAAQ,QAAQ,OAAO,CAAC,gCAAgC,CAAC,GAAG,EAAE;EAClE;GACE,MAAM;GACN,SAAmE;IACjE,MAAM,UAAU,QAAQ,sBAAsB;AAC9C,WAAO;KACL,GAAI,QAAQ,oBAAoB,QAC5B,EACE,SAAS,EACP,OAAO,CACL;MACE,MAAM;MACN,aAAa;MACd,CACF,EACF,EACF,GACD,EAAE;KACN,MAAM,EACJ,YAAY,CAAC,QAAQ,EACtB;KACF;;GAEJ;EAEW;;AAGhB,MAAM,sBAAsB;AAC5B,MAAM,+BAA+B;AAErC,MAAM,wCAAgD;CACpD,MAAM;CACN,UAAU,IAAI;AACZ,SAAO,OAAO,sBAAsB,+BAA+B,KAAA;;CAErE,KAAK,IAAI;AACP,MAAI,OAAO,6BAA8B;AACzC,SAAO;;;;;;;;;;;;;;;CAeV"}
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tanstack-router-testing/react-start-testing",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Upstream-shaped test helpers for @tanstack/react-start: direct server function tests, mocks, env control, and Vitest wiring.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"server-functions",
|
|
8
|
+
"start",
|
|
9
|
+
"tanstack",
|
|
10
|
+
"testing",
|
|
11
|
+
"vitest"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "eve0415",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/eve0415/tanstack-router-testing.git",
|
|
18
|
+
"directory": "packages/react-start-testing"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"!**/*.tsbuildinfo"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"main": "./dist/index.mjs",
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.mts",
|
|
31
|
+
"import": "./dist/index.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./shim": {
|
|
34
|
+
"types": "./dist/shim.d.mts",
|
|
35
|
+
"import": "./dist/shim.mjs"
|
|
36
|
+
},
|
|
37
|
+
"./vite": {
|
|
38
|
+
"types": "./dist/vite.d.mts",
|
|
39
|
+
"import": "./dist/vite.mjs"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@tanstack/router-plugin": "1.167.25",
|
|
47
|
+
"@tanstack/start-client-core": "1.167.18",
|
|
48
|
+
"@tanstack/start-fn-stubs": "1.161.6",
|
|
49
|
+
"@tanstack/start-storage-context": "1.166.30",
|
|
50
|
+
"@tanstack-router-testing/router-testing-core": "0.0.1"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@tanstack/react-router": "1.168.24",
|
|
54
|
+
"@tanstack/react-start": "1.167.47",
|
|
55
|
+
"@testing-library/react": "16.3.2",
|
|
56
|
+
"@types/react": "19.2.14",
|
|
57
|
+
"@types/react-dom": "19.2.3",
|
|
58
|
+
"@typescript/native-preview": "7.0.0-dev.20260424.2",
|
|
59
|
+
"jsdom": "29.0.2",
|
|
60
|
+
"react": "19.2.5",
|
|
61
|
+
"react-dom": "19.2.5",
|
|
62
|
+
"tsdown": "0.21.10",
|
|
63
|
+
"vite": "8.0.10",
|
|
64
|
+
"vitest": "4.1.5"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"@tanstack/react-router": "^1.168.0",
|
|
68
|
+
"@tanstack/react-start": "^1.167.0",
|
|
69
|
+
"react": "^19.0.0",
|
|
70
|
+
"react-dom": "^19.0.0",
|
|
71
|
+
"vite": "^7.0.0 || ^8.0.0"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "tsdown",
|
|
75
|
+
"dev": "tsdown --watch",
|
|
76
|
+
"test:unit": "vitest run --passWithNoTests",
|
|
77
|
+
"test:types": "tsgo --noEmit"
|
|
78
|
+
}
|
|
79
|
+
}
|