storybook 9.0.0-alpha.2 → 9.0.0-alpha.4
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 +1 -1
- package/dist/actions/decorator.d.ts +6 -0
- package/dist/actions/decorator.js +139 -0
- package/dist/actions/index.cjs +127 -0
- package/dist/actions/index.d.ts +105 -0
- package/dist/actions/index.js +112 -0
- package/dist/actions/manager.js +1196 -0
- package/dist/actions/preview.cjs +165 -0
- package/dist/actions/preview.d.ts +55 -0
- package/dist/actions/preview.js +156 -0
- package/dist/bin/index.cjs +63 -65
- package/dist/bin/index.js +63 -65
- package/dist/channels/index.cjs +209 -234
- package/dist/channels/index.js +304 -308
- package/dist/cli/bin/index.cjs +409 -409
- package/dist/cli/bin/index.js +414 -414
- package/dist/cli/index.cjs +1 -1
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +1 -1
- package/dist/client-logger/index.cjs +56 -88
- package/dist/client-logger/index.js +41 -47
- package/dist/common/index.cjs +148 -148
- package/dist/common/index.d.ts +1 -5
- package/dist/common/index.js +171 -171
- package/dist/components/index.cjs +9413 -11578
- package/dist/components/index.d.ts +92 -92
- package/dist/components/index.js +6768 -7544
- package/dist/core-events/index.d.ts +138 -25
- package/dist/core-server/index.cjs +5244 -5270
- package/dist/core-server/index.d.ts +1 -1
- package/dist/core-server/index.js +5356 -5380
- package/dist/core-server/presets/common-manager.js +11 -19
- package/dist/core-server/presets/common-preset.cjs +243 -242
- package/dist/core-server/presets/common-preset.js +379 -378
- package/dist/csf/index.cjs +76 -120
- package/dist/csf/index.d.ts +1 -3
- package/dist/csf/index.js +69 -113
- package/dist/docs-tools/index.cjs +1 -1
- package/dist/docs-tools/index.d.ts +2 -2
- package/dist/docs-tools/index.js +1 -1
- package/dist/instrumenter/index.cjs +1260 -1289
- package/dist/instrumenter/index.js +1344 -1348
- package/dist/manager/globals-module-info.cjs +272 -135
- package/dist/manager/globals-module-info.d.ts +1 -1
- package/dist/manager/globals-module-info.js +257 -120
- package/dist/manager/globals-runtime.js +59553 -22373
- package/dist/manager/globals.cjs +23 -19
- package/dist/manager/globals.d.ts +8 -5
- package/dist/manager/globals.js +10 -6
- package/dist/manager/runtime.js +129 -129
- package/dist/manager-api/index.cjs +1184 -1209
- package/dist/manager-api/index.d.ts +3 -3
- package/dist/manager-api/index.js +1012 -1012
- package/dist/preview/globals.cjs +21 -17
- package/dist/preview/globals.d.ts +4 -1
- package/dist/preview/globals.js +6 -2
- package/dist/preview/runtime.js +43946 -6548
- package/dist/preview-api/index.cjs +1245 -1243
- package/dist/preview-api/index.d.ts +105 -61
- package/dist/preview-api/index.js +1311 -1273
- package/dist/preview-errors.cjs +1 -1
- package/dist/preview-errors.js +1 -1
- package/dist/router/index.cjs +847 -871
- package/dist/router/index.js +193 -199
- package/dist/test/index.cjs +34778 -0
- package/dist/test/index.d.ts +186 -0
- package/dist/test/index.js +32916 -0
- package/dist/test/preview.cjs +15870 -0
- package/dist/test/preview.d.ts +54 -0
- package/dist/test/preview.js +14441 -0
- package/dist/test/spy.cjs +258 -0
- package/dist/test/spy.d.ts +66 -0
- package/dist/test/spy.js +240 -0
- package/dist/theming/create.cjs +79 -2269
- package/dist/theming/create.js +67 -841
- package/dist/theming/index.cjs +1065 -3232
- package/dist/theming/index.js +951 -1719
- package/dist/types/index.d.ts +242 -242
- package/package.json +155 -3
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var x = Object.defineProperty;
|
|
3
|
+
var _ = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var N = Object.getOwnPropertyNames;
|
|
5
|
+
var K = Object.prototype.hasOwnProperty;
|
|
6
|
+
var n = (t, e) => x(t, "name", { value: e, configurable: !0 });
|
|
7
|
+
var U = (t, e) => {
|
|
8
|
+
for (var r in e)
|
|
9
|
+
x(t, r, { get: e[r], enumerable: !0 });
|
|
10
|
+
}, W = (t, e, r, l) => {
|
|
11
|
+
if (e && typeof e == "object" || typeof e == "function")
|
|
12
|
+
for (let o of N(e))
|
|
13
|
+
!K.call(t, o) && o !== r && x(t, o, { get: () => e[o], enumerable: !(l = _(e, o)) || l.enumerable });
|
|
14
|
+
return t;
|
|
15
|
+
};
|
|
16
|
+
var Y = (t) => W(x({}, "__esModule", { value: !0 }), t);
|
|
17
|
+
|
|
18
|
+
// src/test/spy.ts
|
|
19
|
+
var oe = {};
|
|
20
|
+
U(oe, {
|
|
21
|
+
clearAllMocks: () => Z,
|
|
22
|
+
fn: () => X,
|
|
23
|
+
isMockFunction: () => E,
|
|
24
|
+
mocked: () => ne,
|
|
25
|
+
mocks: () => T,
|
|
26
|
+
onMockCall: () => J,
|
|
27
|
+
resetAllMocks: () => ee,
|
|
28
|
+
restoreAllMocks: () => te,
|
|
29
|
+
spyOn: () => Q
|
|
30
|
+
});
|
|
31
|
+
module.exports = Y(oe);
|
|
32
|
+
|
|
33
|
+
// ../node_modules/tinyspy/dist/index.js
|
|
34
|
+
function O(t, e) {
|
|
35
|
+
if (!t)
|
|
36
|
+
throw new Error(e);
|
|
37
|
+
}
|
|
38
|
+
n(O, "d");
|
|
39
|
+
function g(t, e) {
|
|
40
|
+
return typeof e === t;
|
|
41
|
+
}
|
|
42
|
+
n(g, "y");
|
|
43
|
+
function $(t) {
|
|
44
|
+
return t instanceof Promise;
|
|
45
|
+
}
|
|
46
|
+
n($, "w");
|
|
47
|
+
function w(t, e, r) {
|
|
48
|
+
Object.defineProperty(t, e, r);
|
|
49
|
+
}
|
|
50
|
+
n(w, "f");
|
|
51
|
+
function M(t, e, r) {
|
|
52
|
+
Object.defineProperty(t, e, { value: r });
|
|
53
|
+
}
|
|
54
|
+
n(M, "l");
|
|
55
|
+
var v = Symbol.for("tinyspy:spy"), q = /* @__PURE__ */ new Set(), z = /* @__PURE__ */ n((t) => {
|
|
56
|
+
t.called = !1, t.callCount = 0, t.calls = [], t.results = [], t.resolves = [], t.next = [];
|
|
57
|
+
}, "P"), B = /* @__PURE__ */ n((t) => (w(t, v, { value: { reset: /* @__PURE__ */ n(() => z(t[v]), "reset") } }), t[v]), "K"), h = /* @__PURE__ */ n(
|
|
58
|
+
(t) => t[v] || B(t), "T");
|
|
59
|
+
function G(t) {
|
|
60
|
+
O(
|
|
61
|
+
g("function", t) || g("undefined", t),
|
|
62
|
+
"cannot spy on a non-function value"
|
|
63
|
+
);
|
|
64
|
+
let e = /* @__PURE__ */ n(function(...l) {
|
|
65
|
+
let o = h(e);
|
|
66
|
+
o.called = !0, o.callCount++, o.calls.push(l);
|
|
67
|
+
let p = o.next.shift();
|
|
68
|
+
if (p) {
|
|
69
|
+
o.results.push(p);
|
|
70
|
+
let [i, f] = p;
|
|
71
|
+
if (i === "ok")
|
|
72
|
+
return f;
|
|
73
|
+
throw f;
|
|
74
|
+
}
|
|
75
|
+
let c, y = "ok", a = o.results.length;
|
|
76
|
+
if (o.impl)
|
|
77
|
+
try {
|
|
78
|
+
new.target ? c = Reflect.construct(o.impl, l, new.target) : c = o.impl.apply(this, l), y = "ok";
|
|
79
|
+
} catch (i) {
|
|
80
|
+
throw c = i, y = "error", o.results.push([y, i]), i;
|
|
81
|
+
}
|
|
82
|
+
let m = [y, c];
|
|
83
|
+
return $(c) && c.then(
|
|
84
|
+
(i) => o.resolves[a] = ["ok", i],
|
|
85
|
+
(i) => o.resolves[a] = ["error", i]
|
|
86
|
+
), o.results.push(m), c;
|
|
87
|
+
}, "t");
|
|
88
|
+
M(e, "_isMockFunction", !0), M(e, "length", t ? t.length : 0), M(e, "name", t && t.name || "spy");
|
|
89
|
+
let r = h(e);
|
|
90
|
+
return r.reset(), r.impl = t, e;
|
|
91
|
+
}
|
|
92
|
+
n(G, "m");
|
|
93
|
+
var C = /* @__PURE__ */ n((t, e) => Object.getOwnPropertyDescriptor(t, e), "k"), j = /* @__PURE__ */ n((t, e) => {
|
|
94
|
+
e != null && typeof e == "function" && e.prototype != null && Object.setPrototypeOf(t.prototype, e.prototype);
|
|
95
|
+
}, "O");
|
|
96
|
+
function R(t, e, r) {
|
|
97
|
+
O(
|
|
98
|
+
!g("undefined", t),
|
|
99
|
+
"spyOn could not find an object to spy upon"
|
|
100
|
+
), O(
|
|
101
|
+
g("object", t) || g("function", t),
|
|
102
|
+
"cannot spyOn on a primitive value"
|
|
103
|
+
);
|
|
104
|
+
let [l, o] = (() => {
|
|
105
|
+
if (!g("object", e))
|
|
106
|
+
return [e, "value"];
|
|
107
|
+
if ("getter" in e && "setter" in e)
|
|
108
|
+
throw new Error("cannot spy on both getter and setter");
|
|
109
|
+
if ("getter" in e)
|
|
110
|
+
return [e.getter, "get"];
|
|
111
|
+
if ("setter" in e)
|
|
112
|
+
return [e.setter, "set"];
|
|
113
|
+
throw new Error("specify getter or setter to spy on");
|
|
114
|
+
})(), p = C(t, l), c = Object.getPrototypeOf(t), y = c && C(c, l), a = p || y;
|
|
115
|
+
O(
|
|
116
|
+
a || l in t,
|
|
117
|
+
`${String(l)} does not exist`
|
|
118
|
+
);
|
|
119
|
+
let m = !1;
|
|
120
|
+
o === "value" && a && !a.value && a.get && (o = "get", m = !0, r = a.get());
|
|
121
|
+
let i;
|
|
122
|
+
a ? i = a[o] : o !== "value" ? i = /* @__PURE__ */ n(() => t[l], "o") : i = t[l];
|
|
123
|
+
let f = /* @__PURE__ */ n((k) => {
|
|
124
|
+
let { value: b, ...d } = a || {
|
|
125
|
+
configurable: !0,
|
|
126
|
+
writable: !0
|
|
127
|
+
};
|
|
128
|
+
o !== "value" && delete d.writable, d[o] = k, w(t, l, d);
|
|
129
|
+
}, "g"), I = /* @__PURE__ */ n(() => a ? w(t, l, a) : f(i), "b");
|
|
130
|
+
r || (r = i);
|
|
131
|
+
let s = G(r);
|
|
132
|
+
o === "value" && j(s, i);
|
|
133
|
+
let u = s[v];
|
|
134
|
+
return M(u, "restore", I), M(u, "getOriginal", () => m ? i() : i), M(u, "willCall", (k) => (u.impl = k, s)), f(
|
|
135
|
+
m ? () => (j(s, r), s) : s
|
|
136
|
+
), q.add(s), s;
|
|
137
|
+
}
|
|
138
|
+
n(R, "C");
|
|
139
|
+
|
|
140
|
+
// ../node_modules/@vitest/spy/dist/index.js
|
|
141
|
+
var T = /* @__PURE__ */ new Set();
|
|
142
|
+
function E(t) {
|
|
143
|
+
return typeof t == "function" && "_isMockFunction" in t && t._isMockFunction;
|
|
144
|
+
}
|
|
145
|
+
n(E, "isMockFunction");
|
|
146
|
+
function V(t, e, r) {
|
|
147
|
+
let o = r ? { [{
|
|
148
|
+
get: "getter",
|
|
149
|
+
set: "setter"
|
|
150
|
+
}[r]]: e } : e, p = R(t, o);
|
|
151
|
+
return D(p);
|
|
152
|
+
}
|
|
153
|
+
n(V, "spyOn");
|
|
154
|
+
var H = 0;
|
|
155
|
+
function D(t) {
|
|
156
|
+
let e = t, r, l = [], o = [], p = [], c = h(t), y = {
|
|
157
|
+
get calls() {
|
|
158
|
+
return c.calls;
|
|
159
|
+
},
|
|
160
|
+
get contexts() {
|
|
161
|
+
return o;
|
|
162
|
+
},
|
|
163
|
+
get instances() {
|
|
164
|
+
return l;
|
|
165
|
+
},
|
|
166
|
+
get invocationCallOrder() {
|
|
167
|
+
return p;
|
|
168
|
+
},
|
|
169
|
+
get results() {
|
|
170
|
+
return c.results.map(([s, u]) => ({ type: s === "error" ? "throw" : "return", value: u }));
|
|
171
|
+
},
|
|
172
|
+
get settledResults() {
|
|
173
|
+
return c.resolves.map(([s, u]) => ({ type: s === "error" ? "rejected" : "fulfilled", value: u }));
|
|
174
|
+
},
|
|
175
|
+
get lastCall() {
|
|
176
|
+
return c.calls[c.calls.length - 1];
|
|
177
|
+
}
|
|
178
|
+
}, a = [], m = !1;
|
|
179
|
+
function i(...s) {
|
|
180
|
+
return l.push(this), o.push(this), p.push(++H), (m ? r : a.shift() || r || c.getOriginal() || (() => {
|
|
181
|
+
})).apply(this, s);
|
|
182
|
+
}
|
|
183
|
+
n(i, "mockCall");
|
|
184
|
+
let f = e.name;
|
|
185
|
+
e.getMockName = () => f || "vi.fn()", e.mockName = (s) => (f = s, e), e.mockClear = () => (c.reset(), l = [], o = [], p = [], e), e.mockReset =
|
|
186
|
+
() => (e.mockClear(), r = /* @__PURE__ */ n(() => {
|
|
187
|
+
}, "implementation"), a = [], e), e.mockRestore = () => (e.mockReset(), c.restore(), r = void 0, e), e.getMockImplementation = () => r, e.
|
|
188
|
+
mockImplementation = (s) => (r = s, c.willCall(i), e), e.mockImplementationOnce = (s) => (a.push(s), e);
|
|
189
|
+
function I(s, u) {
|
|
190
|
+
let k = r;
|
|
191
|
+
r = s, c.willCall(i), m = !0;
|
|
192
|
+
let b = /* @__PURE__ */ n(() => {
|
|
193
|
+
r = k, m = !1;
|
|
194
|
+
}, "reset"), d = u();
|
|
195
|
+
return d instanceof Promise ? d.then(() => (b(), e)) : (b(), e);
|
|
196
|
+
}
|
|
197
|
+
return n(I, "withImplementation"), e.withImplementation = I, e.mockReturnThis = () => e.mockImplementation(function() {
|
|
198
|
+
return this;
|
|
199
|
+
}), e.mockReturnValue = (s) => e.mockImplementation(() => s), e.mockReturnValueOnce = (s) => e.mockImplementationOnce(() => s), e.mockResolvedValue =
|
|
200
|
+
(s) => e.mockImplementation(() => Promise.resolve(s)), e.mockResolvedValueOnce = (s) => e.mockImplementationOnce(() => Promise.resolve(s)),
|
|
201
|
+
e.mockRejectedValue = (s) => e.mockImplementation(() => Promise.reject(s)), e.mockRejectedValueOnce = (s) => e.mockImplementationOnce(() => Promise.
|
|
202
|
+
reject(s)), Object.defineProperty(e, "mock", {
|
|
203
|
+
get: /* @__PURE__ */ n(() => y, "get")
|
|
204
|
+
}), c.willCall(i), T.add(e), e;
|
|
205
|
+
}
|
|
206
|
+
n(D, "enhanceSpy");
|
|
207
|
+
function P(t) {
|
|
208
|
+
let e = D(R({
|
|
209
|
+
spy: t || function() {
|
|
210
|
+
}
|
|
211
|
+
}, "spy"));
|
|
212
|
+
return t && e.mockImplementation(t), e;
|
|
213
|
+
}
|
|
214
|
+
n(P, "fn");
|
|
215
|
+
|
|
216
|
+
// src/test/spy.ts
|
|
217
|
+
var S = /* @__PURE__ */ new Set();
|
|
218
|
+
function J(t) {
|
|
219
|
+
return S.add(t), () => void S.delete(t);
|
|
220
|
+
}
|
|
221
|
+
n(J, "onMockCall");
|
|
222
|
+
var Q = /* @__PURE__ */ n((...t) => {
|
|
223
|
+
let e = V(...t);
|
|
224
|
+
return L(e);
|
|
225
|
+
}, "spyOn");
|
|
226
|
+
function X(t) {
|
|
227
|
+
let e = t ? P(t) : P();
|
|
228
|
+
return L(e);
|
|
229
|
+
}
|
|
230
|
+
n(X, "fn");
|
|
231
|
+
function L(t) {
|
|
232
|
+
let e = F(t), r = e.mockImplementation.bind(null);
|
|
233
|
+
return e.mockImplementation = (l) => F(r(l)), e;
|
|
234
|
+
}
|
|
235
|
+
n(L, "reactiveMock");
|
|
236
|
+
function F(t) {
|
|
237
|
+
let e = h(t), r = e.impl;
|
|
238
|
+
return e.willCall(function(...l) {
|
|
239
|
+
return S.forEach((o) => o(t, l)), r?.apply(this, l);
|
|
240
|
+
}), t;
|
|
241
|
+
}
|
|
242
|
+
n(F, "listenWhenCalled");
|
|
243
|
+
function Z() {
|
|
244
|
+
T.forEach((t) => t.mockClear());
|
|
245
|
+
}
|
|
246
|
+
n(Z, "clearAllMocks");
|
|
247
|
+
function ee() {
|
|
248
|
+
T.forEach((t) => t.mockReset());
|
|
249
|
+
}
|
|
250
|
+
n(ee, "resetAllMocks");
|
|
251
|
+
function te() {
|
|
252
|
+
T.forEach((t) => t.mockRestore());
|
|
253
|
+
}
|
|
254
|
+
n(te, "restoreAllMocks");
|
|
255
|
+
function ne(t, e = {}) {
|
|
256
|
+
return t;
|
|
257
|
+
}
|
|
258
|
+
n(ne, "mocked");
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { MockInstance, spyOn as spyOn$1, Mock as Mock$1, MaybeMocked, MaybeMockedDeep, MaybePartiallyMocked, MaybePartiallyMockedDeep } from '@vitest/spy';
|
|
2
|
+
export * from '@vitest/spy';
|
|
3
|
+
export { isMockFunction, mocks } from '@vitest/spy';
|
|
4
|
+
|
|
5
|
+
type Listener = (mock: MockInstance, args: unknown[]) => void;
|
|
6
|
+
declare function onMockCall(callback: Listener): () => void;
|
|
7
|
+
declare const spyOn: typeof spyOn$1;
|
|
8
|
+
type Procedure = (...args: any[]) => any;
|
|
9
|
+
type Mock<T extends Procedure | any[] = any[], R = any> = T extends Procedure ? Mock$1<T> : T extends any[] ? Mock$1<(...args: T) => R> : never;
|
|
10
|
+
declare function fn<T extends Procedure = Procedure>(implementation?: T): Mock<T>;
|
|
11
|
+
declare function fn<TArgs extends any[] = any, R = any>(): Mock<(...args: TArgs) => R>;
|
|
12
|
+
declare function fn<TArgs extends any[] = any[], R = any>(implementation: (...args: TArgs) => R): Mock<(...args: TArgs) => R>;
|
|
13
|
+
declare function fn<TArgs extends any[] = any[], R = any>(implementation?: (...args: TArgs) => R): Mock<(...args: TArgs) => R>;
|
|
14
|
+
/**
|
|
15
|
+
* Calls [`.mockClear()`](https://vitest.dev/api/mock#mockclear) on every mocked function. This will
|
|
16
|
+
* only empty `.mock` state, it will not reset implementation.
|
|
17
|
+
*
|
|
18
|
+
* It is useful if you need to clean up mock between different assertions.
|
|
19
|
+
*/
|
|
20
|
+
declare function clearAllMocks(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Calls [`.mockReset()`](https://vitest.dev/api/mock#mockreset) on every mocked function. This will
|
|
23
|
+
* empty `.mock` state, reset "once" implementations and force the base implementation to return
|
|
24
|
+
* `undefined` when invoked.
|
|
25
|
+
*
|
|
26
|
+
* This is useful when you want to completely reset a mock to the default state.
|
|
27
|
+
*/
|
|
28
|
+
declare function resetAllMocks(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Calls [`.mockRestore()`](https://vitest.dev/api/mock#mockrestore) on every mocked function. This
|
|
31
|
+
* will restore all original implementations.
|
|
32
|
+
*/
|
|
33
|
+
declare function restoreAllMocks(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Type helper for TypeScript. Just returns the object that was passed.
|
|
36
|
+
*
|
|
37
|
+
* When `partial` is `true` it will expect a `Partial<T>` as a return value. By default, this will
|
|
38
|
+
* only make TypeScript believe that the first level values are mocked. You can pass down `{ deep:
|
|
39
|
+
* true }` as a second argument to tell TypeScript that the whole object is mocked, if it actually
|
|
40
|
+
* is.
|
|
41
|
+
*
|
|
42
|
+
* @param item Anything that can be mocked
|
|
43
|
+
* @param deep If the object is deeply mocked
|
|
44
|
+
* @param options If the object is partially or deeply mocked
|
|
45
|
+
*/
|
|
46
|
+
declare function mocked<T>(item: T, deep?: false): MaybeMocked<T>;
|
|
47
|
+
declare function mocked<T>(item: T, deep: true): MaybeMockedDeep<T>;
|
|
48
|
+
declare function mocked<T>(item: T, options: {
|
|
49
|
+
partial?: false;
|
|
50
|
+
deep?: false;
|
|
51
|
+
}): MaybeMocked<T>;
|
|
52
|
+
declare function mocked<T>(item: T, options: {
|
|
53
|
+
partial?: false;
|
|
54
|
+
deep: true;
|
|
55
|
+
}): MaybeMockedDeep<T>;
|
|
56
|
+
declare function mocked<T>(item: T, options: {
|
|
57
|
+
partial: true;
|
|
58
|
+
deep?: false;
|
|
59
|
+
}): MaybePartiallyMocked<T>;
|
|
60
|
+
declare function mocked<T>(item: T, options: {
|
|
61
|
+
partial: true;
|
|
62
|
+
deep: true;
|
|
63
|
+
}): MaybePartiallyMockedDeep<T>;
|
|
64
|
+
declare function mocked<T>(item: T): MaybeMocked<T>;
|
|
65
|
+
|
|
66
|
+
export { type Mock, clearAllMocks, fn, mocked, onMockCall, resetAllMocks, restoreAllMocks, spyOn };
|
package/dist/test/spy.js
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
var F = Object.defineProperty;
|
|
2
|
+
var n = (t, e) => F(t, "name", { value: e, configurable: !0 });
|
|
3
|
+
|
|
4
|
+
// ../node_modules/tinyspy/dist/index.js
|
|
5
|
+
function x(t, e) {
|
|
6
|
+
if (!t)
|
|
7
|
+
throw new Error(e);
|
|
8
|
+
}
|
|
9
|
+
n(x, "d");
|
|
10
|
+
function g(t, e) {
|
|
11
|
+
return typeof e === t;
|
|
12
|
+
}
|
|
13
|
+
n(g, "y");
|
|
14
|
+
function L(t) {
|
|
15
|
+
return t instanceof Promise;
|
|
16
|
+
}
|
|
17
|
+
n(L, "w");
|
|
18
|
+
function b(t, e, r) {
|
|
19
|
+
Object.defineProperty(t, e, r);
|
|
20
|
+
}
|
|
21
|
+
n(b, "f");
|
|
22
|
+
function M(t, e, r) {
|
|
23
|
+
Object.defineProperty(t, e, { value: r });
|
|
24
|
+
}
|
|
25
|
+
n(M, "l");
|
|
26
|
+
var T = Symbol.for("tinyspy:spy"), _ = /* @__PURE__ */ new Set(), N = /* @__PURE__ */ n((t) => {
|
|
27
|
+
t.called = !1, t.callCount = 0, t.calls = [], t.results = [], t.resolves = [], t.next = [];
|
|
28
|
+
}, "P"), K = /* @__PURE__ */ n((t) => (b(t, T, { value: { reset: /* @__PURE__ */ n(() => N(t[T]), "reset") } }), t[T]), "K"), h = /* @__PURE__ */ n(
|
|
29
|
+
(t) => t[T] || K(t), "T");
|
|
30
|
+
function U(t) {
|
|
31
|
+
x(
|
|
32
|
+
g("function", t) || g("undefined", t),
|
|
33
|
+
"cannot spy on a non-function value"
|
|
34
|
+
);
|
|
35
|
+
let e = /* @__PURE__ */ n(function(...l) {
|
|
36
|
+
let s = h(e);
|
|
37
|
+
s.called = !0, s.callCount++, s.calls.push(l);
|
|
38
|
+
let p = s.next.shift();
|
|
39
|
+
if (p) {
|
|
40
|
+
s.results.push(p);
|
|
41
|
+
let [i, f] = p;
|
|
42
|
+
if (i === "ok")
|
|
43
|
+
return f;
|
|
44
|
+
throw f;
|
|
45
|
+
}
|
|
46
|
+
let c, y = "ok", a = s.results.length;
|
|
47
|
+
if (s.impl)
|
|
48
|
+
try {
|
|
49
|
+
new.target ? c = Reflect.construct(s.impl, l, new.target) : c = s.impl.apply(this, l), y = "ok";
|
|
50
|
+
} catch (i) {
|
|
51
|
+
throw c = i, y = "error", s.results.push([y, i]), i;
|
|
52
|
+
}
|
|
53
|
+
let m = [y, c];
|
|
54
|
+
return L(c) && c.then(
|
|
55
|
+
(i) => s.resolves[a] = ["ok", i],
|
|
56
|
+
(i) => s.resolves[a] = ["error", i]
|
|
57
|
+
), s.results.push(m), c;
|
|
58
|
+
}, "t");
|
|
59
|
+
M(e, "_isMockFunction", !0), M(e, "length", t ? t.length : 0), M(e, "name", t && t.name || "spy");
|
|
60
|
+
let r = h(e);
|
|
61
|
+
return r.reset(), r.impl = t, e;
|
|
62
|
+
}
|
|
63
|
+
n(U, "m");
|
|
64
|
+
var S = /* @__PURE__ */ n((t, e) => Object.getOwnPropertyDescriptor(t, e), "k"), C = /* @__PURE__ */ n((t, e) => {
|
|
65
|
+
e != null && typeof e == "function" && e.prototype != null && Object.setPrototypeOf(t.prototype, e.prototype);
|
|
66
|
+
}, "O");
|
|
67
|
+
function w(t, e, r) {
|
|
68
|
+
x(
|
|
69
|
+
!g("undefined", t),
|
|
70
|
+
"spyOn could not find an object to spy upon"
|
|
71
|
+
), x(
|
|
72
|
+
g("object", t) || g("function", t),
|
|
73
|
+
"cannot spyOn on a primitive value"
|
|
74
|
+
);
|
|
75
|
+
let [l, s] = (() => {
|
|
76
|
+
if (!g("object", e))
|
|
77
|
+
return [e, "value"];
|
|
78
|
+
if ("getter" in e && "setter" in e)
|
|
79
|
+
throw new Error("cannot spy on both getter and setter");
|
|
80
|
+
if ("getter" in e)
|
|
81
|
+
return [e.getter, "get"];
|
|
82
|
+
if ("setter" in e)
|
|
83
|
+
return [e.setter, "set"];
|
|
84
|
+
throw new Error("specify getter or setter to spy on");
|
|
85
|
+
})(), p = S(t, l), c = Object.getPrototypeOf(t), y = c && S(c, l), a = p || y;
|
|
86
|
+
x(
|
|
87
|
+
a || l in t,
|
|
88
|
+
`${String(l)} does not exist`
|
|
89
|
+
);
|
|
90
|
+
let m = !1;
|
|
91
|
+
s === "value" && a && !a.value && a.get && (s = "get", m = !0, r = a.get());
|
|
92
|
+
let i;
|
|
93
|
+
a ? i = a[s] : s !== "value" ? i = /* @__PURE__ */ n(() => t[l], "o") : i = t[l];
|
|
94
|
+
let f = /* @__PURE__ */ n((k) => {
|
|
95
|
+
let { value: I, ...d } = a || {
|
|
96
|
+
configurable: !0,
|
|
97
|
+
writable: !0
|
|
98
|
+
};
|
|
99
|
+
s !== "value" && delete d.writable, d[s] = k, b(t, l, d);
|
|
100
|
+
}, "g"), O = /* @__PURE__ */ n(() => a ? b(t, l, a) : f(i), "b");
|
|
101
|
+
r || (r = i);
|
|
102
|
+
let o = U(r);
|
|
103
|
+
s === "value" && C(o, i);
|
|
104
|
+
let u = o[T];
|
|
105
|
+
return M(u, "restore", O), M(u, "getOriginal", () => m ? i() : i), M(u, "willCall", (k) => (u.impl = k, o)), f(
|
|
106
|
+
m ? () => (C(o, r), o) : o
|
|
107
|
+
), _.add(o), o;
|
|
108
|
+
}
|
|
109
|
+
n(w, "C");
|
|
110
|
+
|
|
111
|
+
// ../node_modules/@vitest/spy/dist/index.js
|
|
112
|
+
var v = /* @__PURE__ */ new Set();
|
|
113
|
+
function W(t) {
|
|
114
|
+
return typeof t == "function" && "_isMockFunction" in t && t._isMockFunction;
|
|
115
|
+
}
|
|
116
|
+
n(W, "isMockFunction");
|
|
117
|
+
function A(t, e, r) {
|
|
118
|
+
let s = r ? { [{
|
|
119
|
+
get: "getter",
|
|
120
|
+
set: "setter"
|
|
121
|
+
}[r]]: e } : e, p = w(t, s);
|
|
122
|
+
return E(p);
|
|
123
|
+
}
|
|
124
|
+
n(A, "spyOn");
|
|
125
|
+
var Y = 0;
|
|
126
|
+
function E(t) {
|
|
127
|
+
let e = t, r, l = [], s = [], p = [], c = h(t), y = {
|
|
128
|
+
get calls() {
|
|
129
|
+
return c.calls;
|
|
130
|
+
},
|
|
131
|
+
get contexts() {
|
|
132
|
+
return s;
|
|
133
|
+
},
|
|
134
|
+
get instances() {
|
|
135
|
+
return l;
|
|
136
|
+
},
|
|
137
|
+
get invocationCallOrder() {
|
|
138
|
+
return p;
|
|
139
|
+
},
|
|
140
|
+
get results() {
|
|
141
|
+
return c.results.map(([o, u]) => ({ type: o === "error" ? "throw" : "return", value: u }));
|
|
142
|
+
},
|
|
143
|
+
get settledResults() {
|
|
144
|
+
return c.resolves.map(([o, u]) => ({ type: o === "error" ? "rejected" : "fulfilled", value: u }));
|
|
145
|
+
},
|
|
146
|
+
get lastCall() {
|
|
147
|
+
return c.calls[c.calls.length - 1];
|
|
148
|
+
}
|
|
149
|
+
}, a = [], m = !1;
|
|
150
|
+
function i(...o) {
|
|
151
|
+
return l.push(this), s.push(this), p.push(++Y), (m ? r : a.shift() || r || c.getOriginal() || (() => {
|
|
152
|
+
})).apply(this, o);
|
|
153
|
+
}
|
|
154
|
+
n(i, "mockCall");
|
|
155
|
+
let f = e.name;
|
|
156
|
+
e.getMockName = () => f || "vi.fn()", e.mockName = (o) => (f = o, e), e.mockClear = () => (c.reset(), l = [], s = [], p = [], e), e.mockReset =
|
|
157
|
+
() => (e.mockClear(), r = /* @__PURE__ */ n(() => {
|
|
158
|
+
}, "implementation"), a = [], e), e.mockRestore = () => (e.mockReset(), c.restore(), r = void 0, e), e.getMockImplementation = () => r, e.
|
|
159
|
+
mockImplementation = (o) => (r = o, c.willCall(i), e), e.mockImplementationOnce = (o) => (a.push(o), e);
|
|
160
|
+
function O(o, u) {
|
|
161
|
+
let k = r;
|
|
162
|
+
r = o, c.willCall(i), m = !0;
|
|
163
|
+
let I = /* @__PURE__ */ n(() => {
|
|
164
|
+
r = k, m = !1;
|
|
165
|
+
}, "reset"), d = u();
|
|
166
|
+
return d instanceof Promise ? d.then(() => (I(), e)) : (I(), e);
|
|
167
|
+
}
|
|
168
|
+
return n(O, "withImplementation"), e.withImplementation = O, e.mockReturnThis = () => e.mockImplementation(function() {
|
|
169
|
+
return this;
|
|
170
|
+
}), e.mockReturnValue = (o) => e.mockImplementation(() => o), e.mockReturnValueOnce = (o) => e.mockImplementationOnce(() => o), e.mockResolvedValue =
|
|
171
|
+
(o) => e.mockImplementation(() => Promise.resolve(o)), e.mockResolvedValueOnce = (o) => e.mockImplementationOnce(() => Promise.resolve(o)),
|
|
172
|
+
e.mockRejectedValue = (o) => e.mockImplementation(() => Promise.reject(o)), e.mockRejectedValueOnce = (o) => e.mockImplementationOnce(() => Promise.
|
|
173
|
+
reject(o)), Object.defineProperty(e, "mock", {
|
|
174
|
+
get: /* @__PURE__ */ n(() => y, "get")
|
|
175
|
+
}), c.willCall(i), v.add(e), e;
|
|
176
|
+
}
|
|
177
|
+
n(E, "enhanceSpy");
|
|
178
|
+
function R(t) {
|
|
179
|
+
let e = E(w({
|
|
180
|
+
spy: t || function() {
|
|
181
|
+
}
|
|
182
|
+
}, "spy"));
|
|
183
|
+
return t && e.mockImplementation(t), e;
|
|
184
|
+
}
|
|
185
|
+
n(R, "fn");
|
|
186
|
+
|
|
187
|
+
// src/test/spy.ts
|
|
188
|
+
var P = /* @__PURE__ */ new Set();
|
|
189
|
+
function H(t) {
|
|
190
|
+
return P.add(t), () => void P.delete(t);
|
|
191
|
+
}
|
|
192
|
+
n(H, "onMockCall");
|
|
193
|
+
var J = /* @__PURE__ */ n((...t) => {
|
|
194
|
+
let e = A(...t);
|
|
195
|
+
return D(e);
|
|
196
|
+
}, "spyOn");
|
|
197
|
+
function Q(t) {
|
|
198
|
+
let e = t ? R(t) : R();
|
|
199
|
+
return D(e);
|
|
200
|
+
}
|
|
201
|
+
n(Q, "fn");
|
|
202
|
+
function D(t) {
|
|
203
|
+
let e = V(t), r = e.mockImplementation.bind(null);
|
|
204
|
+
return e.mockImplementation = (l) => V(r(l)), e;
|
|
205
|
+
}
|
|
206
|
+
n(D, "reactiveMock");
|
|
207
|
+
function V(t) {
|
|
208
|
+
let e = h(t), r = e.impl;
|
|
209
|
+
return e.willCall(function(...l) {
|
|
210
|
+
return P.forEach((s) => s(t, l)), r?.apply(this, l);
|
|
211
|
+
}), t;
|
|
212
|
+
}
|
|
213
|
+
n(V, "listenWhenCalled");
|
|
214
|
+
function X() {
|
|
215
|
+
v.forEach((t) => t.mockClear());
|
|
216
|
+
}
|
|
217
|
+
n(X, "clearAllMocks");
|
|
218
|
+
function Z() {
|
|
219
|
+
v.forEach((t) => t.mockReset());
|
|
220
|
+
}
|
|
221
|
+
n(Z, "resetAllMocks");
|
|
222
|
+
function ee() {
|
|
223
|
+
v.forEach((t) => t.mockRestore());
|
|
224
|
+
}
|
|
225
|
+
n(ee, "restoreAllMocks");
|
|
226
|
+
function te(t, e = {}) {
|
|
227
|
+
return t;
|
|
228
|
+
}
|
|
229
|
+
n(te, "mocked");
|
|
230
|
+
export {
|
|
231
|
+
X as clearAllMocks,
|
|
232
|
+
Q as fn,
|
|
233
|
+
W as isMockFunction,
|
|
234
|
+
te as mocked,
|
|
235
|
+
v as mocks,
|
|
236
|
+
H as onMockCall,
|
|
237
|
+
Z as resetAllMocks,
|
|
238
|
+
ee as restoreAllMocks,
|
|
239
|
+
J as spyOn
|
|
240
|
+
};
|