vitest-auto-spy 1.9.0 → 1.9.2
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/README.md +10 -7
- package/assets/one-api-three-runtimes.svg +79 -27
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -5,13 +5,16 @@
|
|
|
5
5
|
**Auto-generate fully-typed test spies from a class — across any Vitest-compatible runtime and framework.**
|
|
6
6
|
|
|
7
7
|
The only auto-spy library that reads a **class** and gives a **fully-typed** spy of every method
|
|
8
|
-
with **return-type-aware** helpers
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
[
|
|
14
|
-
[
|
|
8
|
+
with **return-type-aware** helpers — `resolveWith` / `rejectWith` for `Promise`s, `nextWith` /
|
|
9
|
+
`throwWith` for RxJS `Observable`s, and `calledWith` / `mustBeCalledWith` for argument matching. Or
|
|
10
|
+
skip the class entirely and mock straight from a **type or interface** with `createAutoMock<T>()` and
|
|
11
|
+
recursive `mockDeep<T>()`. Runs on **Vitest**, **Bun** (`bun:test`) and **`node:test`** behind one
|
|
12
|
+
identical API, with **RxJS** spies and **Angular / NestJS / React / Vue·Pinia / Svelte** recipes
|
|
13
|
+
([availability](#availability)). A drop-in replacement for
|
|
14
|
+
[`jest-auto-spies`](https://www.npmjs.com/package/jest-auto-spies) — same API.
|
|
15
|
+
|
|
16
|
+
[](https://www.npmjs.com/package/vitest-auto-spy)
|
|
17
|
+
[](https://www.npmjs.com/package/vitest-auto-spy)
|
|
15
18
|
[](https://github.com/ASDAlexey/vitest-auto-spy/actions/workflows/ci.yml)
|
|
16
19
|
[](https://bundlephobia.com/package/vitest-auto-spy)
|
|
17
20
|
[](https://www.npmjs.com/package/vitest-auto-spy)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="860" height="384" viewBox="0 0 860 384" font-family="ui-sans-serif, -apple-system, Segoe UI, Roboto, sans-serif" role="img" aria-label="createSpyFromClass(UserService) returns a fully-typed Spy of UserService whose methods carry resolveWith / nextWith / calledWith helpers — one API across Vitest, Bun and node:test">
|
|
2
2
|
<defs>
|
|
3
3
|
<linearGradient id="bg" x1="0" y1="0" x2="1" y2="1">
|
|
4
4
|
<stop offset="0" stop-color="#ffffff"/>
|
|
@@ -13,57 +13,109 @@
|
|
|
13
13
|
<stop offset="1" stop-color="#1f6feb"/>
|
|
14
14
|
</linearGradient>
|
|
15
15
|
<linearGradient id="arrow" x1="0" y1="0" x2="1" y2="0">
|
|
16
|
-
<stop offset="0" stop-color="#
|
|
16
|
+
<stop offset="0" stop-color="#5a91e6"/>
|
|
17
17
|
<stop offset="1" stop-color="#1f6feb"/>
|
|
18
18
|
</linearGradient>
|
|
19
|
+
<linearGradient id="vitest" x1="0" y1="0" x2="0" y2="1">
|
|
20
|
+
<stop offset="0" stop-color="#FCC72B"/>
|
|
21
|
+
<stop offset="1" stop-color="#729B1B"/>
|
|
22
|
+
</linearGradient>
|
|
23
|
+
<linearGradient id="node" x1="0" y1="0" x2="0" y2="1">
|
|
24
|
+
<stop offset="0" stop-color="#83CD29"/>
|
|
25
|
+
<stop offset="1" stop-color="#3C873A"/>
|
|
26
|
+
</linearGradient>
|
|
19
27
|
<filter id="shadow" x="-20%" y="-20%" width="140%" height="160%">
|
|
20
28
|
<feDropShadow dx="0" dy="6" stdDeviation="10" flood-color="#1f2a44" flood-opacity="0.14"/>
|
|
21
29
|
</filter>
|
|
22
30
|
<style>
|
|
23
31
|
@media (prefers-color-scheme: dark) {
|
|
24
32
|
.bg { fill: #0d1117; }
|
|
25
|
-
.card { fill: #161b22; stroke: #30363d; }
|
|
33
|
+
.card { fill: #161b22; stroke: #30363d; filter: none; }
|
|
26
34
|
.title { fill: #e6edf3; }
|
|
27
35
|
.sub { fill: #8b949e; }
|
|
28
|
-
.code { fill: #e6edf3; }
|
|
29
36
|
.fn { fill: #d2a8ff; }
|
|
30
37
|
.type { fill: #7ee787; }
|
|
31
38
|
.punct { fill: #8b949e; }
|
|
39
|
+
.method { fill: #79c0ff; }
|
|
40
|
+
.sep { fill: #6e7681; }
|
|
41
|
+
.div { stroke: #21262d; }
|
|
42
|
+
.tag { fill: #21262d; stroke: #30363d; }
|
|
43
|
+
.tagtx { fill: #8b949e; }
|
|
32
44
|
.arrow { stroke: url(#arrow); }
|
|
45
|
+
.bR { fill: #3d1e00; stroke: #bc4c00; } .bRt { fill: #ffa657; }
|
|
46
|
+
.bN { fill: #3d1327; stroke: #bf3989; } .bNt { fill: #f778ba; }
|
|
47
|
+
.bC { fill: #0a2a43; stroke: #1f6feb; } .bCt { fill: #79c0ff; }
|
|
48
|
+
.cV { fill: #1b2410; stroke: #729B1B; } .cVt { fill: #b7d75a; }
|
|
49
|
+
.cB { fill: #3d1327; stroke: #bf3989; } .cBt { fill: #f778ba; }
|
|
50
|
+
.cN { fill: #0b2e13; stroke: #3fb950; } .cNt { fill: #7ee787; }
|
|
33
51
|
}
|
|
34
52
|
</style>
|
|
35
53
|
</defs>
|
|
36
54
|
|
|
37
|
-
<rect class="bg" width="
|
|
55
|
+
<rect class="bg" width="860" height="384" fill="url(#bg)" rx="20"/>
|
|
56
|
+
|
|
57
|
+
<!-- header -->
|
|
58
|
+
<text class="title" x="40" y="54" font-size="30" font-weight="700" fill="#0d1117">vitest-auto-spy</text>
|
|
59
|
+
<rect x="40" y="66" width="92" height="5" rx="2.5" fill="url(#brand)"/>
|
|
60
|
+
<text class="sub" x="40" y="90" font-size="15" fill="#57606a">One class-based API. Every Vitest-compatible runtime.</text>
|
|
38
61
|
|
|
39
|
-
|
|
40
|
-
<
|
|
62
|
+
<!-- source: the class + call (single line) -->
|
|
63
|
+
<rect class="card" x="40" y="100" width="320" height="168" rx="16" fill="url(#card)" stroke="#d0d7de" filter="url(#shadow)"/>
|
|
64
|
+
<rect class="tag" x="64" y="138" width="56" height="24" rx="12" fill="#eef1f6" stroke="#d0d7de"/>
|
|
65
|
+
<text class="tagtx" x="92" y="154" font-size="12" font-weight="600" text-anchor="middle" fill="#6e7781">class</text>
|
|
66
|
+
<text x="64" y="204" font-size="13.5" font-family="ui-monospace, SFMono-Regular, Menlo, monospace"><tspan class="fn" fill="#8250df">createSpyFromClass</tspan><tspan class="punct" fill="#6e7781">(</tspan><tspan class="type" fill="#0550ae">UserService</tspan><tspan class="punct" fill="#6e7781">)</tspan></text>
|
|
67
|
+
<text class="sub" x="64" y="230" font-size="12.5" fill="#57606a">reads every method — no hand-written spies</text>
|
|
41
68
|
|
|
42
|
-
<!--
|
|
43
|
-
<
|
|
44
|
-
<
|
|
69
|
+
<!-- arrow (nudged 5px left) -->
|
|
70
|
+
<line class="arrow" x1="363" y1="184" x2="377" y2="184" stroke="url(#arrow)" stroke-width="3" stroke-linecap="round"/>
|
|
71
|
+
<polygon points="377,177 387,184 377,191" fill="#1f6feb"/>
|
|
45
72
|
|
|
46
|
-
<!--
|
|
47
|
-
<
|
|
48
|
-
<
|
|
73
|
+
<!-- fully-typed spy with per-method helpers -->
|
|
74
|
+
<rect class="card" x="400" y="100" width="420" height="168" rx="16" fill="url(#card)" stroke="#d0d7de" filter="url(#shadow)"/>
|
|
75
|
+
<text class="title" x="424" y="140" font-size="17" font-weight="700" fill="#0d1117">Spy<UserService></text>
|
|
76
|
+
<rect class="tag" x="700" y="122" width="96" height="24" rx="12" fill="#eef1f6" stroke="#d0d7de"/>
|
|
77
|
+
<text class="tagtx" x="748" y="138" font-size="12" font-weight="600" text-anchor="middle" fill="#6e7781">fully typed</text>
|
|
78
|
+
<line class="div" x1="424" y1="156" x2="796" y2="156" stroke="#e5e9f0" stroke-width="1"/>
|
|
49
79
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
80
|
+
<g font-family="ui-monospace, SFMono-Regular, Menlo, monospace" font-size="14">
|
|
81
|
+
<text class="method" x="424" y="188" fill="#0953a8">getUser()</text>
|
|
82
|
+
<text class="sep" x="600" y="188" font-size="14" text-anchor="middle" fill="#8c959f">›</text>
|
|
83
|
+
<rect class="bR" x="628" y="173" width="168" height="22" rx="11" fill="#fff1e5" stroke="#f0a868"/>
|
|
84
|
+
<text class="bRt" x="712" y="188" font-size="12.5" font-weight="600" text-anchor="middle" fill="#bc4c00">resolveWith</text>
|
|
85
|
+
|
|
86
|
+
<text class="method" x="424" y="214" fill="#0953a8">items$</text>
|
|
87
|
+
<text class="sep" x="600" y="214" font-size="14" text-anchor="middle" fill="#8c959f">›</text>
|
|
88
|
+
<rect class="bN" x="628" y="199" width="168" height="22" rx="11" fill="#ffeff7" stroke="#f472b6"/>
|
|
89
|
+
<text class="bNt" x="712" y="214" font-size="12.5" font-weight="600" text-anchor="middle" fill="#bf3989">nextWith</text>
|
|
90
|
+
|
|
91
|
+
<text class="method" x="424" y="240" fill="#0953a8">save()</text>
|
|
92
|
+
<text class="sep" x="600" y="240" font-size="14" text-anchor="middle" fill="#8c959f">›</text>
|
|
93
|
+
<rect class="bC" x="628" y="225" width="168" height="22" rx="11" fill="#ddf4ff" stroke="#54aeff"/>
|
|
94
|
+
<text class="bCt" x="712" y="240" font-size="12.5" font-weight="600" text-anchor="middle" fill="#0969da">calledWith</text>
|
|
95
|
+
</g>
|
|
54
96
|
|
|
55
|
-
<!-- runtime chips -->
|
|
97
|
+
<!-- runtime chips with brand marks -->
|
|
56
98
|
<g>
|
|
57
|
-
|
|
58
|
-
<
|
|
59
|
-
<
|
|
99
|
+
<!-- Vitest -->
|
|
100
|
+
<rect class="cV" x="40" y="312" width="240" height="48" rx="24" fill="#f4f9e6" stroke="#a9c14f"/>
|
|
101
|
+
<g transform="translate(58,324)"><path d="M13 0 L3 14 L10 14 L8 24 L20 9 L12 9 Z" fill="url(#vitest)"/></g>
|
|
102
|
+
<text class="cVt" x="172" y="341" font-size="17" font-weight="600" text-anchor="middle" fill="#5c7a12">Vitest</text>
|
|
60
103
|
|
|
61
|
-
|
|
62
|
-
<
|
|
63
|
-
<
|
|
104
|
+
<!-- Bun -->
|
|
105
|
+
<rect class="cB" x="300" y="312" width="240" height="48" rx="24" fill="#fbe9f4" stroke="#f472b6"/>
|
|
106
|
+
<g transform="translate(316,324)">
|
|
107
|
+
<rect x="1" y="2" width="24" height="21" rx="10.5" fill="#f7ede1" stroke="#e2d3c0" stroke-width="1"/>
|
|
108
|
+
<ellipse cx="9" cy="12" rx="1.5" ry="2.3" fill="#20232a"/>
|
|
109
|
+
<ellipse cx="17" cy="12" rx="1.5" ry="2.3" fill="#20232a"/>
|
|
110
|
+
<circle cx="6" cy="15.5" r="2" fill="#f9a8d4"/>
|
|
111
|
+
<circle cx="20" cy="15.5" r="2" fill="#f9a8d4"/>
|
|
112
|
+
<path d="M11 16 Q13 18 15 16" stroke="#20232a" stroke-width="1" fill="none" stroke-linecap="round"/>
|
|
113
|
+
</g>
|
|
114
|
+
<text class="cBt" x="432" y="341" font-size="17" font-weight="600" text-anchor="middle" fill="#be185d">Bun  (bun:test)</text>
|
|
64
115
|
|
|
65
|
-
|
|
66
|
-
<
|
|
67
|
-
<
|
|
116
|
+
<!-- node:test -->
|
|
117
|
+
<rect class="cN" x="560" y="312" width="240" height="48" rx="24" fill="#e6f4ea" stroke="#5aa469"/>
|
|
118
|
+
<g transform="translate(578,324)"><path d="M12 0 L22.39 6 L22.39 18 L12 24 L1.61 18 L1.61 6 Z" fill="url(#node)" stroke="#3C873A" stroke-width="0.5"/></g>
|
|
119
|
+
<text class="cNt" x="694" y="341" font-size="17" font-weight="600" text-anchor="middle" fill="#2f7d32">node:test</text>
|
|
68
120
|
</g>
|
|
69
121
|
</svg>
|
package/package.json
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-auto-spy",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2",
|
|
4
4
|
"description": "Auto-generate fully-typed test spies from a class — across Vitest, Bun and node:test, with NestJS/React/Vue/Svelte/Angular recipes. Drop-in replacement for jest-auto-spies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"auto-mock",
|
|
7
|
+
"automock",
|
|
7
8
|
"class-mock",
|
|
8
9
|
"typed-mock",
|
|
10
|
+
"type-mock",
|
|
11
|
+
"interface-mock",
|
|
12
|
+
"deep-mock",
|
|
13
|
+
"createautomock",
|
|
14
|
+
"mockdeep",
|
|
9
15
|
"auto-spy",
|
|
10
16
|
"auto-spies",
|
|
17
|
+
"spy-from-class",
|
|
11
18
|
"vitest-mock",
|
|
12
19
|
"sinon-alternative",
|
|
13
20
|
"jest-auto-spies",
|
|
@@ -18,6 +25,7 @@
|
|
|
18
25
|
"nestjs",
|
|
19
26
|
"react",
|
|
20
27
|
"vue",
|
|
28
|
+
"pinia",
|
|
21
29
|
"svelte",
|
|
22
30
|
"angular",
|
|
23
31
|
"testing",
|