@tanstack-router-testing/react-start-testing 0.1.0 → 0.2.0
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/dist/vite.mjs +10 -3
- package/dist/vite.mjs.map +1 -1
- package/package.json +2 -2
package/dist/vite.mjs
CHANGED
|
@@ -49,7 +49,11 @@ const tanstackStartBrowserCompat = () => ({
|
|
|
49
49
|
name: "tanstack-start-testing:browser-compat",
|
|
50
50
|
enforce: "pre",
|
|
51
51
|
config() {
|
|
52
|
-
return { environments: { client: { optimizeDeps: { exclude: [
|
|
52
|
+
return { environments: { client: { optimizeDeps: { exclude: [
|
|
53
|
+
"@tanstack/start-storage-context",
|
|
54
|
+
"@tanstack/start-server-core",
|
|
55
|
+
"@tanstack/start-client-core"
|
|
56
|
+
] } } } };
|
|
53
57
|
},
|
|
54
58
|
resolveId(id) {
|
|
55
59
|
return this.environment.name === "client" && id === "@tanstack/start-storage-context" ? STORAGE_CONTEXT_STUB_ID : void 0;
|
|
@@ -78,8 +82,11 @@ const VIRTUAL_MODULE_IDS = new Set([
|
|
|
78
82
|
*/
|
|
79
83
|
const tanstackStartVirtualStubs = () => ({
|
|
80
84
|
name: "tanstack-start-testing:virtual-stubs",
|
|
81
|
-
|
|
82
|
-
return VIRTUAL_MODULE_IDS.
|
|
85
|
+
config() {
|
|
86
|
+
return { resolve: { alias: [...VIRTUAL_MODULE_IDS].map((id) => ({
|
|
87
|
+
find: id,
|
|
88
|
+
replacement: `\0${id}`
|
|
89
|
+
})) } };
|
|
83
90
|
},
|
|
84
91
|
load(id) {
|
|
85
92
|
return id.startsWith("\0") && VIRTUAL_MODULE_IDS.has(id.slice(1)) ? "export default {}; export {};" : void 0;
|
package/dist/vite.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.mjs","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import type { Config } from '@tanstack/router-plugin/vite';\nimport 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 * Additional options forwarded to the underlying `tanstackRouter()` plugin.\n *\n * Explicit top-level options (`routesDirectory`, `generatedRouteTree`) take\n * precedence over values in this object. `target` is always forced to `'react'`.\n *\n * @example\n * ```ts\n * tanstackStartTesting({\n * router: {\n * routeFileIgnorePattern: '.*\\\\.test\\\\.(ts|tsx)$',\n * routeTreeFileFooter: () => [\n * \"declare module '@tanstack/react-start' {\",\n * ' interface Register { router: ReturnType<typeof getRouter> }',\n * '}',\n * ],\n * },\n * })\n * ```\n */\n readonly router?: Partial<Config>;\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 = {}): Plugin[] => {\n const routerPluginOptions = {\n routesDirectory: 'src/routes',\n generatedRouteTree: 'src/routeTree.gen.ts',\n ...options.router,\n ...(options.routesDirectory !== undefined ? { routesDirectory: options.routesDirectory } : {}),\n ...(options.generatedRouteTree !== undefined ? { generatedRouteTree: options.generatedRouteTree } : {}),\n target: 'react' as const,\n };\n const routerPlugins = tanstackRouter(routerPluginOptions);\n const plugins: Plugin[] = [\n ...(Array.isArray(routerPlugins) ? routerPlugins : [routerPlugins]),\n tanstackStartBrowserCompat(),\n tanstackStartVirtualStubs(),\n ...(options.rsc === true ? [tanstackStartRscTestingRuntime()] : []),\n {\n name: '@tanstack/react-start/testing',\n config(): UserConfig & { test: { setupFiles: readonly string[] } } {\n const genPath = routerPluginOptions.generatedRouteTree;\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 STORAGE_CONTEXT_STUB_ID = '\\0tanstack-start-storage-context-browser-stub';\nconst STORAGE_CONTEXT_STUB_CODE = 'export function getStartContext() { return undefined; }\\nexport function runWithStartContext(_ctx, fn) { return fn(); }';\n\n/**\n * Stub `@tanstack/start-storage-context` in browser environments to prevent\n * `node:async_hooks` from crashing Vitest browser mode.\n *\n * @returns A Vite plugin that intercepts the import in client environments and\n * serves a no-op module with matching exports.\n */\nconst tanstackStartBrowserCompat = (): Plugin => ({\n name: 'tanstack-start-testing:browser-compat',\n enforce: 'pre',\n config() {\n return {\n environments: {\n client: {\n optimizeDeps: {\n exclude: ['@tanstack/start-storage-context'],\n },\n },\n },\n };\n },\n resolveId(id) {\n return this.environment.name === 'client' && id === '@tanstack/start-storage-context' ? STORAGE_CONTEXT_STUB_ID : undefined;\n },\n load(id) {\n if (id !== STORAGE_CONTEXT_STUB_ID) return;\n return STORAGE_CONTEXT_STUB_CODE;\n },\n});\n\nconst VIRTUAL_MODULE_IDS = new Set([\n '#tanstack-router-entry',\n '#tanstack-start-entry',\n '#tanstack-start-plugin-adapters',\n '#tanstack-start-server-fn-resolver',\n 'virtual:tanstack-rsc-ssr-decode',\n 'virtual:tanstack-rsc-browser-decode',\n 'tanstack-start-manifest:v',\n 'tanstack-start-injected-head-scripts:v',\n]);\n\n/**\n * Resolve all known `#tanstack-*` and `virtual:tanstack-*` module IDs to\n * empty virtual stubs so they don't cause unresolved import errors in tests.\n *\n * @returns A Vite plugin that resolves and loads no-op stubs for TanStack\n * Start's internal virtual modules.\n */\nconst tanstackStartVirtualStubs = (): Plugin => ({\n name: 'tanstack-start-testing:virtual-stubs',\n
|
|
1
|
+
{"version":3,"file":"vite.mjs","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import type { Config } from '@tanstack/router-plugin/vite';\nimport 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 * Additional options forwarded to the underlying `tanstackRouter()` plugin.\n *\n * Explicit top-level options (`routesDirectory`, `generatedRouteTree`) take\n * precedence over values in this object. `target` is always forced to `'react'`.\n *\n * @example\n * ```ts\n * tanstackStartTesting({\n * router: {\n * routeFileIgnorePattern: '.*\\\\.test\\\\.(ts|tsx)$',\n * routeTreeFileFooter: () => [\n * \"declare module '@tanstack/react-start' {\",\n * ' interface Register { router: ReturnType<typeof getRouter> }',\n * '}',\n * ],\n * },\n * })\n * ```\n */\n readonly router?: Partial<Config>;\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 = {}): Plugin[] => {\n const routerPluginOptions = {\n routesDirectory: 'src/routes',\n generatedRouteTree: 'src/routeTree.gen.ts',\n ...options.router,\n ...(options.routesDirectory !== undefined ? { routesDirectory: options.routesDirectory } : {}),\n ...(options.generatedRouteTree !== undefined ? { generatedRouteTree: options.generatedRouteTree } : {}),\n target: 'react' as const,\n };\n const routerPlugins = tanstackRouter(routerPluginOptions);\n const plugins: Plugin[] = [\n ...(Array.isArray(routerPlugins) ? routerPlugins : [routerPlugins]),\n tanstackStartBrowserCompat(),\n tanstackStartVirtualStubs(),\n ...(options.rsc === true ? [tanstackStartRscTestingRuntime()] : []),\n {\n name: '@tanstack/react-start/testing',\n config(): UserConfig & { test: { setupFiles: readonly string[] } } {\n const genPath = routerPluginOptions.generatedRouteTree;\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 STORAGE_CONTEXT_STUB_ID = '\\0tanstack-start-storage-context-browser-stub';\nconst STORAGE_CONTEXT_STUB_CODE = 'export function getStartContext() { return undefined; }\\nexport function runWithStartContext(_ctx, fn) { return fn(); }';\n\n/**\n * Stub `@tanstack/start-storage-context` in browser environments to prevent\n * `node:async_hooks` from crashing Vitest browser mode.\n *\n * @returns A Vite plugin that intercepts the import in client environments and\n * serves a no-op module with matching exports.\n */\nconst tanstackStartBrowserCompat = (): Plugin => ({\n name: 'tanstack-start-testing:browser-compat',\n enforce: 'pre',\n config() {\n return {\n environments: {\n client: {\n optimizeDeps: {\n exclude: ['@tanstack/start-storage-context', '@tanstack/start-server-core', '@tanstack/start-client-core'],\n },\n },\n },\n };\n },\n resolveId(id) {\n return this.environment.name === 'client' && id === '@tanstack/start-storage-context' ? STORAGE_CONTEXT_STUB_ID : undefined;\n },\n load(id) {\n if (id !== STORAGE_CONTEXT_STUB_ID) return;\n return STORAGE_CONTEXT_STUB_CODE;\n },\n});\n\nconst VIRTUAL_MODULE_IDS = new Set([\n '#tanstack-router-entry',\n '#tanstack-start-entry',\n '#tanstack-start-plugin-adapters',\n '#tanstack-start-server-fn-resolver',\n 'virtual:tanstack-rsc-ssr-decode',\n 'virtual:tanstack-rsc-browser-decode',\n 'tanstack-start-manifest:v',\n 'tanstack-start-injected-head-scripts:v',\n]);\n\n/**\n * Resolve all known `#tanstack-*` and `virtual:tanstack-*` module IDs to\n * empty virtual stubs so they don't cause unresolved import errors in tests.\n *\n * @returns A Vite plugin that resolves and loads no-op stubs for TanStack\n * Start's internal virtual modules.\n */\nconst tanstackStartVirtualStubs = (): Plugin => ({\n name: 'tanstack-start-testing:virtual-stubs',\n config() {\n return {\n resolve: {\n alias: [...VIRTUAL_MODULE_IDS].map(id => ({\n find: id,\n replacement: `\\0${id}`,\n })),\n },\n };\n },\n load(id) {\n return id.startsWith('\\0') && VIRTUAL_MODULE_IDS.has(id.slice(1)) ? 'export default {}; export {};' : undefined;\n },\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":";;;;;;;;AA4DA,MAAa,wBAAwB,UAAuC,EAAE,KAAe;CAC3F,MAAM,sBAAsB;EAC1B,iBAAiB;EACjB,oBAAoB;EACpB,GAAG,QAAQ;EACX,GAAI,QAAQ,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,KAAK,IAAI;AACP,SAAO,GAAG,WAAW,KAAK,IAAI,mBAAmB,IAAI,GAAG,MAAM,EAAE,CAAC,GAAG,kCAAkC,KAAA;;CAEzG;AAED,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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack-router-testing/react-start-testing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Upstream-shaped test helpers for @tanstack/react-start: direct server function tests, mocks, env control, and Vitest wiring.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@tanstack/start-client-core": "1.167.18",
|
|
52
52
|
"@tanstack/start-fn-stubs": "1.161.6",
|
|
53
53
|
"@tanstack/start-storage-context": "1.166.30",
|
|
54
|
-
"@tanstack-router-testing/router-testing-core": "0.
|
|
54
|
+
"@tanstack-router-testing/router-testing-core": "0.2.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@tanstack/react-router": "1.168.24",
|