vitest-native 0.1.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/LICENSE +21 -0
- package/README.md +456 -0
- package/dist/chunk-CjcI7cDX.mjs +15 -0
- package/dist/helpers.cjs +113 -0
- package/dist/helpers.d.cts +19 -0
- package/dist/helpers.d.mts +19 -0
- package/dist/helpers.mjs +108 -0
- package/dist/index-CJqS-y_M.d.cts +268 -0
- package/dist/index-h4vpIkQO.d.mts +266 -0
- package/dist/index.cjs +308 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.mts +14 -0
- package/dist/index.mjs +299 -0
- package/dist/preset-map-C5d8DSY7.cjs +21 -0
- package/dist/preset-map-CTAjv5aa.mjs +16 -0
- package/dist/presets-ArwboRy7.cjs +980 -0
- package/dist/presets-DgEuMxfn.mjs +896 -0
- package/dist/presets.cjs +9 -0
- package/dist/presets.d.cts +2 -0
- package/dist/presets.d.mts +2 -0
- package/dist/presets.mjs +2 -0
- package/dist/serializer.cjs +118 -0
- package/dist/serializer.d.cts +16 -0
- package/dist/serializer.d.mts +16 -0
- package/dist/serializer.mjs +117 -0
- package/dist/setup.cjs +1869 -0
- package/dist/setup.d.cts +1 -0
- package/dist/setup.d.mts +1 -0
- package/dist/setup.mjs +1869 -0
- package/package.json +124 -0
package/dist/presets.cjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_presets = require("./presets-ArwboRy7.cjs");
|
|
3
|
+
exports.asyncStorage = require_presets.asyncStorage;
|
|
4
|
+
exports.expo = require_presets.expo;
|
|
5
|
+
exports.gestureHandler = require_presets.gestureHandler;
|
|
6
|
+
exports.navigation = require_presets.navigation;
|
|
7
|
+
exports.reanimated = require_presets.reanimated;
|
|
8
|
+
exports.safeAreaContext = require_presets.safeAreaContext;
|
|
9
|
+
exports.screens = require_presets.screens;
|
package/dist/presets.mjs
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/serializer.ts
|
|
3
|
+
/**
|
|
4
|
+
* Vitest snapshot serializer for React Native components.
|
|
5
|
+
*
|
|
6
|
+
* Produces clean JSX-like output from React test renderer instances
|
|
7
|
+
* instead of raw createElement objects.
|
|
8
|
+
*
|
|
9
|
+
* Usage: expect.addSnapshotSerializer(serializer)
|
|
10
|
+
*/
|
|
11
|
+
/** Props that are React internals and should be omitted from snapshot output. */
|
|
12
|
+
const INTERNAL_PROPS = new Set([
|
|
13
|
+
"__reactFiber",
|
|
14
|
+
"__reactInternalInstance",
|
|
15
|
+
"__reactEvents",
|
|
16
|
+
"_owner",
|
|
17
|
+
"_store",
|
|
18
|
+
"_self",
|
|
19
|
+
"_source",
|
|
20
|
+
"ref",
|
|
21
|
+
"key"
|
|
22
|
+
]);
|
|
23
|
+
/** Returns true if `key` starts with any of the internal prefixes. */
|
|
24
|
+
function isInternalProp(key) {
|
|
25
|
+
if (INTERNAL_PROPS.has(key)) return true;
|
|
26
|
+
if (key.startsWith("__reactFiber$")) return true;
|
|
27
|
+
if (key.startsWith("__reactInternalInstance$")) return true;
|
|
28
|
+
if (key.startsWith("__reactEvents$")) return true;
|
|
29
|
+
if (key.startsWith("__reactProps$")) return true;
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Resolve the display name of a component type.
|
|
34
|
+
* Handles strings ("View"), functions (named or anonymous), and forwardRef/memo wrappers.
|
|
35
|
+
*/
|
|
36
|
+
function getTypeName(type) {
|
|
37
|
+
if (typeof type === "string") return type;
|
|
38
|
+
if (typeof type === "function") return type.displayName || type.name || "Unknown";
|
|
39
|
+
if (typeof type === "object" && type !== null) {
|
|
40
|
+
const obj = type;
|
|
41
|
+
if (obj.displayName) return obj.displayName;
|
|
42
|
+
if (obj.render) return obj.render.displayName || obj.render.name || "ForwardRef";
|
|
43
|
+
if (obj.type) return getTypeName(obj.type);
|
|
44
|
+
}
|
|
45
|
+
return "Unknown";
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Format a single prop value for snapshot display.
|
|
49
|
+
*/
|
|
50
|
+
function formatPropValue(value) {
|
|
51
|
+
if (typeof value === "string") return `"${value}"`;
|
|
52
|
+
if (typeof value === "number" || typeof value === "boolean") return `{${String(value)}}`;
|
|
53
|
+
if (typeof value === "function") return `{[Function ${value.name || "anonymous"}]}`;
|
|
54
|
+
if (value === null) return "{null}";
|
|
55
|
+
if (value === void 0) return "{undefined}";
|
|
56
|
+
if (Array.isArray(value)) return `{${JSON.stringify(value)}}`;
|
|
57
|
+
if (typeof value === "object") return `{${JSON.stringify(value)}}`;
|
|
58
|
+
return `{${String(value)}}`;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Determine whether a value looks like a React test instance (from react-test-renderer
|
|
62
|
+
* or @testing-library/react-native).
|
|
63
|
+
*/
|
|
64
|
+
function isReactTestInstance(val) {
|
|
65
|
+
if (val == null || typeof val !== "object") return false;
|
|
66
|
+
const obj = val;
|
|
67
|
+
if ("type" in obj && "props" in obj && "children" in obj) return true;
|
|
68
|
+
if (obj.$$typeof && "type" in obj && "props" in obj) return true;
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
const serializer = {
|
|
72
|
+
test(val) {
|
|
73
|
+
return isReactTestInstance(val);
|
|
74
|
+
},
|
|
75
|
+
serialize(val, config, indentation, depth, refs, printer) {
|
|
76
|
+
if (depth > (config.maxDepth ?? 10)) return `${indentation}<...>`;
|
|
77
|
+
const typeName = getTypeName(val.type);
|
|
78
|
+
const nextIndentation = indentation + (config.indent ?? " ");
|
|
79
|
+
const props = val.props ?? {};
|
|
80
|
+
const propKeys = Object.keys(props).filter((key) => key !== "children" && !isInternalProp(key));
|
|
81
|
+
let children = [];
|
|
82
|
+
if (Array.isArray(val.children)) children = val.children.filter((c) => c != null);
|
|
83
|
+
else if (val.children != null) children = [val.children];
|
|
84
|
+
else if (props.children != null) if (Array.isArray(props.children)) children = props.children.filter((c) => c != null);
|
|
85
|
+
else children = [props.children];
|
|
86
|
+
let result = `${indentation}<${typeName}`;
|
|
87
|
+
if (propKeys.length > 0) for (const key of propKeys.sort()) {
|
|
88
|
+
const value = props[key];
|
|
89
|
+
if (typeof value === "boolean" && value === true) result += `\n${nextIndentation}${key}`;
|
|
90
|
+
else result += `\n${nextIndentation}${key}=${formatPropValue(value)}`;
|
|
91
|
+
}
|
|
92
|
+
if (children.length === 0) {
|
|
93
|
+
if (propKeys.length > 0) result += `\n${indentation}/>`;
|
|
94
|
+
else result += " />";
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
if (children.length === 1 && typeof children[0] === "string") {
|
|
98
|
+
if (propKeys.length > 0) result += `\n${indentation}>`;
|
|
99
|
+
else result += ">";
|
|
100
|
+
result += `\n${nextIndentation}${children[0]}`;
|
|
101
|
+
result += `\n${indentation}</${typeName}>`;
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
if (propKeys.length > 0) result += `\n${indentation}>`;
|
|
105
|
+
else result += ">";
|
|
106
|
+
for (const child of children) {
|
|
107
|
+
if (child == null) continue;
|
|
108
|
+
if (typeof child === "string") result += `\n${nextIndentation}${child}`;
|
|
109
|
+
else if (typeof child === "number") result += `\n${nextIndentation}${String(child)}`;
|
|
110
|
+
else if (isReactTestInstance(child)) result += "\n" + printer(child, config, nextIndentation, depth + 1, refs);
|
|
111
|
+
else result += "\n" + nextIndentation + printer(child, config, nextIndentation, depth + 1, refs);
|
|
112
|
+
}
|
|
113
|
+
result += `\n${indentation}</${typeName}>`;
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
//#endregion
|
|
118
|
+
exports.serializer = serializer;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/serializer.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Vitest snapshot serializer for React Native components.
|
|
4
|
+
*
|
|
5
|
+
* Produces clean JSX-like output from React test renderer instances
|
|
6
|
+
* instead of raw createElement objects.
|
|
7
|
+
*
|
|
8
|
+
* Usage: expect.addSnapshotSerializer(serializer)
|
|
9
|
+
*/
|
|
10
|
+
interface SnapshotSerializer {
|
|
11
|
+
serialize(val: any, config: any, indentation: string, depth: number, refs: any[], printer: Function): string;
|
|
12
|
+
test(val: any): boolean;
|
|
13
|
+
}
|
|
14
|
+
declare const serializer: SnapshotSerializer;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { SnapshotSerializer, serializer };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/serializer.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Vitest snapshot serializer for React Native components.
|
|
4
|
+
*
|
|
5
|
+
* Produces clean JSX-like output from React test renderer instances
|
|
6
|
+
* instead of raw createElement objects.
|
|
7
|
+
*
|
|
8
|
+
* Usage: expect.addSnapshotSerializer(serializer)
|
|
9
|
+
*/
|
|
10
|
+
interface SnapshotSerializer {
|
|
11
|
+
serialize(val: any, config: any, indentation: string, depth: number, refs: any[], printer: Function): string;
|
|
12
|
+
test(val: any): boolean;
|
|
13
|
+
}
|
|
14
|
+
declare const serializer: SnapshotSerializer;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { SnapshotSerializer, serializer };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
//#region src/serializer.ts
|
|
2
|
+
/**
|
|
3
|
+
* Vitest snapshot serializer for React Native components.
|
|
4
|
+
*
|
|
5
|
+
* Produces clean JSX-like output from React test renderer instances
|
|
6
|
+
* instead of raw createElement objects.
|
|
7
|
+
*
|
|
8
|
+
* Usage: expect.addSnapshotSerializer(serializer)
|
|
9
|
+
*/
|
|
10
|
+
/** Props that are React internals and should be omitted from snapshot output. */
|
|
11
|
+
const INTERNAL_PROPS = new Set([
|
|
12
|
+
"__reactFiber",
|
|
13
|
+
"__reactInternalInstance",
|
|
14
|
+
"__reactEvents",
|
|
15
|
+
"_owner",
|
|
16
|
+
"_store",
|
|
17
|
+
"_self",
|
|
18
|
+
"_source",
|
|
19
|
+
"ref",
|
|
20
|
+
"key"
|
|
21
|
+
]);
|
|
22
|
+
/** Returns true if `key` starts with any of the internal prefixes. */
|
|
23
|
+
function isInternalProp(key) {
|
|
24
|
+
if (INTERNAL_PROPS.has(key)) return true;
|
|
25
|
+
if (key.startsWith("__reactFiber$")) return true;
|
|
26
|
+
if (key.startsWith("__reactInternalInstance$")) return true;
|
|
27
|
+
if (key.startsWith("__reactEvents$")) return true;
|
|
28
|
+
if (key.startsWith("__reactProps$")) return true;
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resolve the display name of a component type.
|
|
33
|
+
* Handles strings ("View"), functions (named or anonymous), and forwardRef/memo wrappers.
|
|
34
|
+
*/
|
|
35
|
+
function getTypeName(type) {
|
|
36
|
+
if (typeof type === "string") return type;
|
|
37
|
+
if (typeof type === "function") return type.displayName || type.name || "Unknown";
|
|
38
|
+
if (typeof type === "object" && type !== null) {
|
|
39
|
+
const obj = type;
|
|
40
|
+
if (obj.displayName) return obj.displayName;
|
|
41
|
+
if (obj.render) return obj.render.displayName || obj.render.name || "ForwardRef";
|
|
42
|
+
if (obj.type) return getTypeName(obj.type);
|
|
43
|
+
}
|
|
44
|
+
return "Unknown";
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Format a single prop value for snapshot display.
|
|
48
|
+
*/
|
|
49
|
+
function formatPropValue(value) {
|
|
50
|
+
if (typeof value === "string") return `"${value}"`;
|
|
51
|
+
if (typeof value === "number" || typeof value === "boolean") return `{${String(value)}}`;
|
|
52
|
+
if (typeof value === "function") return `{[Function ${value.name || "anonymous"}]}`;
|
|
53
|
+
if (value === null) return "{null}";
|
|
54
|
+
if (value === void 0) return "{undefined}";
|
|
55
|
+
if (Array.isArray(value)) return `{${JSON.stringify(value)}}`;
|
|
56
|
+
if (typeof value === "object") return `{${JSON.stringify(value)}}`;
|
|
57
|
+
return `{${String(value)}}`;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Determine whether a value looks like a React test instance (from react-test-renderer
|
|
61
|
+
* or @testing-library/react-native).
|
|
62
|
+
*/
|
|
63
|
+
function isReactTestInstance(val) {
|
|
64
|
+
if (val == null || typeof val !== "object") return false;
|
|
65
|
+
const obj = val;
|
|
66
|
+
if ("type" in obj && "props" in obj && "children" in obj) return true;
|
|
67
|
+
if (obj.$$typeof && "type" in obj && "props" in obj) return true;
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const serializer = {
|
|
71
|
+
test(val) {
|
|
72
|
+
return isReactTestInstance(val);
|
|
73
|
+
},
|
|
74
|
+
serialize(val, config, indentation, depth, refs, printer) {
|
|
75
|
+
if (depth > (config.maxDepth ?? 10)) return `${indentation}<...>`;
|
|
76
|
+
const typeName = getTypeName(val.type);
|
|
77
|
+
const nextIndentation = indentation + (config.indent ?? " ");
|
|
78
|
+
const props = val.props ?? {};
|
|
79
|
+
const propKeys = Object.keys(props).filter((key) => key !== "children" && !isInternalProp(key));
|
|
80
|
+
let children = [];
|
|
81
|
+
if (Array.isArray(val.children)) children = val.children.filter((c) => c != null);
|
|
82
|
+
else if (val.children != null) children = [val.children];
|
|
83
|
+
else if (props.children != null) if (Array.isArray(props.children)) children = props.children.filter((c) => c != null);
|
|
84
|
+
else children = [props.children];
|
|
85
|
+
let result = `${indentation}<${typeName}`;
|
|
86
|
+
if (propKeys.length > 0) for (const key of propKeys.sort()) {
|
|
87
|
+
const value = props[key];
|
|
88
|
+
if (typeof value === "boolean" && value === true) result += `\n${nextIndentation}${key}`;
|
|
89
|
+
else result += `\n${nextIndentation}${key}=${formatPropValue(value)}`;
|
|
90
|
+
}
|
|
91
|
+
if (children.length === 0) {
|
|
92
|
+
if (propKeys.length > 0) result += `\n${indentation}/>`;
|
|
93
|
+
else result += " />";
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
if (children.length === 1 && typeof children[0] === "string") {
|
|
97
|
+
if (propKeys.length > 0) result += `\n${indentation}>`;
|
|
98
|
+
else result += ">";
|
|
99
|
+
result += `\n${nextIndentation}${children[0]}`;
|
|
100
|
+
result += `\n${indentation}</${typeName}>`;
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
if (propKeys.length > 0) result += `\n${indentation}>`;
|
|
104
|
+
else result += ">";
|
|
105
|
+
for (const child of children) {
|
|
106
|
+
if (child == null) continue;
|
|
107
|
+
if (typeof child === "string") result += `\n${nextIndentation}${child}`;
|
|
108
|
+
else if (typeof child === "number") result += `\n${nextIndentation}${String(child)}`;
|
|
109
|
+
else if (isReactTestInstance(child)) result += "\n" + printer(child, config, nextIndentation, depth + 1, refs);
|
|
110
|
+
else result += "\n" + nextIndentation + printer(child, config, nextIndentation, depth + 1, refs);
|
|
111
|
+
}
|
|
112
|
+
result += `\n${indentation}</${typeName}>`;
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
//#endregion
|
|
117
|
+
export { serializer };
|