@reckona/mreact-test-utils 0.0.186 → 0.0.188
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/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,UAAU,EACV,IAAI,EACJ,QAAQ,GAGT,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAkC,MAAM,8BAA8B,CAAC;AAC1F,OAAO,EACL,eAAe,EACf,eAAe,EACf,gBAAgB,GAEjB,MAAM,wBAAwB,CAAC;AA8ChC,MAAM,uBAAuB,GAC3B,iGAAiG,CAAC;AAEpG,uEAAuE;AACvE,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAM,GAAG,oBAAoB;IAClE,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC;IAE3D,OAAO;QACL,MAAM;QACN,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,EAAE;YACvB,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,mBAAmB,CAAC;YACrD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;YACpE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,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1C,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;AACvB,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,kBAAkB,CAAI,EAAW;IAC/C,OAAO,QAAQ,CAAC,EAAE,CAAC,CAAC;AACtB,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,OAAO,GAAG,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAExD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAyB,CAAC;AAC1E,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACxC,OAAO,KAAK;SACT,UAAU,CAAC,SAAS,EAAE,GAAG,CAAC;SAC1B,UAAU,CAAC,SAAS,EAAE,GAAG,CAAC;SAC1B,UAAU,CAAC,SAAS,EAAE,GAAG,CAAC;SAC1B,UAAU,CAAC,SAAS,EAAE,QAAQ,CAAC;SAC/B,UAAU,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,cAAc,CAAC,SAAsB,EAAE,KAA2B;IACzE,OAAO,UAAU,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AACtF,CAAC","sourcesContent":["import { mkdir, mkdtemp, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport {\n batchAsync,\n cell,\n computed,\n type Cell,\n type ReadonlyCell,\n} from \"@reckona/mreact-reactive-core\";\nimport { flushEffects } from \"@reckona/mreact-reactive-core/testing\";\nimport { createRoot, type Dispose, type RenderValue } from \"@reckona/mreact-reactive-dom\";\nimport {\n isNotFoundError,\n isRedirectError,\n renderAppRequest,\n type RenderAppRequestOptions,\n} from \"@reckona/mreact-router\";\n\n/** Temporary app fixture for rendering and writing app-router files in tests. */\nexport interface AppFixture {\n readonly appDir: string;\n render(path: string, options?: AppFixtureRenderOptions | undefined): Promise<Response>;\n write(path: string, contents: string): Promise<void>;\n}\n\n/** Options passed when rendering a request with an app fixture. */\nexport type AppFixtureRenderOptions = Omit<RenderAppRequestOptions, \"appDir\" | \"request\"> & {\n request?: RequestInit | undefined;\n origin?: string | undefined;\n};\n\n/** Query state decoded from an SSR hydration script. */\nexport interface DehydratedQueryState {\n queries: Array<{\n data: unknown;\n queryHash: string;\n queryKey: readonly unknown[];\n updatedAt: number;\n }>;\n}\n\n/** Result returned by the component render helper. */\nexport interface ComponentRenderResult {\n readonly container: HTMLElement;\n rerender(value: ComponentRenderInput): void;\n unmount(): void;\n}\n\n/** Component render input accepted by render and rerender. */\nexport type ComponentRenderInput = RenderValue | (() => RenderValue);\n\n/** Route handler signature accepted by invokeRouteHandler. */\nexport type RouteHandler<TContext = undefined> = (\n request: Request,\n context: TContext,\n) => Response | Promise<Response>;\n\n/** Options for mounting a component render in tests. */\nexport interface ComponentRenderOptions {\n container?: HTMLElement | undefined;\n}\n\nconst queryStateScriptPattern =\n /<script\\b[^>]*\\bid=(?:\"__mreact_query_state\"|'__mreact_query_state')[^>]*>([\\s\\S]*?)<\\/script>/i;\n\n/** Creates a temporary app fixture directory for integration tests. */\nexport async function createAppFixture(prefix = \"mreact-app-fixture\"): Promise<AppFixture> {\n const appDir = await mkdtemp(join(tmpdir(), `${prefix}-`));\n\n return {\n appDir,\n render(path, options = {}) {\n const origin = options.origin ?? \"http://local.test\";\n const request = new Request(new URL(path, origin), options.request);\n const { origin: _origin, request: _request, ...routerOptions } = options;\n\n void _origin;\n void _request;\n\n return renderAppRequest({\n ...routerOptions,\n appDir,\n request,\n });\n },\n async write(path, contents) {\n const file = join(appDir, path);\n await mkdir(dirname(file), { recursive: true });\n await writeFile(file, contents);\n },\n };\n}\n\n/** Reads a response body as text. */\nexport async function responseText(response: Response): Promise<string> {\n return response.text();\n}\n\n/** Invokes a route handler and normalizes redirect, not-found, and invalid responses. */\nexport async function invokeRouteHandler<TContext = undefined>(\n handler: RouteHandler<TContext>,\n request: Request,\n context?: TContext,\n): Promise<Response> {\n try {\n const response = await handler(request, context as TContext);\n\n return response instanceof Response\n ? response\n : new Response(\"Invalid route response\", { status: 500 });\n } catch (error) {\n if (error instanceof Response) {\n return error;\n }\n\n if (isRedirectError(error)) {\n return new Response(null, {\n headers: { location: error.location },\n status: error.status,\n });\n }\n\n if (isNotFoundError(error)) {\n return new Response(\"Not Found\", { status: 404 });\n }\n\n throw error;\n }\n}\n\n/** Renders a reactive component value into a DOM container for tests. */\nexport function render(\n value: ComponentRenderInput,\n options: ComponentRenderOptions = {},\n): ComponentRenderResult {\n const container = options.container ?? document.createElement(\"div\");\n let current = value;\n let dispose = mountComponent(container, current);\n\n return {\n container,\n rerender(next) {\n dispose();\n current = next;\n dispose = mountComponent(container, current);\n },\n unmount() {\n dispose();\n },\n };\n}\n\n/** Runs a test action and flushes reactive effects after it settles. */\nexport async function act<T>(fn: () => Promise<T> | T): Promise<T> {\n const result = await batchAsync(fn);\n await flushReactive();\n return result;\n}\n\n/** Flushes queued reactive effects for tests. */\nexport async function flushReactive(): Promise<void> {\n await flushEffects();\n}\n\n/** Creates a real reactive cell for tests that need controllable state. */\nexport function createCellMock<T>(initial: T): Cell<T> {\n return cell(initial);\n}\n\n/** Creates a real computed reactive value for tests. */\nexport function createComputedMock<T>(fn: () => T): ReadonlyCell<T> {\n return computed(fn);\n}\n\n/** Reads dehydrated query state from rendered HTML. */\nexport function readQueryState(html: string): DehydratedQueryState | undefined {\n const encoded = queryStateScriptPattern.exec(html)?.[1];\n\n if (encoded === undefined) {\n return undefined;\n }\n\n return JSON.parse(unescapeJsonForHtml(encoded)) as DehydratedQueryState;\n}\n\nfunction unescapeJsonForHtml(value: string): string {\n return value\n .replaceAll(\"\\\\u003c\", \"<\")\n .replaceAll(\"\\\\u003e\", \">\")\n .replaceAll(\"\\\\u0026\", \"&\")\n .replaceAll(\"\\\\u2028\", \"\\u2028\")\n .replaceAll(\"\\\\u2029\", \"\\u2029\");\n}\n\nfunction mountComponent(container: HTMLElement, value: ComponentRenderInput): Dispose {\n return createRoot(container, () => (typeof value === \"function\" ? value() : value));\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reckona/mreact-test-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.188",
|
|
4
4
|
"description": "Integration test helpers for mreact app-router applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fixtures",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@reckona/mreact-reactive-core": "0.0.
|
|
44
|
-
"@reckona/mreact-
|
|
45
|
-
"@reckona/mreact-
|
|
43
|
+
"@reckona/mreact-reactive-core": "0.0.188",
|
|
44
|
+
"@reckona/mreact-reactive-dom": "0.0.188",
|
|
45
|
+
"@reckona/mreact-router": "0.0.188"
|
|
46
46
|
}
|
|
47
47
|
}
|