@multiplatform.one/test-utils 7.82.4 → 7.82.6
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/package.json +2 -1
- package/src/index.tsx +23 -0
- package/types/index.d.ts +8 -0
- package/types/index.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/test-utils",
|
|
3
|
-
"version": "7.82.
|
|
3
|
+
"version": "7.82.6",
|
|
4
4
|
"description": "Shared testing utilities for multiplatform.one packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"multiplatform.one",
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
"@testing-library/jest-dom": "^7.0.1",
|
|
65
65
|
"@testing-library/react": "^16.3.3",
|
|
66
66
|
"matchmedia-polyfill": "^0.3.2",
|
|
67
|
+
"react-cookie": "^8.1.2",
|
|
67
68
|
"tamagui": "2.7.6"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
package/src/index.tsx
CHANGED
|
@@ -19,6 +19,7 @@ import type { RenderOptions, RenderResult } from "@testing-library/react";
|
|
|
19
19
|
import type { ReactElement, ReactNode } from "react";
|
|
20
20
|
import { TamaguiProvider, YStack } from "tamagui";
|
|
21
21
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
22
|
+
import { Cookies, CookiesProvider } from "react-cookie";
|
|
22
23
|
|
|
23
24
|
// ─── Types ───────────────────────────────────────────────────────────────────
|
|
24
25
|
|
|
@@ -27,6 +28,11 @@ export interface RenderWithProvidersOptions extends Omit<RenderOptions, "wrapper
|
|
|
27
28
|
tamagui?: boolean;
|
|
28
29
|
/** Wrap in QueryClientProvider. Defaults to true. Pass a QueryClient to use a custom one. */
|
|
29
30
|
queryClient?: boolean | QueryClient;
|
|
31
|
+
/**
|
|
32
|
+
* Wrap in a CookiesProvider. Defaults to true, with a fresh in-memory jar per
|
|
33
|
+
* render. Pass a Cookies instance to share or pre-seed one.
|
|
34
|
+
*/
|
|
35
|
+
cookies?: boolean | Cookies;
|
|
30
36
|
/** Wrap in ThemeProvider. Defaults to false. */
|
|
31
37
|
theme?: boolean;
|
|
32
38
|
/** Wrap in FrappeProvider with mock. Defaults to false. */
|
|
@@ -81,6 +87,15 @@ function createDefaultQueryClient(): QueryClient {
|
|
|
81
87
|
});
|
|
82
88
|
}
|
|
83
89
|
|
|
90
|
+
/** A cookie jar that never reads or writes document.cookie. */
|
|
91
|
+
export function createMemoryCookies(initial: Record<string, string> = {}): Cookies {
|
|
92
|
+
const jar = new Cookies(initial);
|
|
93
|
+
// universal-cookie re-parses document.cookie on every read when it can see a
|
|
94
|
+
// DOM, which would carry one test's cookies into the next.
|
|
95
|
+
Reflect.set(jar, "HAS_DOCUMENT_COOKIE", false);
|
|
96
|
+
return jar;
|
|
97
|
+
}
|
|
98
|
+
|
|
84
99
|
function enhanceRenderResult(result: RenderResult): EnhancedRenderResult {
|
|
85
100
|
const container = result.container;
|
|
86
101
|
return {
|
|
@@ -286,12 +301,16 @@ export function renderWithProviders(
|
|
|
286
301
|
const {
|
|
287
302
|
tamagui = true,
|
|
288
303
|
queryClient = true,
|
|
304
|
+
cookies = true,
|
|
289
305
|
theme: _theme = false,
|
|
290
306
|
frappe: _frappe = false,
|
|
291
307
|
keycloak: _keycloak = false,
|
|
292
308
|
...renderOptions
|
|
293
309
|
} = options;
|
|
294
310
|
|
|
311
|
+
const jar =
|
|
312
|
+
cookies === false ? undefined : typeof cookies === "object" ? cookies : createMemoryCookies();
|
|
313
|
+
|
|
295
314
|
function Wrapper({ children }: { children: ReactNode }) {
|
|
296
315
|
let content = children;
|
|
297
316
|
|
|
@@ -301,6 +320,10 @@ export function renderWithProviders(
|
|
|
301
320
|
content = <QueryClientProvider client={client}>{content}</QueryClientProvider>;
|
|
302
321
|
}
|
|
303
322
|
|
|
323
|
+
if (jar) {
|
|
324
|
+
content = <CookiesProvider cookies={jar}>{content}</CookiesProvider>;
|
|
325
|
+
}
|
|
326
|
+
|
|
304
327
|
// Tamagui provider (outermost standard provider)
|
|
305
328
|
if (tamagui) {
|
|
306
329
|
content = (
|
package/types/index.d.ts
CHANGED
|
@@ -14,11 +14,17 @@
|
|
|
14
14
|
import type { RenderOptions, RenderResult } from "@testing-library/react";
|
|
15
15
|
import type { ReactElement, ReactNode } from "react";
|
|
16
16
|
import { QueryClient } from "@tanstack/react-query";
|
|
17
|
+
import { Cookies } from "react-cookie";
|
|
17
18
|
export interface RenderWithProvidersOptions extends Omit<RenderOptions, "wrapper"> {
|
|
18
19
|
/** Wrap in TamaguiProvider. Defaults to true. */
|
|
19
20
|
tamagui?: boolean;
|
|
20
21
|
/** Wrap in QueryClientProvider. Defaults to true. Pass a QueryClient to use a custom one. */
|
|
21
22
|
queryClient?: boolean | QueryClient;
|
|
23
|
+
/**
|
|
24
|
+
* Wrap in a CookiesProvider. Defaults to true, with a fresh in-memory jar per
|
|
25
|
+
* render. Pass a Cookies instance to share or pre-seed one.
|
|
26
|
+
*/
|
|
27
|
+
cookies?: boolean | Cookies;
|
|
22
28
|
/** Wrap in ThemeProvider. Defaults to false. */
|
|
23
29
|
theme?: boolean;
|
|
24
30
|
/** Wrap in FrappeProvider with mock. Defaults to false. */
|
|
@@ -52,6 +58,8 @@ export interface EnhancedRenderResult extends RenderResult {
|
|
|
52
58
|
getLabel: (text: string) => Element | null | undefined;
|
|
53
59
|
getError: () => Element | null | undefined;
|
|
54
60
|
}
|
|
61
|
+
/** A cookie jar that never reads or writes document.cookie. */
|
|
62
|
+
export declare function createMemoryCookies(initial?: Record<string, string>): Cookies;
|
|
55
63
|
/**
|
|
56
64
|
* Standard test providers wrapper component.
|
|
57
65
|
* Wraps children in TamaguiProvider + YStack.
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAY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