vitest-auto-spy 1.5.1 → 1.8.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/README.md +98 -3
- package/assets/angular-provide-auto-spy.svg +63 -0
- package/assets/one-api-three-runtimes.svg +51 -0
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +1 -1
- package/dist/angular.d.ts +1 -1
- package/dist/angular.js +1 -1
- package/dist/bun.cjs +1 -1
- package/dist/bun.d.cts +2 -2
- package/dist/bun.d.ts +2 -2
- package/dist/bun.js +1 -1
- package/dist/chunk-HVN6A3AX.js +1 -0
- package/dist/chunk-MQCVIN2A.js +1 -0
- package/dist/chunk-WP2TFS53.js +1 -0
- package/dist/console.cjs +1 -0
- package/dist/console.d.cts +39 -0
- package/dist/console.d.ts +39 -0
- package/dist/console.js +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/nestjs.cjs +1 -1
- package/dist/nestjs.d.cts +1 -1
- package/dist/nestjs.d.ts +1 -1
- package/dist/nestjs.js +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +1 -1
- package/dist/rxjs.d.cts +2 -2
- package/dist/rxjs.d.ts +2 -2
- package/dist/svelte.cjs +1 -1
- package/dist/svelte.d.cts +1 -1
- package/dist/svelte.d.ts +1 -1
- package/dist/svelte.js +1 -1
- package/dist/{types-C84-zP_V.d.cts → types-Cv3L71P0.d.cts} +6 -1
- package/dist/{types-C84-zP_V.d.ts → types-Cv3L71P0.d.ts} +6 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +2 -2
- package/dist/vue.d.ts +2 -2
- package/dist/vue.js +1 -1
- package/package.json +11 -2
- package/dist/chunk-ACSYU277.js +0 -1
- package/dist/chunk-VLNCYBUN.js +0 -1
package/README.md
CHANGED
|
@@ -25,6 +25,10 @@ replacement for [`jest-auto-spies`](https://www.npmjs.com/package/jest-auto-spie
|
|
|
25
25
|
|
|
26
26
|
📦 [**npm**](https://www.npmjs.com/package/vitest-auto-spy) · 🐙 [**GitHub**](https://github.com/ASDAlexey/vitest-auto-spy) · 🔖 [**Changelog**](./CHANGELOG.md)
|
|
27
27
|
|
|
28
|
+
<br/>
|
|
29
|
+
|
|
30
|
+
<img src="./assets/one-api-three-runtimes.svg" alt="One class-based API, three Vitest-compatible runtimes: Vitest, Bun and node:test" width="720" />
|
|
31
|
+
|
|
28
32
|
</div>
|
|
29
33
|
|
|
30
34
|
---
|
|
@@ -37,6 +41,8 @@ replacement for [`jest-auto-spies`](https://www.npmjs.com/package/jest-auto-spie
|
|
|
37
41
|
- 🔀 `calledWith` / `mustBeCalledWith` argument dispatch
|
|
38
42
|
- 📡 First-class RxJS `Observable` spying (`nextWith`, `nextWithValues`, `throwWith`, …)
|
|
39
43
|
- ⚙️ Getter / setter spies via `accessorSpies`
|
|
44
|
+
- 🧰 DI & mocking utilities — `provideAutoSpy` / `injectSpy` (Angular, NestJS, Vue), `createFunctionSpy`, `mockReadonlyProp` for signals
|
|
45
|
+
- 🔇 Console spies — `import { consoleInfoSpy } from 'vitest-auto-spy/console'` silences `console` and asserts its calls
|
|
40
46
|
- 🟢 100% test coverage, **zero runtime dependencies** (in-tree arg serializer, no `javascript-stringify`)
|
|
41
47
|
|
|
42
48
|
## Table of contents
|
|
@@ -60,6 +66,7 @@ replacement for [`jest-auto-spies`](https://www.npmjs.com/package/jest-auto-spie
|
|
|
60
66
|
- [Vue / Pinia](#vue--pinia)
|
|
61
67
|
- [Svelte](#svelte)
|
|
62
68
|
- [Angular](#angular)
|
|
69
|
+
- [Utilities](#utilities)
|
|
63
70
|
- [API reference](#api-reference)
|
|
64
71
|
- [FAQ & troubleshooting](#faq--troubleshooting)
|
|
65
72
|
- [Versioning](#versioning)
|
|
@@ -92,7 +99,7 @@ them only for the matching entry point. The package itself has **zero runtime de
|
|
|
92
99
|
| Peer | Needed for | Optional? |
|
|
93
100
|
| --- | --- | --- |
|
|
94
101
|
| `vitest` | the default runner | no |
|
|
95
|
-
| `rxjs` | `vitest-auto-spy/rxjs` observable spies (and `Spy<T>` type-checking) | yes |
|
|
102
|
+
| `rxjs` | `vitest-auto-spy/rxjs` observable spies (and `Spy<T>` type-checking) — `>=7`, **no upper bound** (the rxjs 8 line included) | yes |
|
|
96
103
|
| `@angular/core` | `vitest-auto-spy/angular` helpers | yes |
|
|
97
104
|
|
|
98
105
|
## Availability
|
|
@@ -105,7 +112,7 @@ them only for the matching entry point. The package itself has **zero runtime de
|
|
|
105
112
|
| --- | --- |
|
|
106
113
|
| `vitest-auto-spy` · `vitest-auto-spy/rxjs` · `vitest-auto-spy/angular` | ✅ **Published** |
|
|
107
114
|
| `vitest-auto-spy/bun` · `vitest-auto-spy/node` | ✅ **Published** |
|
|
108
|
-
| `vitest-auto-spy/nestjs` · `/react` · `/vue` · `/svelte` | ✅ **Published** |
|
|
115
|
+
| `vitest-auto-spy/nestjs` · `/react` · `/vue` · `/svelte` · `/console` | ✅ **Published** |
|
|
109
116
|
|
|
110
117
|
## Quick start
|
|
111
118
|
|
|
@@ -210,6 +217,7 @@ Node / Bun / React / Vue project pulls **neither rxjs nor Angular into its runti
|
|
|
210
217
|
| `vitest-auto-spy/react` | the core, with a natural import for React Testing Library suites | — (your `react`) | ✅ |
|
|
211
218
|
| `vitest-auto-spy/vue` | `provideAutoSpy` for `global.provide` + Pinia store spying | — (your `vue`/`pinia`) | ✅ |
|
|
212
219
|
| `vitest-auto-spy/svelte` | the core, with a natural import for Svelte suites | — (your `svelte`) | ✅ |
|
|
220
|
+
| `vitest-auto-spy/console` | `consoleInfoSpy` & friends — silent typed spies over the global `console`, installed on import | `vitest` | ✅ |
|
|
213
221
|
|
|
214
222
|
✅ all entry points published (see [Availability](#availability)).
|
|
215
223
|
|
|
@@ -255,8 +263,9 @@ import { createSpyFromClass } from 'vitest-auto-spy/node'; // node:test
|
|
|
255
263
|
|
|
256
264
|
| Library | Reads a class? | Return-type-aware helpers? | Runtimes | We win on |
|
|
257
265
|
| --- | :---: | :---: | --- | --- |
|
|
258
|
-
| **vitest-auto-spy** | ✅ | ✅ | Vitest
|
|
266
|
+
| **vitest-auto-spy** | ✅ | ✅ | Vitest · Bun · node:test | — |
|
|
259
267
|
| [jest-auto-spies](https://www.npmjs.com/package/jest-auto-spies) | ✅ | ✅ | Jest only | Vitest/Bun/Node successor, **same API** — direct migration path |
|
|
268
|
+
| [@bugsplat/vitest-auto-spies](https://www.npmjs.com/package/@bugsplat/vitest-auto-spies) | ✅ | ✅ | Vitest only | Same class-based API **plus** Bun & `node:test`, [type-only `createAutoMock`](#auto-mock-by-type-no-class-needed), framework recipes (Angular/NestJS/React/Vue/Svelte), console spies, and **zero runtime deps** (it depends on `@hirez_io/auto-spies-core`) |
|
|
260
269
|
| [vitest-mock-extended](https://www.npmjs.com/package/vitest-mock-extended) | ❌ (Proxy) | ❌ | Vitest | Return-type ergonomics **and** reading a real class (we also ship a Proxy mode: [`createAutoMock`](#auto-mock-by-type-no-class-needed)) |
|
|
261
270
|
| [@golevelup/ts-vitest](https://www.npmjs.com/package/@golevelup/ts-vitest) | partial | ❌ | Vitest | Typed `Promise`/`Observable` helpers + explicit class→spy + `mustBeCalledWith` |
|
|
262
271
|
| [sinon](https://www.npmjs.com/package/sinon) | ❌ (manual) | ❌ | Any | Auto-generated + fully typed vs. manual + loosely typed |
|
|
@@ -280,11 +289,16 @@ The public API is intentionally identical. In most projects the migration is a
|
|
|
280
289
|
The only API-shape change from `jest-auto-spies` is that the Angular helpers and the
|
|
281
290
|
observable layer live behind the `/angular` and `/rxjs` subpaths (see [Entry points & runtimes](#entry-points--runtimes)).
|
|
282
291
|
|
|
292
|
+
This also covers migrating from [`@bugsplat/vitest-auto-spies`](https://www.npmjs.com/package/@bugsplat/vitest-auto-spies),
|
|
293
|
+
which re-exports the same `jest-auto-spies` API — the swap is identical, and you gain Bun /
|
|
294
|
+
`node:test`, `createAutoMock`, framework recipes and console spies on top.
|
|
295
|
+
|
|
283
296
|
| jest-auto-spies | vitest-auto-spy | Status |
|
|
284
297
|
| --- | --- | --- |
|
|
285
298
|
| `createSpyFromClass` | `createSpyFromClass` | ✅ identical |
|
|
286
299
|
| `provideAutoSpy` | `provideAutoSpy` | ✅ identical |
|
|
287
300
|
| `calledWith` / `mustBeCalledWith` | same | ✅ identical |
|
|
301
|
+
| `calledWith(...).returnValue(v)` | same — `.returnValue` **and** `.mockReturnValue` both work | ✅ identical |
|
|
288
302
|
| `resolveWith` / `rejectWith` / `resolveWithPerCall` | same | ✅ identical |
|
|
289
303
|
| `nextWith` / `nextOneTimeWith` / `nextWithValues` / `nextWithPerCall` | same | ✅ identical |
|
|
290
304
|
| `throwWith` / `complete` / `returnSubject` | same | ✅ identical |
|
|
@@ -589,6 +603,12 @@ it('shows the cart total from the store', () => {
|
|
|
589
603
|
|
|
590
604
|
### Angular
|
|
591
605
|
|
|
606
|
+
<div align="center">
|
|
607
|
+
|
|
608
|
+
<img src="./assets/angular-provide-auto-spy.svg" alt="Angular TestBed recipe: provideAutoSpy registers a typed spy provider and injectSpy returns Spy<ApiService> — no manual { provide, useValue }, no TestBed.inject<any> cast" width="720" />
|
|
609
|
+
|
|
610
|
+
</div>
|
|
611
|
+
|
|
592
612
|
`provideAutoSpy` is the shorthand for providing an auto-spy in a `TestBed`:
|
|
593
613
|
|
|
594
614
|
```ts
|
|
@@ -625,6 +645,79 @@ mockReadonlyPropGetter(service, 'label', () => 'A'); // dynamic getter
|
|
|
625
645
|
mockAccessorsProp(service, 'theme'); // spied get + set
|
|
626
646
|
```
|
|
627
647
|
|
|
648
|
+
## Utilities
|
|
649
|
+
|
|
650
|
+
Beyond the spy factories, the package ships a set of small standalone helpers. Each one is a
|
|
651
|
+
single-purpose utility you can pick up independently — they all ride on the same core:
|
|
652
|
+
|
|
653
|
+
| Utility | Entry point | What it's for |
|
|
654
|
+
| --- | --- | --- |
|
|
655
|
+
| `injectSpy(token)` / `injectSpy(moduleRef, token)` | `/angular`, `/nestjs` | Pull a provided spy out of the DI container, already typed as `Spy<T>` — no casting |
|
|
656
|
+
| `provideAutoSpy(Class, config?)` | `/angular`, `/nestjs`, `/vue` | One-liner `{ provide, useValue }` (or Vue `global.provide`) that builds the spy for you |
|
|
657
|
+
| `createFunctionSpy(name)` | core | A single standalone function spy with the full helper set (`calledWith`, `resolveWith`, `nextWith`, …) — no class needed |
|
|
658
|
+
| `createAutoMock<T>(overrides?)` | core | Proxy-based spy from a **type/interface** alone ([details](#auto-mock-by-type-no-class-needed)) |
|
|
659
|
+
| `createObservableWithValues(configs, opts?)` | `/rxjs` | Build a fake `Observable` emitting a precise sequence of values / errors / completion |
|
|
660
|
+
| `consoleInfoSpy` / `consoleWarnSpy` / … | `/console` | Silent typed spies over the global `console`, installed on import ([details](#console-spies--vitest-auto-spyconsole)) |
|
|
661
|
+
| `mockReadonlyProp(obj, prop, value)` | `/angular` | Overwrite a `readonly` property (incl. Angular signals) with a static value |
|
|
662
|
+
| `mockReadonlyPropGetter(obj, prop, getter)` | `/angular` | Same, but backed by a dynamic getter |
|
|
663
|
+
| `mockAccessorsProp(obj, prop)` | `/angular` | Redefine a property with spied `get` + `set` |
|
|
664
|
+
| `errorHandler` | core | The `mustBeCalledWith` argument-mismatch reporter — swap it to customize failure output |
|
|
665
|
+
|
|
666
|
+
A taste of the DI pair — provide the spy, inject it back fully typed:
|
|
667
|
+
|
|
668
|
+
```ts
|
|
669
|
+
import { provideAutoSpy, injectSpy } from 'vitest-auto-spy/angular';
|
|
670
|
+
|
|
671
|
+
TestBed.configureTestingModule({ providers: [provideAutoSpy(UserService)] });
|
|
672
|
+
const userService = injectSpy(UserService); // Spy<UserService>, no `as` cast
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
And a standalone function spy, when there's no class or interface at all:
|
|
676
|
+
|
|
677
|
+
```ts
|
|
678
|
+
import { createFunctionSpy } from 'vitest-auto-spy';
|
|
679
|
+
|
|
680
|
+
const onSave = createFunctionSpy<(id: number) => Promise<void>>('onSave');
|
|
681
|
+
onSave.calledWith(1).resolveWith();
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
### Console spies — `vitest-auto-spy/console`
|
|
685
|
+
|
|
686
|
+
Importing the entry replaces `console.debug` / `error` / `info` / `log` / `time` / `timeEnd` /
|
|
687
|
+
`trace` / `warn` with **silent, fully-typed spies** and exports each one ready to assert — no
|
|
688
|
+
`vi.spyOn(console, 'info')` boilerplate in every suite, no log output polluting the test run:
|
|
689
|
+
|
|
690
|
+
```ts
|
|
691
|
+
import { consoleInfoSpy, consoleWarnSpy } from 'vitest-auto-spy/console';
|
|
692
|
+
|
|
693
|
+
service.doWork();
|
|
694
|
+
|
|
695
|
+
expect(consoleInfoSpy).toHaveBeenCalledWith('done');
|
|
696
|
+
expect(consoleWarnSpy).not.toHaveBeenCalled();
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
Housekeeping: `resetConsoleSpies()` clears the recorded calls between tests (Vitest's
|
|
700
|
+
`clearMocks: true` already does that automatically), `restoreConsole()` puts the original
|
|
701
|
+
methods back, and `installConsoleSpies()` re-installs after a restore.
|
|
702
|
+
|
|
703
|
+
> The spies use the registered `MockAdapter` — import your runtime entry
|
|
704
|
+
> (`vitest-auto-spy/bun`, `…/node`) **before** `vitest-auto-spy/console` and the console spies
|
|
705
|
+
> are driven by that runner's mocks; with no prior runtime entry the default Vitest adapter is used.
|
|
706
|
+
|
|
707
|
+
Prefer a fully detached fake instead of touching the real global? `createAutoMock<Console>()`
|
|
708
|
+
gives you a typed, in-memory console to inject into code that takes a logger:
|
|
709
|
+
|
|
710
|
+
```ts
|
|
711
|
+
import { createAutoMock } from 'vitest-auto-spy';
|
|
712
|
+
|
|
713
|
+
const fakeConsole = createAutoMock<Console>();
|
|
714
|
+
const service = new ReportService(fakeConsole);
|
|
715
|
+
|
|
716
|
+
service.doWork();
|
|
717
|
+
|
|
718
|
+
expect(fakeConsole.info).toHaveBeenCalledWith('done');
|
|
719
|
+
```
|
|
720
|
+
|
|
628
721
|
## API reference
|
|
629
722
|
|
|
630
723
|
| Export | Description |
|
|
@@ -637,6 +730,8 @@ mockAccessorsProp(service, 'theme'); // spied get + set
|
|
|
637
730
|
| `createFunctionSpy(name)` | A single standalone function spy with all helpers |
|
|
638
731
|
| `createObservableWithValues(configs, opts?)` | Build an Observable from value configs |
|
|
639
732
|
| `mockReadonlyProp` / `mockReadonlyPropGetter` / `mockAccessorsProp` | Mock readonly / accessor / signal props |
|
|
733
|
+
| `consoleDebugSpy` … `consoleWarnSpy` _(`/console`)_ | Silent typed spies replacing the global `console` methods on import |
|
|
734
|
+
| `installConsoleSpies()` / `resetConsoleSpies()` / `restoreConsole()` | Install / clear / undo the console spies |
|
|
640
735
|
| `errorHandler` | The `mustBeCalledWith` argument-mismatch error helper |
|
|
641
736
|
|
|
642
737
|
**Spied sync method:** `mockReturnValue`, `calledWith(...)`, `mustBeCalledWith(...)`
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="840" height="320" viewBox="0 0 840 320" font-family="ui-sans-serif, -apple-system, Segoe UI, Roboto, sans-serif" role="img" aria-label="Angular TestBed: provideAutoSpy registers a typed spy provider and injectSpy returns Spy<ApiService> — no manual provide/useValue, no TestBed.inject<any>">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="acard" x1="0" y1="0" x2="0" y2="1">
|
|
4
|
+
<stop offset="0" stop-color="#ffffff"/>
|
|
5
|
+
<stop offset="1" stop-color="#f4f6fb"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
<style>
|
|
8
|
+
@media (prefers-color-scheme: dark) {
|
|
9
|
+
.abg { fill: #0d1117; }
|
|
10
|
+
.acard { fill: #161b22; stroke: #30363d; }
|
|
11
|
+
.atitle { fill: #e6edf3; }
|
|
12
|
+
.asub { fill: #8b949e; }
|
|
13
|
+
.acode { fill: #e6edf3; }
|
|
14
|
+
.aarrow { stroke: #6e7681; }
|
|
15
|
+
.achip { fill: #1f6feb22; stroke: #388bfd; }
|
|
16
|
+
.achipText { fill: #58a6ff; }
|
|
17
|
+
.abad { fill: #2ea04326; stroke: #3fb950; }
|
|
18
|
+
.abadText { fill: #3fb950; }
|
|
19
|
+
}
|
|
20
|
+
</style>
|
|
21
|
+
</defs>
|
|
22
|
+
|
|
23
|
+
<rect class="abg" width="840" height="320" fill="#ffffff" rx="16"/>
|
|
24
|
+
|
|
25
|
+
<text class="atitle" x="40" y="52" font-size="26" font-weight="700" fill="#0d1117">Angular · TestBed recipe</text>
|
|
26
|
+
<text class="asub" x="40" y="78" font-size="15" fill="#57606a">provideAutoSpy + injectSpy — a typed spy provider, zero boilerplate.</text>
|
|
27
|
+
|
|
28
|
+
<!-- providers -->
|
|
29
|
+
<rect class="acard" x="40" y="108" width="330" height="76" rx="12" fill="url(#acard)" stroke="#d0d7de"/>
|
|
30
|
+
<text class="asub" x="62" y="132" font-size="12" fill="#57606a">providers:</text>
|
|
31
|
+
<text class="acode" x="62" y="158" font-size="15" font-family="ui-monospace, SFMono-Regular, Menlo, monospace" fill="#0d1117">provideAutoSpy(</text>
|
|
32
|
+
<text class="acode" x="62" y="178" font-size="15" font-family="ui-monospace, SFMono-Regular, Menlo, monospace" fill="#0d1117">  ApiService)</text>
|
|
33
|
+
|
|
34
|
+
<!-- arrow 1 -->
|
|
35
|
+
<line class="aarrow" x1="378" y1="146" x2="452" y2="146" stroke="#8c959f" stroke-width="2"/>
|
|
36
|
+
<polygon points="452,141 464,146 452,151" fill="#8c959f"/>
|
|
37
|
+
|
|
38
|
+
<!-- injectSpy -->
|
|
39
|
+
<rect class="acard" x="472" y="108" width="328" height="76" rx="12" fill="url(#acard)" stroke="#d0d7de"/>
|
|
40
|
+
<text class="acode" x="494" y="142" font-size="15" font-family="ui-monospace, SFMono-Regular, Menlo, monospace" fill="#0d1117">injectSpy(ApiService)</text>
|
|
41
|
+
<text class="atitle" x="494" y="168" font-size="15" font-weight="600" fill="#0d1117">: Spy<ApiService></text>
|
|
42
|
+
|
|
43
|
+
<!-- what you DON'T write -->
|
|
44
|
+
<g>
|
|
45
|
+
<rect class="abad" x="40" y="216" width="378" height="42" rx="21" fill="#dafbe1" stroke="#4ac26b"/>
|
|
46
|
+
<text class="abadText" x="229" y="242" font-size="14" font-weight="600" text-anchor="middle" fill="#1a7f37">no manual { provide, useValue }</text>
|
|
47
|
+
|
|
48
|
+
<rect class="abad" x="430" y="216" width="370" height="42" rx="21" fill="#dafbe1" stroke="#4ac26b"/>
|
|
49
|
+
<text class="abadText" x="615" y="242" font-size="14" font-weight="600" text-anchor="middle" fill="#1a7f37">no TestBed.inject<any> cast</text>
|
|
50
|
+
</g>
|
|
51
|
+
|
|
52
|
+
<!-- frameworks sharing the recipe -->
|
|
53
|
+
<g>
|
|
54
|
+
<rect class="achip" x="40" y="272" width="240" height="34" rx="17" fill="#ddf4ff" stroke="#54aeff"/>
|
|
55
|
+
<text class="achipText" x="160" y="294" font-size="14" font-weight="600" text-anchor="middle" fill="#0969da">Angular</text>
|
|
56
|
+
|
|
57
|
+
<rect class="achip" x="300" y="272" width="240" height="34" rx="17" fill="#ddf4ff" stroke="#54aeff"/>
|
|
58
|
+
<text class="achipText" x="420" y="294" font-size="14" font-weight="600" text-anchor="middle" fill="#0969da">NestJS</text>
|
|
59
|
+
|
|
60
|
+
<rect class="achip" x="560" y="272" width="240" height="34" rx="17" fill="#ddf4ff" stroke="#54aeff"/>
|
|
61
|
+
<text class="achipText" x="680" y="294" font-size="14" font-weight="600" text-anchor="middle" fill="#0969da">Vue · Pinia</text>
|
|
62
|
+
</g>
|
|
63
|
+
</svg>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="840" height="300" viewBox="0 0 840 300" font-family="ui-sans-serif, -apple-system, Segoe UI, Roboto, sans-serif" role="img" aria-label="One class-based API, three Vitest-compatible runtimes: Vitest, Bun, node:test">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="card" x1="0" y1="0" x2="0" y2="1">
|
|
4
|
+
<stop offset="0" stop-color="#ffffff"/>
|
|
5
|
+
<stop offset="1" stop-color="#f4f6fb"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
<style>
|
|
8
|
+
@media (prefers-color-scheme: dark) {
|
|
9
|
+
.bg { fill: #0d1117; }
|
|
10
|
+
.card { fill: #161b22; stroke: #30363d; }
|
|
11
|
+
.title { fill: #e6edf3; }
|
|
12
|
+
.sub { fill: #8b949e; }
|
|
13
|
+
.code { fill: #e6edf3; }
|
|
14
|
+
.arrow { stroke: #6e7681; }
|
|
15
|
+
.chip { fill: #1f6feb22; stroke: #388bfd; }
|
|
16
|
+
.chipText { fill: #58a6ff; }
|
|
17
|
+
}
|
|
18
|
+
</style>
|
|
19
|
+
</defs>
|
|
20
|
+
|
|
21
|
+
<rect class="bg" width="840" height="300" fill="#ffffff" rx="16"/>
|
|
22
|
+
|
|
23
|
+
<text class="title" x="40" y="56" font-size="30" font-weight="700" fill="#0d1117">vitest-auto-spy</text>
|
|
24
|
+
<text class="sub" x="40" y="84" font-size="16" fill="#57606a">One class-based API. Every Vitest-compatible runtime.</text>
|
|
25
|
+
|
|
26
|
+
<!-- source call -->
|
|
27
|
+
<rect class="card" x="40" y="120" width="330" height="70" rx="12" fill="url(#card)" stroke="#d0d7de"/>
|
|
28
|
+
<text class="code" x="62" y="153" font-size="16" font-family="ui-monospace, SFMono-Regular, Menlo, monospace" fill="#0d1117">createSpyFromClass(</text>
|
|
29
|
+
<text class="code" x="62" y="176" font-size="16" font-family="ui-monospace, SFMono-Regular, Menlo, monospace" fill="#0d1117">  UserService)</text>
|
|
30
|
+
|
|
31
|
+
<!-- arrow -->
|
|
32
|
+
<line class="arrow" x1="378" y1="155" x2="470" y2="155" stroke="#8c959f" stroke-width="2"/>
|
|
33
|
+
<polygon points="470,150 482,155 470,160" fill="#8c959f"/>
|
|
34
|
+
|
|
35
|
+
<!-- fully-typed spy -->
|
|
36
|
+
<rect class="card" x="490" y="120" width="310" height="70" rx="12" fill="url(#card)" stroke="#d0d7de"/>
|
|
37
|
+
<text class="title" x="512" y="150" font-size="16" font-weight="600" fill="#0d1117">Spy<UserService></text>
|
|
38
|
+
<text class="sub" x="512" y="174" font-size="13" fill="#57606a">typed methods + resolveWith / nextWith / calledWith</text>
|
|
39
|
+
|
|
40
|
+
<!-- runtime chips -->
|
|
41
|
+
<g>
|
|
42
|
+
<rect class="chip" x="40" y="228" width="240" height="46" rx="23" fill="#ddf4ff" stroke="#54aeff"/>
|
|
43
|
+
<text class="chipText" x="160" y="257" font-size="17" font-weight="600" text-anchor="middle" fill="#0969da">Vitest</text>
|
|
44
|
+
|
|
45
|
+
<rect class="chip" x="300" y="228" width="240" height="46" rx="23" fill="#ddf4ff" stroke="#54aeff"/>
|
|
46
|
+
<text class="chipText" x="420" y="257" font-size="17" font-weight="600" text-anchor="middle" fill="#0969da">Bun  (bun:test)</text>
|
|
47
|
+
|
|
48
|
+
<rect class="chip" x="560" y="228" width="240" height="46" rx="23" fill="#ddf4ff" stroke="#54aeff"/>
|
|
49
|
+
<text class="chipText" x="680" y="257" font-size="17" font-weight="600" text-anchor="middle" fill="#0969da">node:test</text>
|
|
50
|
+
</g>
|
|
51
|
+
</svg>
|
package/dist/angular.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var vitest=require('vitest'),testing=require('@angular/core/testing');var y;function b(e){y=e;}var
|
|
1
|
+
'use strict';var vitest=require('vitest'),testing=require('@angular/core/testing');var y;function b(e){y=e;}var E="No mock adapter registered. Import a runtime entry once before creating spies \u2014 'vitest-auto-spy' (default, Vitest) or a runtime variant such as 'vitest-auto-spy/bun'.";function a(){if(!y)throw new Error(E);return y}var k={createMockFn(e,t){let r=e?vitest.vi.fn(e):vitest.vi.fn();return t!==void 0&&r.mockName(t),r},spyOnGetter(e,t){return vitest.vi.spyOn(e,t,"get")},spyOnSetter(e,t){return vitest.vi.spyOn(e,t,"set")},getCalls(e){return e.mock.calls},reset(e){e.mockReset();}};function T(e,t){Object.defineProperty(e,t,{get(){},set(r){},configurable:true});}function S(e,t,r){let n=a();return r==="setter"?n.spyOnSetter(e,t):n.spyOnGetter(e,t)}function O(e,t,r){let n={getters:{},setters:{}};e.accessorSpies=n,t.forEach(o=>{T(e,o),n.getters[o]=S(e,o,"getter");}),r.forEach(o=>{Object.prototype.hasOwnProperty.call(e,o)||T(e,o),n.setters[o]=S(e,o,"setter");});}function _(e){return `'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}'`}function $(e,t){return Object.entries(e).map(([r,n])=>`${r}:${c(n,t)}`).join(",")}function H(e,t){return `new Map([${[...e.entries()].map(([n,o])=>`[${c(n,t)},${c(o,t)}]`).join(",")}])`}function K(e,t){if(t.has(e))return "[Circular]";t.add(e);let r;return e instanceof Date?r=`new Date(${e.getTime()})`:e instanceof Map?r=H(e,t):e instanceof Set?r=`new Set([${[...e].map(n=>c(n,t)).join(",")}])`:Array.isArray(e)?r=`[${e.map(n=>c(n,t)).join(",")}]`:r=`{${$(e,t)}}`,t.delete(e),r}function c(e,t=new WeakSet){return typeof e=="string"?_(e):typeof e=="bigint"?`${e}n`:typeof e=="symbol"?e.toString():typeof e=="function"?`[Function: ${e.name}]`:typeof e=="object"&&e!==null?K(e,t):Object.is(e,-0)?"-0":String(e)}var f=class{#e={};set(t,r){this.#e[this.#t(t)]=r;}get(t){return this.#e[this.#t(t)]}#t(t){return c(t)}};var z=e=>`The function '${e}' was configured with 'mustBeCalledWith' and expects to be called with specific arguments. `,B="But the function was called without any arguments.",G=e=>{let t=c(e);return `But the actual arguments were: ${t.substring(1,t.length-1)}`},j={throwArgumentsError(e,t){let r=e.length===0?B:G(e);throw new Error(z(t)+r)}};var I="Observable spies require rxjs. Import 'vitest-auto-spy/rxjs' once (e.g. in your test setup) to enable observablePropsToSpyOn / nextWith / nextWithValues / throwWith / complete / returnSubject.";function C(){throw new Error(I);}function u(e,t){return Object.assign(e,t)}function D(e){return e.map(t=>({wrappedValue:t.delay===void 0?Promise.resolve(t.value):new Promise(r=>setTimeout(()=>r(t.value),t.delay))}))}function h(e,t){u(e,{resolveWith:r=>{t({value:Promise.resolve(r)});},rejectWith:r=>{t({value:r,_isRejectedPromise:true});},resolveWithPerCall:r=>{r.length!==0&&t({value:void 0,valuesPerCalls:D(r)});}});}function w(e,t){h(e,r=>{t.value=r.value,t._isRejectedPromise=r._isRejectedPromise??false,t.valuesPerCalls=r.valuesPerCalls??[];});}function M(e,t){h(e,r=>{e.argsToValuesMap.set(t,r);});}function q(e){return typeof e=="object"&&e!==null&&"value"in e}function F(e){if(e._isRejectedPromise)return Promise.reject(e.value);let t=e.valuesPerCalls?.shift();return t?t.wrappedValue:e.value}function v(e,t){let r=e.argsToValuesMap.get(t);return q(r)?{found:true,value:F(r)}:{found:false,value:void 0}}function N(e,t,r,n,o){if(e.wasConfigured){let s=v(e,n);if(s.found)return s.value}if(t.wasConfigured){let s=v(t,n);if(s.found)return s.value;j.throwArgumentsError(n,o);}return F(r)}function P(e,t){e.wasConfigured=true;let r=n=>{e.argsToValuesMap.set(t,{value:n});};return u(e,{mockReturnValue:r,returnValue:r}),M(e,t),e}function A(){return {wasConfigured:false,argsToValuesMap:new f}}function R(e){let t=A(),r=A(),n={value:void 0},o=a().createMockFn((...i)=>N(t,r,n,i,e),e);w(o,n);let s=u(o,{calledWith:(...i)=>P(t,i),mustBeCalledWith:(...i)=>P(r,i)});return s}var x={methodsToSpyOn:[],observablePropsToSpyOn:[],settersToSpyOn:[],gettersToSpyOn:[]};function U(e){let t=Object.getOwnPropertyDescriptors(e);return Object.keys(t).filter(r=>r!=="constructor"&&!t[r]?.get)}var V=new WeakMap;function L(e){let t=V.get(e);if(t)return t;let r=new Set,n=e;for(;n;){let s=Object.getPrototypeOf(n);s&&U(n).forEach(i=>r.add(i)),n=s;}let o=[...r];return V.set(e,o),o}function J(e){return e?Array.isArray(e)?{...x,methodsToSpyOn:e}:{methodsToSpyOn:e.methodsToSpyOn??[],observablePropsToSpyOn:e.observablePropsToSpyOn??[],settersToSpyOn:e.settersToSpyOn??[],gettersToSpyOn:e.gettersToSpyOn??[]}:{...x}}function W(e,t){let{methodsToSpyOn:r,observablePropsToSpyOn:n,settersToSpyOn:o,gettersToSpyOn:s}=J(t),i=r.length>0?r:L(e.prototype),p={};return n.forEach(l=>{p[l]=C().createPropSpy();}),O(p,s,o),i.forEach(l=>{p[l]=R(l);}),p}function Y(e,t){return {provide:e,useValue:W(e,t)}}function Q(e){return testing.TestBed.inject(e)}function Z(e,t,r){Object.defineProperty(e,t,{get:()=>r,configurable:true});}function ee(e,t,r){Object.defineProperty(e,t,{get:r,configurable:true});}function te(e,t){let r=a();Object.defineProperty(e,t,{get:r.createMockFn(),set:r.createMockFn(),configurable:true});}b(k);exports.injectSpy=Q;exports.mockAccessorsProp=te;exports.mockReadonlyProp=Z;exports.mockReadonlyPropGetter=ee;exports.provideAutoSpy=Y;
|
package/dist/angular.d.cts
CHANGED
package/dist/angular.d.ts
CHANGED
package/dist/angular.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-6LFQMHSX.js';import {a,
|
|
1
|
+
import {a as a$1}from'./chunk-6LFQMHSX.js';import {a as a$2}from'./chunk-WP2TFS53.js';import {a,c as c$1}from'./chunk-MQCVIN2A.js';import'./chunk-7IUYJ6ZW.js';import {TestBed}from'@angular/core/testing';function c(e,o){return {provide:e,useValue:a$2(e,o)}}function s(e){return TestBed.inject(e)}function y(e,o,r){Object.defineProperty(e,o,{get:()=>r,configurable:true});}function d(e,o,r){Object.defineProperty(e,o,{get:r,configurable:true});}function u(e,o){let r=c$1();Object.defineProperty(e,o,{get:r.createMockFn(),set:r.createMockFn(),configurable:true});}a(a$1);export{s as injectSpy,u as mockAccessorsProp,y as mockReadonlyProp,d as mockReadonlyPropGetter,c as provideAutoSpy};
|
package/dist/bun.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var bun_test=require('bun:test');function S({createMockFn:e,getCalls:t,reset:r}){return {createMockFn:e,spyOnGetter:(o,n)=>b(e,o,n,"get"),spyOnSetter:(o,n)=>b(e,o,n,"set"),getCalls:t,reset:r}}function b(e,t,r,o){let n=Object.getOwnPropertyDescriptor(t,r),s=o==="get"?n?.get:n?.set,i=e(s),c={configurable:true,enumerable:n?.enumerable??true};return n?.get&&(c.get=n.get),n?.set&&(c.set=n.set),o==="get"?c.get=i:c.set=i,Object.defineProperty(t,r,c),i}function w(e){return S({createMockFn:(r,o)=>{let n=e.mock(r??(()=>{}));return o!==void 0&&n.mockName&&n.mockName(o),n},getCalls:r=>r.mock.calls,reset:r=>r.mockReset()})}var y;function M(e){y=e;}var
|
|
1
|
+
'use strict';var bun_test=require('bun:test');function S({createMockFn:e,getCalls:t,reset:r}){return {createMockFn:e,spyOnGetter:(o,n)=>b(e,o,n,"get"),spyOnSetter:(o,n)=>b(e,o,n,"set"),getCalls:t,reset:r}}function b(e,t,r,o){let n=Object.getOwnPropertyDescriptor(t,r),s=o==="get"?n?.get:n?.set,i=e(s),c={configurable:true,enumerable:n?.enumerable??true};return n?.get&&(c.get=n.get),n?.set&&(c.set=n.set),o==="get"?c.get=i:c.set=i,Object.defineProperty(t,r,c),i}function w(e){return S({createMockFn:(r,o)=>{let n=e.mock(r??(()=>{}));return o!==void 0&&n.mockName&&n.mockName(o),n},getCalls:r=>r.mock.calls,reset:r=>r.mockReset()})}var y;function M(e){y=e;}var E="No mock adapter registered. Import a runtime entry once before creating spies \u2014 'vitest-auto-spy' (default, Vitest) or a runtime variant such as 'vitest-auto-spy/bun'.";function d(){if(!y)throw new Error(E);return y}function h(e,t){Object.defineProperty(e,t,{get(){},set(r){},configurable:true});}function O(e,t,r){let o=d();return r==="setter"?o.spyOnSetter(e,t):o.spyOnGetter(e,t)}function T(e,t,r){let o={getters:{},setters:{}};e.accessorSpies=o,t.forEach(n=>{h(e,n),o.getters[n]=O(e,n,"getter");}),r.forEach(n=>{Object.prototype.hasOwnProperty.call(e,n)||h(e,n),o.setters[n]=O(e,n,"setter");});}function _(e){return `'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}'`}function B(e,t){return Object.entries(e).map(([r,o])=>`${r}:${a(o,t)}`).join(",")}function H(e,t){return `new Map([${[...e.entries()].map(([o,n])=>`[${a(o,t)},${a(n,t)}]`).join(",")}])`}function $(e,t){if(t.has(e))return "[Circular]";t.add(e);let r;return e instanceof Date?r=`new Date(${e.getTime()})`:e instanceof Map?r=H(e,t):e instanceof Set?r=`new Set([${[...e].map(o=>a(o,t)).join(",")}])`:Array.isArray(e)?r=`[${e.map(o=>a(o,t)).join(",")}]`:r=`{${B(e,t)}}`,t.delete(e),r}function a(e,t=new WeakSet){return typeof e=="string"?_(e):typeof e=="bigint"?`${e}n`:typeof e=="symbol"?e.toString():typeof e=="function"?`[Function: ${e.name}]`:typeof e=="object"&&e!==null?$(e,t):Object.is(e,-0)?"-0":String(e)}var f=class{#e={};set(t,r){this.#e[this.#t(t)]=r;}get(t){return this.#e[this.#t(t)]}#t(t){return a(t)}};var z=e=>`The function '${e}' was configured with 'mustBeCalledWith' and expects to be called with specific arguments. `,D="But the function was called without any arguments.",I=e=>{let t=a(e);return `But the actual arguments were: ${t.substring(1,t.length-1)}`},m={throwArgumentsError(e,t){let r=e.length===0?D:I(e);throw new Error(z(t)+r)}};var G="Observable spies require rxjs. Import 'vitest-auto-spy/rxjs' once (e.g. in your test setup) to enable observablePropsToSpyOn / nextWith / nextWithValues / throwWith / complete / returnSubject.";function C(){throw new Error(G);}function u(e,t){return Object.assign(e,t)}function K(e){return e.map(t=>({wrappedValue:t.delay===void 0?Promise.resolve(t.value):new Promise(r=>setTimeout(()=>r(t.value),t.delay))}))}function j(e,t){u(e,{resolveWith:r=>{t({value:Promise.resolve(r)});},rejectWith:r=>{t({value:r,_isRejectedPromise:true});},resolveWithPerCall:r=>{r.length!==0&&t({value:void 0,valuesPerCalls:K(r)});}});}function F(e,t){j(e,r=>{t.value=r.value,t._isRejectedPromise=r._isRejectedPromise??false,t.valuesPerCalls=r.valuesPerCalls??[];});}function A(e,t){j(e,r=>{e.argsToValuesMap.set(t,r);});}function N(e){return typeof e=="object"&&e!==null&&"value"in e}function x(e){if(e._isRejectedPromise)return Promise.reject(e.value);let t=e.valuesPerCalls?.shift();return t?t.wrappedValue:e.value}function P(e,t){let r=e.argsToValuesMap.get(t);return N(r)?{found:true,value:x(r)}:{found:false,value:void 0}}function q(e,t,r,o,n){if(e.wasConfigured){let s=P(e,o);if(s.found)return s.value}if(t.wasConfigured){let s=P(t,o);if(s.found)return s.value;m.throwArgumentsError(o,n);}return x(r)}function R(e,t){e.wasConfigured=true;let r=o=>{e.argsToValuesMap.set(t,{value:o});};return u(e,{mockReturnValue:r,returnValue:r}),A(e,t),e}function v(){return {wasConfigured:false,argsToValuesMap:new f}}function p(e){let t=v(),r=v(),o={value:void 0},n=d().createMockFn((...i)=>q(t,r,o,i,e),e);F(n,o);let s=u(n,{calledWith:(...i)=>R(t,i),mustBeCalledWith:(...i)=>R(r,i)});return s}var V={methodsToSpyOn:[],observablePropsToSpyOn:[],settersToSpyOn:[],gettersToSpyOn:[]};function U(e){let t=Object.getOwnPropertyDescriptors(e);return Object.keys(t).filter(r=>r!=="constructor"&&!t[r]?.get)}var W=new WeakMap;function L(e){let t=W.get(e);if(t)return t;let r=new Set,o=e;for(;o;){let s=Object.getPrototypeOf(o);s&&U(o).forEach(i=>r.add(i)),o=s;}let n=[...r];return W.set(e,n),n}function J(e){return e?Array.isArray(e)?{...V,methodsToSpyOn:e}:{methodsToSpyOn:e.methodsToSpyOn??[],observablePropsToSpyOn:e.observablePropsToSpyOn??[],settersToSpyOn:e.settersToSpyOn??[],gettersToSpyOn:e.gettersToSpyOn??[]}:{...V}}function X(e,t){let{methodsToSpyOn:r,observablePropsToSpyOn:o,settersToSpyOn:n,gettersToSpyOn:s}=J(t),i=r.length>0?r:L(e.prototype),c={};return o.forEach(l=>{c[l]=C().createPropSpy();}),T(c,s,n),i.forEach(l=>{c[l]=p(l);}),c}function Y(e={}){let t=new Map;for(let o of Reflect.ownKeys(e))t.set(o,Reflect.get(e,o));let r={get(o,n){if(t.has(n))return t.get(n);if(typeof n=="symbol"||n==="then"||n==="constructor")return;let s=p(String(n));return t.set(n,s),s},set(o,n,s){return t.set(n,s),true},has(o,n){return t.has(n)},ownKeys(){return [...t.keys()]},getOwnPropertyDescriptor(o,n){if(t.has(n))return {configurable:true,enumerable:true,value:t.get(n),writable:true}}};return new Proxy({},r)}M(w({mock:bun_test.mock}));exports.createAutoMock=Y;exports.createFunctionSpy=p;exports.createSpyFromClass=X;exports.errorHandler=m;
|
package/dist/bun.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ClassType, a as ClassSpyConfiguration, O as OnlyMethodKeysOf, S as Spy, F as Func, i as AddSpyMethodsByReturnTypes } from './types-
|
|
2
|
-
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, b as CompleteValueConfig, E as ErrorValueConfig, N as NextValueConfig, j as OnlyObservablePropsOf, k as OnlyPropsOf, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-
|
|
1
|
+
import { C as ClassType, a as ClassSpyConfiguration, O as OnlyMethodKeysOf, S as Spy, F as Func, i as AddSpyMethodsByReturnTypes } from './types-Cv3L71P0.cjs';
|
|
2
|
+
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, b as CompleteValueConfig, E as ErrorValueConfig, N as NextValueConfig, j as OnlyObservablePropsOf, k as OnlyPropsOf, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-Cv3L71P0.cjs';
|
|
3
3
|
import 'rxjs';
|
|
4
4
|
import 'vitest';
|
|
5
5
|
|
package/dist/bun.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ClassType, a as ClassSpyConfiguration, O as OnlyMethodKeysOf, S as Spy, F as Func, i as AddSpyMethodsByReturnTypes } from './types-
|
|
2
|
-
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, b as CompleteValueConfig, E as ErrorValueConfig, N as NextValueConfig, j as OnlyObservablePropsOf, k as OnlyPropsOf, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-
|
|
1
|
+
import { C as ClassType, a as ClassSpyConfiguration, O as OnlyMethodKeysOf, S as Spy, F as Func, i as AddSpyMethodsByReturnTypes } from './types-Cv3L71P0.js';
|
|
2
|
+
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, b as CompleteValueConfig, E as ErrorValueConfig, N as NextValueConfig, j as OnlyObservablePropsOf, k as OnlyPropsOf, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-Cv3L71P0.js';
|
|
3
3
|
import 'rxjs';
|
|
4
4
|
import 'vitest';
|
|
5
5
|
|
package/dist/bun.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-IPBQZ4JC.js';export{a as createAutoMock}from'./chunk-
|
|
1
|
+
import {a as a$1}from'./chunk-IPBQZ4JC.js';export{a as createAutoMock}from'./chunk-HVN6A3AX.js';export{a as createSpyFromClass}from'./chunk-WP2TFS53.js';import {a}from'./chunk-MQCVIN2A.js';export{e as createFunctionSpy,d as errorHandler}from'./chunk-MQCVIN2A.js';import'./chunk-7IUYJ6ZW.js';import {mock}from'bun:test';function r(k){return a$1({createMockFn:(o,n)=>{let e=k.mock(o??(()=>{}));return n!==void 0&&e.mockName&&e.mockName(n),e},getCalls:o=>o.mock.calls,reset:o=>o.mockReset()})}a(r({mock:mock}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {e}from'./chunk-MQCVIN2A.js';function s(u={}){let r=new Map;for(let t of Reflect.ownKeys(u))r.set(t,Reflect.get(u,t));let a={get(t,e$1){if(r.has(e$1))return r.get(e$1);if(typeof e$1=="symbol"||e$1==="then"||e$1==="constructor")return;let n=e(String(e$1));return r.set(e$1,n),n},set(t,e,n){return r.set(e,n),true},has(t,e){return r.has(e)},ownKeys(){return [...r.keys()]},getOwnPropertyDescriptor(t,e){if(r.has(e))return {configurable:true,enumerable:true,value:r.get(e),writable:true}}};return new Proxy({},a)}export{s as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {b as b$1,d as d$1}from'./chunk-7IUYJ6ZW.js';var c;function W(e){c=e;}function x(){return c!==void 0}var b="No mock adapter registered. Import a runtime entry once before creating spies \u2014 'vitest-auto-spy' (default, Vitest) or a runtime variant such as 'vitest-auto-spy/bun'.";function d(){if(!c)throw new Error(b);return c}function j(e){return `'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}'`}function M(e,t){return Object.entries(e).map(([n,r])=>`${n}:${o(r,t)}`).join(",")}function T(e,t){return `new Map([${[...e.entries()].map(([r,i])=>`[${o(r,t)},${o(i,t)}]`).join(",")}])`}function S(e,t){if(t.has(e))return "[Circular]";t.add(e);let n;return e instanceof Date?n=`new Date(${e.getTime()})`:e instanceof Map?n=T(e,t):e instanceof Set?n=`new Set([${[...e].map(r=>o(r,t)).join(",")}])`:Array.isArray(e)?n=`[${e.map(r=>o(r,t)).join(",")}]`:n=`{${M(e,t)}}`,t.delete(e),n}function o(e,t=new WeakSet){return typeof e=="string"?j(e):typeof e=="bigint"?`${e}n`:typeof e=="symbol"?e.toString():typeof e=="function"?`[Function: ${e.name}]`:typeof e=="object"&&e!==null?S(e,t):Object.is(e,-0)?"-0":String(e)}var V=e=>`The function '${e}' was configured with 'mustBeCalledWith' and expects to be called with specific arguments. `,F="But the function was called without any arguments.",P=e=>{let t=o(e);return `But the actual arguments were: ${t.substring(1,t.length-1)}`},f={throwArgumentsError(e,t){let n=e.length===0?F:P(e);throw new Error(V(t)+n)}};var l=class{#e={};set(t,n){this.#e[this.#t(t)]=n;}get(t){return this.#e[this.#t(t)]}#t(t){return o(t)}};function R(e){return e.map(t=>({wrappedValue:t.delay===void 0?Promise.resolve(t.value):new Promise(n=>setTimeout(()=>n(t.value),t.delay))}))}function m(e,t){d$1(e,{resolveWith:n=>{t({value:Promise.resolve(n)});},rejectWith:n=>{t({value:n,_isRejectedPromise:true});},resolveWithPerCall:n=>{n.length!==0&&t({value:void 0,valuesPerCalls:R(n)});}});}function g(e,t){m(e,n=>{t.value=n.value,t._isRejectedPromise=n._isRejectedPromise??false,t.valuesPerCalls=n.valuesPerCalls??[];});}function y(e,t){m(e,n=>{e.argsToValuesMap.set(t,n);});}function A(e){return typeof e=="object"&&e!==null&&"value"in e}function h(e){if(e._isRejectedPromise)return Promise.reject(e.value);let t=e.valuesPerCalls?.shift();return t?t.wrappedValue:e.value}function k(e,t){let n=e.argsToValuesMap.get(t);return A(n)?{found:true,value:h(n)}:{found:false,value:void 0}}function O(e,t,n,r,i){if(e.wasConfigured){let u=k(e,r);if(u.found)return u.value}if(t.wasConfigured){let u=k(t,r);if(u.found)return u.value;f.throwArgumentsError(r,i);}return h(n)}function w(e,t){e.wasConfigured=true;let n=r=>{e.argsToValuesMap.set(t,{value:r});};return d$1(e,{mockReturnValue:n,returnValue:n}),y(e,t),b$1()?.addToCalledWithObject(e,t),e}function C(){return {wasConfigured:false,argsToValuesMap:new l}}function K(e){let t=C(),n=C(),r={value:void 0},i=d().createMockFn((...a)=>O(t,n,r,a,e),e);g(i,r),b$1()?.addToFunctionSpy(i,r);let u=d$1(i,{calledWith:(...a)=>w(t,a),mustBeCalledWith:(...a)=>w(n,a)});return u}export{W as a,x as b,d as c,f as d,K as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {e,c as c$1}from'./chunk-MQCVIN2A.js';import {c}from'./chunk-7IUYJ6ZW.js';function u(e,t){Object.defineProperty(e,t,{get(){},set(r){},configurable:true});}function f(e,t,r){let s=c$1();return r==="setter"?s.spyOnSetter(e,t):s.spyOnGetter(e,t)}function l(e,t,r){let s={getters:{},setters:{}};e.accessorSpies=s,t.forEach(o=>{u(e,o),s.getters[o]=f(e,o,"getter");}),r.forEach(o=>{Object.prototype.hasOwnProperty.call(e,o)||u(e,o),s.setters[o]=f(e,o,"setter");});}var d={methodsToSpyOn:[],observablePropsToSpyOn:[],settersToSpyOn:[],gettersToSpyOn:[]};function S(e){let t=Object.getOwnPropertyDescriptors(e);return Object.keys(t).filter(r=>r!=="constructor"&&!t[r]?.get)}var O=new WeakMap;function T(e){let t=O.get(e);if(t)return t;let r=new Set,s=e;for(;s;){let n=Object.getPrototypeOf(s);n&&S(s).forEach(p=>r.add(p)),s=n;}let o=[...r];return O.set(e,o),o}function b(e){return e?Array.isArray(e)?{...d,methodsToSpyOn:e}:{methodsToSpyOn:e.methodsToSpyOn??[],observablePropsToSpyOn:e.observablePropsToSpyOn??[],settersToSpyOn:e.settersToSpyOn??[],gettersToSpyOn:e.gettersToSpyOn??[]}:{...d}}function M(e$1,t){let{methodsToSpyOn:r,observablePropsToSpyOn:s,settersToSpyOn:o,gettersToSpyOn:n}=b(t),p=r.length>0?r:T(e$1.prototype),c$1={};return s.forEach(i=>{c$1[i]=c().createPropSpy();}),l(c$1,n,o),p.forEach(i=>{c$1[i]=e(i);}),c$1}export{M as a};
|
package/dist/console.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var vitest=require('vitest');function A(e){return `'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}'`}function W(e,o){return Object.entries(e).map(([t,n])=>`${t}:${r(n,o)}`).join(",")}function P(e,o){return `new Map([${[...e.entries()].map(([n,s])=>`[${r(n,o)},${r(s,o)}]`).join(",")}])`}function E(e,o){if(o.has(e))return "[Circular]";o.add(e);let t;return e instanceof Date?t=`new Date(${e.getTime()})`:e instanceof Map?t=P(e,o):e instanceof Set?t=`new Set([${[...e].map(n=>r(n,o)).join(",")}])`:Array.isArray(e)?t=`[${e.map(n=>r(n,o)).join(",")}]`:t=`{${W(e,o)}}`,o.delete(e),t}function r(e,o=new WeakSet){return typeof e=="string"?A(e):typeof e=="bigint"?`${e}n`:typeof e=="symbol"?e.toString():typeof e=="function"?`[Function: ${e.name}]`:typeof e=="object"&&e!==null?E(e,o):Object.is(e,-0)?"-0":String(e)}var l=class{#e={};set(o,t){this.#e[this.#o(o)]=t;}get(o){return this.#e[this.#o(o)]}#o(o){return r(o)}};var $=e=>`The function '${e}' was configured with 'mustBeCalledWith' and expects to be called with specific arguments. `,_="But the function was called without any arguments.",H=e=>{let o=r(e);return `But the actual arguments were: ${o.substring(1,o.length-1)}`},M={throwArgumentsError(e,o){let t=e.length===0?_:H(e);throw new Error($(o)+t)}};var d;function k(e){d=e;}function b(){return d!==void 0}var B="No mock adapter registered. Import a runtime entry once before creating spies \u2014 'vitest-auto-spy' (default, Vitest) or a runtime variant such as 'vitest-auto-spy/bun'.";function f(){if(!d)throw new Error(B);return d}function u(e,o){return Object.assign(e,o)}function I(e){return e.map(o=>({wrappedValue:o.delay===void 0?Promise.resolve(o.value):new Promise(t=>setTimeout(()=>t(o.value),o.delay))}))}function h(e,o){u(e,{resolveWith:t=>{o({value:Promise.resolve(t)});},rejectWith:t=>{o({value:t,_isRejectedPromise:true});},resolveWithPerCall:t=>{t.length!==0&&o({value:void 0,valuesPerCalls:I(t)});}});}function w(e,o){h(e,t=>{o.value=t.value,o._isRejectedPromise=t._isRejectedPromise??false,o.valuesPerCalls=t.valuesPerCalls??[];});}function j(e,o){h(e,t=>{e.argsToValuesMap.set(o,t);});}function D(e){return typeof e=="object"&&e!==null&&"value"in e}function O(e){if(e._isRejectedPromise)return Promise.reject(e.value);let o=e.valuesPerCalls?.shift();return o?o.wrappedValue:e.value}function T(e,o){let t=e.argsToValuesMap.get(o);return D(t)?{found:true,value:O(t)}:{found:false,value:void 0}}function G(e,o,t,n,s){if(e.wasConfigured){let p=T(e,n);if(p.found)return p.value}if(o.wasConfigured){let p=T(o,n);if(p.found)return p.value;M.throwArgumentsError(n,s);}return O(t)}function F(e,o){e.wasConfigured=true;let t=n=>{e.argsToValuesMap.set(o,{value:n});};return u(e,{mockReturnValue:t,returnValue:t}),j(e,o),e}function v(){return {wasConfigured:false,argsToValuesMap:new l}}function x(e){let o=v(),t=v(),n={value:void 0},s=f().createMockFn((...a)=>G(o,t,n,a,e),e);w(s,n);let p=u(s,{calledWith:(...a)=>F(o,a),mustBeCalledWith:(...a)=>F(t,a)});return p}var S=new Map,C=new Map,c;function L(e){return console[e]}function R(e,o){console[e]=o;}function i(e){S.set(e,L(e));let o=x(`console.${e}`);return R(e,o),C.set(e,o),o}function g(){return c||(c={consoleDebugSpy:i("debug"),consoleErrorSpy:i("error"),consoleInfoSpy:i("info"),consoleLogSpy:i("log"),consoleTimeEndSpy:i("timeEnd"),consoleTimeSpy:i("time"),consoleTraceSpy:i("trace"),consoleWarnSpy:i("warn")},c)}function N(){let e=f();for(let o of C.values())e.reset(o);}function q(){for(let[e,o]of S)R(e,o);S.clear(),C.clear(),c=void 0;}var V={createMockFn(e,o){let t=e?vitest.vi.fn(e):vitest.vi.fn();return o!==void 0&&t.mockName(o),t},spyOnGetter(e,o){return vitest.vi.spyOn(e,o,"get")},spyOnSetter(e,o){return vitest.vi.spyOn(e,o,"set")},getCalls(e){return e.mock.calls},reset(e){e.mockReset();}};b()||k(V);var {consoleDebugSpy:ge,consoleErrorSpy:Me,consoleInfoSpy:ke,consoleLogSpy:be,consoleTimeEndSpy:he,consoleTimeSpy:we,consoleTraceSpy:je,consoleWarnSpy:Te}=g();exports.consoleDebugSpy=ge;exports.consoleErrorSpy=Me;exports.consoleInfoSpy=ke;exports.consoleLogSpy=be;exports.consoleTimeEndSpy=he;exports.consoleTimeSpy=we;exports.consoleTraceSpy=je;exports.consoleWarnSpy=Te;exports.installConsoleSpies=g;exports.resetConsoleSpies=N;exports.restoreConsole=q;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { i as AddSpyMethodsByReturnTypes } from './types-Cv3L71P0.cjs';
|
|
2
|
+
import 'rxjs';
|
|
3
|
+
import 'vitest';
|
|
4
|
+
|
|
5
|
+
/** The call shape shared by every spied console method. */
|
|
6
|
+
type ConsoleMethodFn = (...data: unknown[]) => void;
|
|
7
|
+
/** A spy standing in for one `console` method: silent, with all sync helpers attached. */
|
|
8
|
+
type ConsoleMethodSpy = AddSpyMethodsByReturnTypes<ConsoleMethodFn>;
|
|
9
|
+
/** The bag of installed console spies, one per spied method. */
|
|
10
|
+
interface ConsoleSpies {
|
|
11
|
+
consoleDebugSpy: ConsoleMethodSpy;
|
|
12
|
+
consoleErrorSpy: ConsoleMethodSpy;
|
|
13
|
+
consoleInfoSpy: ConsoleMethodSpy;
|
|
14
|
+
consoleLogSpy: ConsoleMethodSpy;
|
|
15
|
+
consoleTimeEndSpy: ConsoleMethodSpy;
|
|
16
|
+
consoleTimeSpy: ConsoleMethodSpy;
|
|
17
|
+
consoleTraceSpy: ConsoleMethodSpy;
|
|
18
|
+
consoleWarnSpy: ConsoleMethodSpy;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Replace the spied console methods with silent typed spies. Idempotent:
|
|
22
|
+
* repeated calls return the already-installed bag.
|
|
23
|
+
*/
|
|
24
|
+
declare function installConsoleSpies(): ConsoleSpies;
|
|
25
|
+
/** Clear the recorded calls of every installed console spy (the spies stay installed). */
|
|
26
|
+
declare function resetConsoleSpies(): void;
|
|
27
|
+
/** Put the original console methods back and forget the installed spies. */
|
|
28
|
+
declare function restoreConsole(): void;
|
|
29
|
+
|
|
30
|
+
declare const consoleDebugSpy: ConsoleMethodSpy;
|
|
31
|
+
declare const consoleErrorSpy: ConsoleMethodSpy;
|
|
32
|
+
declare const consoleInfoSpy: ConsoleMethodSpy;
|
|
33
|
+
declare const consoleLogSpy: ConsoleMethodSpy;
|
|
34
|
+
declare const consoleTimeEndSpy: ConsoleMethodSpy;
|
|
35
|
+
declare const consoleTimeSpy: ConsoleMethodSpy;
|
|
36
|
+
declare const consoleTraceSpy: ConsoleMethodSpy;
|
|
37
|
+
declare const consoleWarnSpy: ConsoleMethodSpy;
|
|
38
|
+
|
|
39
|
+
export { type ConsoleMethodSpy, type ConsoleSpies, consoleDebugSpy, consoleErrorSpy, consoleInfoSpy, consoleLogSpy, consoleTimeEndSpy, consoleTimeSpy, consoleTraceSpy, consoleWarnSpy, installConsoleSpies, resetConsoleSpies, restoreConsole };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { i as AddSpyMethodsByReturnTypes } from './types-Cv3L71P0.js';
|
|
2
|
+
import 'rxjs';
|
|
3
|
+
import 'vitest';
|
|
4
|
+
|
|
5
|
+
/** The call shape shared by every spied console method. */
|
|
6
|
+
type ConsoleMethodFn = (...data: unknown[]) => void;
|
|
7
|
+
/** A spy standing in for one `console` method: silent, with all sync helpers attached. */
|
|
8
|
+
type ConsoleMethodSpy = AddSpyMethodsByReturnTypes<ConsoleMethodFn>;
|
|
9
|
+
/** The bag of installed console spies, one per spied method. */
|
|
10
|
+
interface ConsoleSpies {
|
|
11
|
+
consoleDebugSpy: ConsoleMethodSpy;
|
|
12
|
+
consoleErrorSpy: ConsoleMethodSpy;
|
|
13
|
+
consoleInfoSpy: ConsoleMethodSpy;
|
|
14
|
+
consoleLogSpy: ConsoleMethodSpy;
|
|
15
|
+
consoleTimeEndSpy: ConsoleMethodSpy;
|
|
16
|
+
consoleTimeSpy: ConsoleMethodSpy;
|
|
17
|
+
consoleTraceSpy: ConsoleMethodSpy;
|
|
18
|
+
consoleWarnSpy: ConsoleMethodSpy;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Replace the spied console methods with silent typed spies. Idempotent:
|
|
22
|
+
* repeated calls return the already-installed bag.
|
|
23
|
+
*/
|
|
24
|
+
declare function installConsoleSpies(): ConsoleSpies;
|
|
25
|
+
/** Clear the recorded calls of every installed console spy (the spies stay installed). */
|
|
26
|
+
declare function resetConsoleSpies(): void;
|
|
27
|
+
/** Put the original console methods back and forget the installed spies. */
|
|
28
|
+
declare function restoreConsole(): void;
|
|
29
|
+
|
|
30
|
+
declare const consoleDebugSpy: ConsoleMethodSpy;
|
|
31
|
+
declare const consoleErrorSpy: ConsoleMethodSpy;
|
|
32
|
+
declare const consoleInfoSpy: ConsoleMethodSpy;
|
|
33
|
+
declare const consoleLogSpy: ConsoleMethodSpy;
|
|
34
|
+
declare const consoleTimeEndSpy: ConsoleMethodSpy;
|
|
35
|
+
declare const consoleTimeSpy: ConsoleMethodSpy;
|
|
36
|
+
declare const consoleTraceSpy: ConsoleMethodSpy;
|
|
37
|
+
declare const consoleWarnSpy: ConsoleMethodSpy;
|
|
38
|
+
|
|
39
|
+
export { type ConsoleMethodSpy, type ConsoleSpies, consoleDebugSpy, consoleErrorSpy, consoleInfoSpy, consoleLogSpy, consoleTimeEndSpy, consoleTimeSpy, consoleTraceSpy, consoleWarnSpy, installConsoleSpies, resetConsoleSpies, restoreConsole };
|
package/dist/console.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {a as a$2}from'./chunk-6LFQMHSX.js';import {b as b$1,a as a$1,e,c}from'./chunk-MQCVIN2A.js';import'./chunk-7IUYJ6ZW.js';var t=new Map,p=new Map,s;function a(o){return console[o]}function y(o,e){console[o]=e;}function n(o){t.set(o,a(o));let e$1=e(`console.${o}`);return y(o,e$1),p.set(o,e$1),e$1}function l(){return s||(s={consoleDebugSpy:n("debug"),consoleErrorSpy:n("error"),consoleInfoSpy:n("info"),consoleLogSpy:n("log"),consoleTimeEndSpy:n("timeEnd"),consoleTimeSpy:n("time"),consoleTraceSpy:n("trace"),consoleWarnSpy:n("warn")},s)}function C(){let o=c();for(let e of p.values())o.reset(e);}function M(){for(let[o,e]of t)y(o,e);t.clear(),p.clear(),s=void 0;}b$1()||a$1(a$2);var {consoleDebugSpy:x,consoleErrorSpy:E,consoleInfoSpy:F,consoleLogSpy:v,consoleTimeEndSpy:b,consoleTimeSpy:A,consoleTraceSpy:k,consoleWarnSpy:w}=l();export{x as consoleDebugSpy,E as consoleErrorSpy,F as consoleInfoSpy,v as consoleLogSpy,b as consoleTimeEndSpy,A as consoleTimeSpy,k as consoleTraceSpy,w as consoleWarnSpy,l as installConsoleSpies,C as resetConsoleSpies,M as restoreConsole};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var vitest=require('vitest');var g;function S(e){g=e;}var
|
|
1
|
+
'use strict';var vitest=require('vitest');var g;function S(e){g=e;}var W="No mock adapter registered. Import a runtime entry once before creating spies \u2014 'vitest-auto-spy' (default, Vitest) or a runtime variant such as 'vitest-auto-spy/bun'.";function d(){if(!g)throw new Error(W);return g}var w={createMockFn(e,t){let r=e?vitest.vi.fn(e):vitest.vi.fn();return t!==void 0&&r.mockName(t),r},spyOnGetter(e,t){return vitest.vi.spyOn(e,t,"get")},spyOnSetter(e,t){return vitest.vi.spyOn(e,t,"set")},getCalls(e){return e.mock.calls},reset(e){e.mockReset();}};function h(e,t){Object.defineProperty(e,t,{get(){},set(r){},configurable:true});}function O(e,t,r){let n=d();return r==="setter"?n.spyOnSetter(e,t):n.spyOnGetter(e,t)}function T(e,t,r){let n={getters:{},setters:{}};e.accessorSpies=n,t.forEach(o=>{h(e,o),n.getters[o]=O(e,o,"getter");}),r.forEach(o=>{Object.prototype.hasOwnProperty.call(e,o)||h(e,o),n.setters[o]=O(e,o,"setter");});}function E(e){return `'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}'`}function _(e,t){return Object.entries(e).map(([r,n])=>`${r}:${u(n,t)}`).join(",")}function H(e,t){return `new Map([${[...e.entries()].map(([n,o])=>`[${u(n,t)},${u(o,t)}]`).join(",")}])`}function $(e,t){if(t.has(e))return "[Circular]";t.add(e);let r;return e instanceof Date?r=`new Date(${e.getTime()})`:e instanceof Map?r=H(e,t):e instanceof Set?r=`new Set([${[...e].map(n=>u(n,t)).join(",")}])`:Array.isArray(e)?r=`[${e.map(n=>u(n,t)).join(",")}]`:r=`{${_(e,t)}}`,t.delete(e),r}function u(e,t=new WeakSet){return typeof e=="string"?E(e):typeof e=="bigint"?`${e}n`:typeof e=="symbol"?e.toString():typeof e=="function"?`[Function: ${e.name}]`:typeof e=="object"&&e!==null?$(e,t):Object.is(e,-0)?"-0":String(e)}var y=class{#e={};set(t,r){this.#e[this.#t(t)]=r;}get(t){return this.#e[this.#t(t)]}#t(t){return u(t)}};var z=e=>`The function '${e}' was configured with 'mustBeCalledWith' and expects to be called with specific arguments. `,B="But the function was called without any arguments.",I=e=>{let t=u(e);return `But the actual arguments were: ${t.substring(1,t.length-1)}`},m={throwArgumentsError(e,t){let r=e.length===0?B:I(e);throw new Error(z(t)+r)}};var G="Observable spies require rxjs. Import 'vitest-auto-spy/rxjs' once (e.g. in your test setup) to enable observablePropsToSpyOn / nextWith / nextWithValues / throwWith / complete / returnSubject.";function M(){throw new Error(G);}function c(e,t){return Object.assign(e,t)}function K(e){return e.map(t=>({wrappedValue:t.delay===void 0?Promise.resolve(t.value):new Promise(r=>setTimeout(()=>r(t.value),t.delay))}))}function j(e,t){c(e,{resolveWith:r=>{t({value:Promise.resolve(r)});},rejectWith:r=>{t({value:r,_isRejectedPromise:true});},resolveWithPerCall:r=>{r.length!==0&&t({value:void 0,valuesPerCalls:K(r)});}});}function C(e,t){j(e,r=>{t.value=r.value,t._isRejectedPromise=r._isRejectedPromise??false,t.valuesPerCalls=r.valuesPerCalls??[];});}function v(e,t){j(e,r=>{e.argsToValuesMap.set(t,r);});}function D(e){return typeof e=="object"&&e!==null&&"value"in e}function A(e){if(e._isRejectedPromise)return Promise.reject(e.value);let t=e.valuesPerCalls?.shift();return t?t.wrappedValue:e.value}function F(e,t){let r=e.argsToValuesMap.get(t);return D(r)?{found:true,value:A(r)}:{found:false,value:void 0}}function q(e,t,r,n,o){if(e.wasConfigured){let s=F(e,n);if(s.found)return s.value}if(t.wasConfigured){let s=F(t,n);if(s.found)return s.value;m.throwArgumentsError(n,o);}return A(r)}function P(e,t){e.wasConfigured=true;let r=n=>{e.argsToValuesMap.set(t,{value:n});};return c(e,{mockReturnValue:r,returnValue:r}),v(e,t),e}function R(){return {wasConfigured:false,argsToValuesMap:new y}}function a(e){let t=R(),r=R(),n={value:void 0},o=d().createMockFn((...i)=>q(t,r,n,i,e),e);C(o,n);let s=c(o,{calledWith:(...i)=>P(t,i),mustBeCalledWith:(...i)=>P(r,i)});return s}var x={methodsToSpyOn:[],observablePropsToSpyOn:[],settersToSpyOn:[],gettersToSpyOn:[]};function N(e){let t=Object.getOwnPropertyDescriptors(e);return Object.keys(t).filter(r=>r!=="constructor"&&!t[r]?.get)}var V=new WeakMap;function U(e){let t=V.get(e);if(t)return t;let r=new Set,n=e;for(;n;){let s=Object.getPrototypeOf(n);s&&N(n).forEach(i=>r.add(i)),n=s;}let o=[...r];return V.set(e,o),o}function L(e){return e?Array.isArray(e)?{...x,methodsToSpyOn:e}:{methodsToSpyOn:e.methodsToSpyOn??[],observablePropsToSpyOn:e.observablePropsToSpyOn??[],settersToSpyOn:e.settersToSpyOn??[],gettersToSpyOn:e.gettersToSpyOn??[]}:{...x}}function J(e,t){let{methodsToSpyOn:r,observablePropsToSpyOn:n,settersToSpyOn:o,gettersToSpyOn:s}=L(t),i=r.length>0?r:U(e.prototype),p={};return n.forEach(l=>{p[l]=M().createPropSpy();}),T(p,s,o),i.forEach(l=>{p[l]=a(l);}),p}function X(e={}){let t=new Map;for(let n of Reflect.ownKeys(e))t.set(n,Reflect.get(e,n));let r={get(n,o){if(t.has(o))return t.get(o);if(typeof o=="symbol"||o==="then"||o==="constructor")return;let s=a(String(o));return t.set(o,s),s},set(n,o,s){return t.set(o,s),true},has(n,o){return t.has(o)},ownKeys(){return [...t.keys()]},getOwnPropertyDescriptor(n,o){if(t.has(o))return {configurable:true,enumerable:true,value:t.get(o),writable:true}}};return new Proxy({},r)}S(w);exports.createAutoMock=X;exports.createFunctionSpy=a;exports.createSpyFromClass=J;exports.errorHandler=m;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, a as ClassSpyConfiguration, C as ClassType, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, O as OnlyMethodKeysOf, j as OnlyObservablePropsOf, k as OnlyPropsOf, S as Spy, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-
|
|
1
|
+
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, a as ClassSpyConfiguration, C as ClassType, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, O as OnlyMethodKeysOf, j as OnlyObservablePropsOf, k as OnlyPropsOf, S as Spy, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-Cv3L71P0.cjs';
|
|
2
2
|
export { createAutoMock, createFunctionSpy, createSpyFromClass, errorHandler } from './bun.cjs';
|
|
3
3
|
import 'rxjs';
|
|
4
4
|
import 'vitest';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, a as ClassSpyConfiguration, C as ClassType, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, O as OnlyMethodKeysOf, j as OnlyObservablePropsOf, k as OnlyPropsOf, S as Spy, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-
|
|
1
|
+
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, a as ClassSpyConfiguration, C as ClassType, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, O as OnlyMethodKeysOf, j as OnlyObservablePropsOf, k as OnlyPropsOf, S as Spy, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-Cv3L71P0.js';
|
|
2
2
|
export { createAutoMock, createFunctionSpy, createSpyFromClass, errorHandler } from './bun.js';
|
|
3
3
|
import 'rxjs';
|
|
4
4
|
import 'vitest';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-6LFQMHSX.js';export{a as createAutoMock}from'./chunk-
|
|
1
|
+
import {a as a$1}from'./chunk-6LFQMHSX.js';export{a as createAutoMock}from'./chunk-HVN6A3AX.js';export{a as createSpyFromClass}from'./chunk-WP2TFS53.js';import {a}from'./chunk-MQCVIN2A.js';export{e as createFunctionSpy,d as errorHandler}from'./chunk-MQCVIN2A.js';import'./chunk-7IUYJ6ZW.js';a(a$1);
|
package/dist/nestjs.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var vitest=require('vitest');var y;function b(e){y=e;}var
|
|
1
|
+
'use strict';var vitest=require('vitest');var y;function b(e){y=e;}var E="No mock adapter registered. Import a runtime entry once before creating spies \u2014 'vitest-auto-spy' (default, Vitest) or a runtime variant such as 'vitest-auto-spy/bun'.";function l(){if(!y)throw new Error(E);return y}var k={createMockFn(e,t){let r=e?vitest.vi.fn(e):vitest.vi.fn();return t!==void 0&&r.mockName(t),r},spyOnGetter(e,t){return vitest.vi.spyOn(e,t,"get")},spyOnSetter(e,t){return vitest.vi.spyOn(e,t,"set")},getCalls(e){return e.mock.calls},reset(e){e.mockReset();}};function S(e,t){Object.defineProperty(e,t,{get(){},set(r){},configurable:true});}function T(e,t,r){let n=l();return r==="setter"?n.spyOnSetter(e,t):n.spyOnGetter(e,t)}function O(e,t,r){let n={getters:{},setters:{}};e.accessorSpies=n,t.forEach(o=>{S(e,o),n.getters[o]=T(e,o,"getter");}),r.forEach(o=>{Object.prototype.hasOwnProperty.call(e,o)||S(e,o),n.setters[o]=T(e,o,"setter");});}function _(e){return `'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}'`}function $(e,t){return Object.entries(e).map(([r,n])=>`${r}:${u(n,t)}`).join(",")}function H(e,t){return `new Map([${[...e.entries()].map(([n,o])=>`[${u(n,t)},${u(o,t)}]`).join(",")}])`}function z(e,t){if(t.has(e))return "[Circular]";t.add(e);let r;return e instanceof Date?r=`new Date(${e.getTime()})`:e instanceof Map?r=H(e,t):e instanceof Set?r=`new Set([${[...e].map(n=>u(n,t)).join(",")}])`:Array.isArray(e)?r=`[${e.map(n=>u(n,t)).join(",")}]`:r=`{${$(e,t)}}`,t.delete(e),r}function u(e,t=new WeakSet){return typeof e=="string"?_(e):typeof e=="bigint"?`${e}n`:typeof e=="symbol"?e.toString():typeof e=="function"?`[Function: ${e.name}]`:typeof e=="object"&&e!==null?z(e,t):Object.is(e,-0)?"-0":String(e)}var f=class{#e={};set(t,r){this.#e[this.#t(t)]=r;}get(t){return this.#e[this.#t(t)]}#t(t){return u(t)}};var N=e=>`The function '${e}' was configured with 'mustBeCalledWith' and expects to be called with specific arguments. `,B="But the function was called without any arguments.",I=e=>{let t=u(e);return `But the actual arguments were: ${t.substring(1,t.length-1)}`},C={throwArgumentsError(e,t){let r=e.length===0?B:I(e);throw new Error(N(t)+r)}};var G="Observable spies require rxjs. Import 'vitest-auto-spy/rxjs' once (e.g. in your test setup) to enable observablePropsToSpyOn / nextWith / nextWithValues / throwWith / complete / returnSubject.";function h(){throw new Error(G);}function a(e,t){return Object.assign(e,t)}function K(e){return e.map(t=>({wrappedValue:t.delay===void 0?Promise.resolve(t.value):new Promise(r=>setTimeout(()=>r(t.value),t.delay))}))}function w(e,t){a(e,{resolveWith:r=>{t({value:Promise.resolve(r)});},rejectWith:r=>{t({value:r,_isRejectedPromise:true});},resolveWithPerCall:r=>{r.length!==0&&t({value:void 0,valuesPerCalls:K(r)});}});}function j(e,t){w(e,r=>{t.value=r.value,t._isRejectedPromise=r._isRejectedPromise??false,t.valuesPerCalls=r.valuesPerCalls??[];});}function M(e,t){w(e,r=>{e.argsToValuesMap.set(t,r);});}function D(e){return typeof e=="object"&&e!==null&&"value"in e}function A(e){if(e._isRejectedPromise)return Promise.reject(e.value);let t=e.valuesPerCalls?.shift();return t?t.wrappedValue:e.value}function v(e,t){let r=e.argsToValuesMap.get(t);return D(r)?{found:true,value:A(r)}:{found:false,value:void 0}}function q(e,t,r,n,o){if(e.wasConfigured){let s=v(e,n);if(s.found)return s.value}if(t.wasConfigured){let s=v(t,n);if(s.found)return s.value;C.throwArgumentsError(n,o);}return A(r)}function F(e,t){e.wasConfigured=true;let r=n=>{e.argsToValuesMap.set(t,{value:n});};return a(e,{mockReturnValue:r,returnValue:r}),M(e,t),e}function R(){return {wasConfigured:false,argsToValuesMap:new f}}function P(e){let t=R(),r=R(),n={value:void 0},o=l().createMockFn((...i)=>q(t,r,n,i,e),e);j(o,n);let s=a(o,{calledWith:(...i)=>F(t,i),mustBeCalledWith:(...i)=>F(r,i)});return s}var V={methodsToSpyOn:[],observablePropsToSpyOn:[],settersToSpyOn:[],gettersToSpyOn:[]};function U(e){let t=Object.getOwnPropertyDescriptors(e);return Object.keys(t).filter(r=>r!=="constructor"&&!t[r]?.get)}var x=new WeakMap;function L(e){let t=x.get(e);if(t)return t;let r=new Set,n=e;for(;n;){let s=Object.getPrototypeOf(n);s&&U(n).forEach(i=>r.add(i)),n=s;}let o=[...r];return x.set(e,o),o}function J(e){return e?Array.isArray(e)?{...V,methodsToSpyOn:e}:{methodsToSpyOn:e.methodsToSpyOn??[],observablePropsToSpyOn:e.observablePropsToSpyOn??[],settersToSpyOn:e.settersToSpyOn??[],gettersToSpyOn:e.gettersToSpyOn??[]}:{...V}}function W(e,t){let{methodsToSpyOn:r,observablePropsToSpyOn:n,settersToSpyOn:o,gettersToSpyOn:s}=J(t),i=r.length>0?r:L(e.prototype),c={};return n.forEach(p=>{c[p]=h().createPropSpy();}),O(c,s,o),i.forEach(p=>{c[p]=P(p);}),c}function X(e,t){return {provide:e,useValue:W(e,t)}}function Y(e,t){return e.get(t)}b(k);exports.injectSpy=Y;exports.provideAutoSpy=X;
|
package/dist/nestjs.d.cts
CHANGED
package/dist/nestjs.d.ts
CHANGED
package/dist/nestjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-6LFQMHSX.js';import {a
|
|
1
|
+
import {a as a$1}from'./chunk-6LFQMHSX.js';import {a as a$2}from'./chunk-WP2TFS53.js';import {a}from'./chunk-MQCVIN2A.js';import'./chunk-7IUYJ6ZW.js';function s(e,t){return {provide:e,useValue:a$2(e,t)}}function n(e,t){return e.get(t)}a(a$1);export{n as injectSpy,s as provideAutoSpy};
|
package/dist/node.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var node_test=require('node:test');var y;function k(e){y=e;}var
|
|
1
|
+
'use strict';var node_test=require('node:test');var y;function k(e){y=e;}var E="No mock adapter registered. Import a runtime entry once before creating spies \u2014 'vitest-auto-spy' (default, Vitest) or a runtime variant such as 'vitest-auto-spy/bun'.";function d(){if(!y)throw new Error(E);return y}function w({createMockFn:e,getCalls:t,reset:r}){return {createMockFn:e,spyOnGetter:(o,n)=>S(e,o,n,"get"),spyOnSetter:(o,n)=>S(e,o,n,"set"),getCalls:t,reset:r}}function S(e,t,r,o){let n=Object.getOwnPropertyDescriptor(t,r),s=o==="get"?n?.get:n?.set,i=e(s),c={configurable:true,enumerable:n?.enumerable??true};return n?.get&&(c.get=n.get),n?.set&&(c.set=n.set),o==="get"?c.get=i:c.set=i,Object.defineProperty(t,r,c),i}function M(e){return w({createMockFn:t=>e.fn(t??(()=>{})),getCalls:t=>t.mock.calls.map(r=>r.arguments),reset:t=>t.mock.resetCalls()})}function h(e,t){Object.defineProperty(e,t,{get(){},set(r){},configurable:true});}function O(e,t,r){let o=d();return r==="setter"?o.spyOnSetter(e,t):o.spyOnGetter(e,t)}function T(e,t,r){let o={getters:{},setters:{}};e.accessorSpies=o,t.forEach(n=>{h(e,n),o.getters[n]=O(e,n,"getter");}),r.forEach(n=>{Object.prototype.hasOwnProperty.call(e,n)||h(e,n),o.setters[n]=O(e,n,"setter");});}function _(e){return `'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}'`}function H(e,t){return Object.entries(e).map(([r,o])=>`${r}:${a(o,t)}`).join(",")}function $(e,t){return `new Map([${[...e.entries()].map(([o,n])=>`[${a(o,t)},${a(n,t)}]`).join(",")}])`}function N(e,t){if(t.has(e))return "[Circular]";t.add(e);let r;return e instanceof Date?r=`new Date(${e.getTime()})`:e instanceof Map?r=$(e,t):e instanceof Set?r=`new Set([${[...e].map(o=>a(o,t)).join(",")}])`:Array.isArray(e)?r=`[${e.map(o=>a(o,t)).join(",")}]`:r=`{${H(e,t)}}`,t.delete(e),r}function a(e,t=new WeakSet){return typeof e=="string"?_(e):typeof e=="bigint"?`${e}n`:typeof e=="symbol"?e.toString():typeof e=="function"?`[Function: ${e.name}]`:typeof e=="object"&&e!==null?N(e,t):Object.is(e,-0)?"-0":String(e)}var f=class{#e={};set(t,r){this.#e[this.#t(t)]=r;}get(t){return this.#e[this.#t(t)]}#t(t){return a(t)}};var z=e=>`The function '${e}' was configured with 'mustBeCalledWith' and expects to be called with specific arguments. `,B="But the function was called without any arguments.",D=e=>{let t=a(e);return `But the actual arguments were: ${t.substring(1,t.length-1)}`},g={throwArgumentsError(e,t){let r=e.length===0?B:D(e);throw new Error(z(t)+r)}};var I="Observable spies require rxjs. Import 'vitest-auto-spy/rxjs' once (e.g. in your test setup) to enable observablePropsToSpyOn / nextWith / nextWithValues / throwWith / complete / returnSubject.";function C(){throw new Error(I);}function u(e,t){return Object.assign(e,t)}function G(e){return e.map(t=>({wrappedValue:t.delay===void 0?Promise.resolve(t.value):new Promise(r=>setTimeout(()=>r(t.value),t.delay))}))}function j(e,t){u(e,{resolveWith:r=>{t({value:Promise.resolve(r)});},rejectWith:r=>{t({value:r,_isRejectedPromise:true});},resolveWithPerCall:r=>{r.length!==0&&t({value:void 0,valuesPerCalls:G(r)});}});}function F(e,t){j(e,r=>{t.value=r.value,t._isRejectedPromise=r._isRejectedPromise??false,t.valuesPerCalls=r.valuesPerCalls??[];});}function A(e,t){j(e,r=>{e.argsToValuesMap.set(t,r);});}function K(e){return typeof e=="object"&&e!==null&&"value"in e}function x(e){if(e._isRejectedPromise)return Promise.reject(e.value);let t=e.valuesPerCalls?.shift();return t?t.wrappedValue:e.value}function P(e,t){let r=e.argsToValuesMap.get(t);return K(r)?{found:true,value:x(r)}:{found:false,value:void 0}}function q(e,t,r,o,n){if(e.wasConfigured){let s=P(e,o);if(s.found)return s.value}if(t.wasConfigured){let s=P(t,o);if(s.found)return s.value;g.throwArgumentsError(o,n);}return x(r)}function v(e,t){e.wasConfigured=true;let r=o=>{e.argsToValuesMap.set(t,{value:o});};return u(e,{mockReturnValue:r,returnValue:r}),A(e,t),e}function R(){return {wasConfigured:false,argsToValuesMap:new f}}function p(e){let t=R(),r=R(),o={value:void 0},n=d().createMockFn((...i)=>q(t,r,o,i,e),e);F(n,o);let s=u(n,{calledWith:(...i)=>v(t,i),mustBeCalledWith:(...i)=>v(r,i)});return s}var V={methodsToSpyOn:[],observablePropsToSpyOn:[],settersToSpyOn:[],gettersToSpyOn:[]};function U(e){let t=Object.getOwnPropertyDescriptors(e);return Object.keys(t).filter(r=>r!=="constructor"&&!t[r]?.get)}var W=new WeakMap;function L(e){let t=W.get(e);if(t)return t;let r=new Set,o=e;for(;o;){let s=Object.getPrototypeOf(o);s&&U(o).forEach(i=>r.add(i)),o=s;}let n=[...r];return W.set(e,n),n}function J(e){return e?Array.isArray(e)?{...V,methodsToSpyOn:e}:{methodsToSpyOn:e.methodsToSpyOn??[],observablePropsToSpyOn:e.observablePropsToSpyOn??[],settersToSpyOn:e.settersToSpyOn??[],gettersToSpyOn:e.gettersToSpyOn??[]}:{...V}}function X(e,t){let{methodsToSpyOn:r,observablePropsToSpyOn:o,settersToSpyOn:n,gettersToSpyOn:s}=J(t),i=r.length>0?r:L(e.prototype),c={};return o.forEach(l=>{c[l]=C().createPropSpy();}),T(c,s,n),i.forEach(l=>{c[l]=p(l);}),c}function Y(e={}){let t=new Map;for(let o of Reflect.ownKeys(e))t.set(o,Reflect.get(e,o));let r={get(o,n){if(t.has(n))return t.get(n);if(typeof n=="symbol"||n==="then"||n==="constructor")return;let s=p(String(n));return t.set(n,s),s},set(o,n,s){return t.set(n,s),true},has(o,n){return t.has(n)},ownKeys(){return [...t.keys()]},getOwnPropertyDescriptor(o,n){if(t.has(n))return {configurable:true,enumerable:true,value:t.get(n),writable:true}}};return new Proxy({},r)}k(M(node_test.mock));exports.createAutoMock=Y;exports.createFunctionSpy=p;exports.createSpyFromClass=X;exports.errorHandler=g;
|
package/dist/node.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, a as ClassSpyConfiguration, C as ClassType, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, O as OnlyMethodKeysOf, j as OnlyObservablePropsOf, k as OnlyPropsOf, S as Spy, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-
|
|
1
|
+
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, a as ClassSpyConfiguration, C as ClassType, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, O as OnlyMethodKeysOf, j as OnlyObservablePropsOf, k as OnlyPropsOf, S as Spy, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-Cv3L71P0.cjs';
|
|
2
2
|
export { createAutoMock, createFunctionSpy, createSpyFromClass, errorHandler } from './bun.cjs';
|
|
3
3
|
import 'rxjs';
|
|
4
4
|
import 'vitest';
|
package/dist/node.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, a as ClassSpyConfiguration, C as ClassType, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, O as OnlyMethodKeysOf, j as OnlyObservablePropsOf, k as OnlyPropsOf, S as Spy, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-
|
|
1
|
+
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, a as ClassSpyConfiguration, C as ClassType, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, O as OnlyMethodKeysOf, j as OnlyObservablePropsOf, k as OnlyPropsOf, S as Spy, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-Cv3L71P0.js';
|
|
2
2
|
export { createAutoMock, createFunctionSpy, createSpyFromClass, errorHandler } from './bun.js';
|
|
3
3
|
import 'rxjs';
|
|
4
4
|
import 'vitest';
|
package/dist/node.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-IPBQZ4JC.js';export{a as createAutoMock}from'./chunk-
|
|
1
|
+
import {a as a$1}from'./chunk-IPBQZ4JC.js';export{a as createAutoMock}from'./chunk-HVN6A3AX.js';export{a as createSpyFromClass}from'./chunk-WP2TFS53.js';import {a}from'./chunk-MQCVIN2A.js';export{e as createFunctionSpy,d as errorHandler}from'./chunk-MQCVIN2A.js';import'./chunk-7IUYJ6ZW.js';import {mock}from'node:test';function t(n){return a$1({createMockFn:e=>n.fn(e??(()=>{})),getCalls:e=>e.mock.calls.map(c=>c.arguments),reset:e=>e.mock.resetCalls()})}a(t(mock));
|
package/dist/react.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var vitest=require('vitest');var g;function S(e){g=e;}var
|
|
1
|
+
'use strict';var vitest=require('vitest');var g;function S(e){g=e;}var W="No mock adapter registered. Import a runtime entry once before creating spies \u2014 'vitest-auto-spy' (default, Vitest) or a runtime variant such as 'vitest-auto-spy/bun'.";function d(){if(!g)throw new Error(W);return g}var w={createMockFn(e,t){let r=e?vitest.vi.fn(e):vitest.vi.fn();return t!==void 0&&r.mockName(t),r},spyOnGetter(e,t){return vitest.vi.spyOn(e,t,"get")},spyOnSetter(e,t){return vitest.vi.spyOn(e,t,"set")},getCalls(e){return e.mock.calls},reset(e){e.mockReset();}};function h(e,t){Object.defineProperty(e,t,{get(){},set(r){},configurable:true});}function O(e,t,r){let n=d();return r==="setter"?n.spyOnSetter(e,t):n.spyOnGetter(e,t)}function T(e,t,r){let n={getters:{},setters:{}};e.accessorSpies=n,t.forEach(o=>{h(e,o),n.getters[o]=O(e,o,"getter");}),r.forEach(o=>{Object.prototype.hasOwnProperty.call(e,o)||h(e,o),n.setters[o]=O(e,o,"setter");});}function E(e){return `'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}'`}function _(e,t){return Object.entries(e).map(([r,n])=>`${r}:${u(n,t)}`).join(",")}function H(e,t){return `new Map([${[...e.entries()].map(([n,o])=>`[${u(n,t)},${u(o,t)}]`).join(",")}])`}function $(e,t){if(t.has(e))return "[Circular]";t.add(e);let r;return e instanceof Date?r=`new Date(${e.getTime()})`:e instanceof Map?r=H(e,t):e instanceof Set?r=`new Set([${[...e].map(n=>u(n,t)).join(",")}])`:Array.isArray(e)?r=`[${e.map(n=>u(n,t)).join(",")}]`:r=`{${_(e,t)}}`,t.delete(e),r}function u(e,t=new WeakSet){return typeof e=="string"?E(e):typeof e=="bigint"?`${e}n`:typeof e=="symbol"?e.toString():typeof e=="function"?`[Function: ${e.name}]`:typeof e=="object"&&e!==null?$(e,t):Object.is(e,-0)?"-0":String(e)}var y=class{#e={};set(t,r){this.#e[this.#t(t)]=r;}get(t){return this.#e[this.#t(t)]}#t(t){return u(t)}};var z=e=>`The function '${e}' was configured with 'mustBeCalledWith' and expects to be called with specific arguments. `,B="But the function was called without any arguments.",I=e=>{let t=u(e);return `But the actual arguments were: ${t.substring(1,t.length-1)}`},m={throwArgumentsError(e,t){let r=e.length===0?B:I(e);throw new Error(z(t)+r)}};var G="Observable spies require rxjs. Import 'vitest-auto-spy/rxjs' once (e.g. in your test setup) to enable observablePropsToSpyOn / nextWith / nextWithValues / throwWith / complete / returnSubject.";function M(){throw new Error(G);}function c(e,t){return Object.assign(e,t)}function K(e){return e.map(t=>({wrappedValue:t.delay===void 0?Promise.resolve(t.value):new Promise(r=>setTimeout(()=>r(t.value),t.delay))}))}function j(e,t){c(e,{resolveWith:r=>{t({value:Promise.resolve(r)});},rejectWith:r=>{t({value:r,_isRejectedPromise:true});},resolveWithPerCall:r=>{r.length!==0&&t({value:void 0,valuesPerCalls:K(r)});}});}function C(e,t){j(e,r=>{t.value=r.value,t._isRejectedPromise=r._isRejectedPromise??false,t.valuesPerCalls=r.valuesPerCalls??[];});}function v(e,t){j(e,r=>{e.argsToValuesMap.set(t,r);});}function D(e){return typeof e=="object"&&e!==null&&"value"in e}function A(e){if(e._isRejectedPromise)return Promise.reject(e.value);let t=e.valuesPerCalls?.shift();return t?t.wrappedValue:e.value}function F(e,t){let r=e.argsToValuesMap.get(t);return D(r)?{found:true,value:A(r)}:{found:false,value:void 0}}function q(e,t,r,n,o){if(e.wasConfigured){let s=F(e,n);if(s.found)return s.value}if(t.wasConfigured){let s=F(t,n);if(s.found)return s.value;m.throwArgumentsError(n,o);}return A(r)}function P(e,t){e.wasConfigured=true;let r=n=>{e.argsToValuesMap.set(t,{value:n});};return c(e,{mockReturnValue:r,returnValue:r}),v(e,t),e}function R(){return {wasConfigured:false,argsToValuesMap:new y}}function a(e){let t=R(),r=R(),n={value:void 0},o=d().createMockFn((...i)=>q(t,r,n,i,e),e);C(o,n);let s=c(o,{calledWith:(...i)=>P(t,i),mustBeCalledWith:(...i)=>P(r,i)});return s}var x={methodsToSpyOn:[],observablePropsToSpyOn:[],settersToSpyOn:[],gettersToSpyOn:[]};function N(e){let t=Object.getOwnPropertyDescriptors(e);return Object.keys(t).filter(r=>r!=="constructor"&&!t[r]?.get)}var V=new WeakMap;function U(e){let t=V.get(e);if(t)return t;let r=new Set,n=e;for(;n;){let s=Object.getPrototypeOf(n);s&&N(n).forEach(i=>r.add(i)),n=s;}let o=[...r];return V.set(e,o),o}function L(e){return e?Array.isArray(e)?{...x,methodsToSpyOn:e}:{methodsToSpyOn:e.methodsToSpyOn??[],observablePropsToSpyOn:e.observablePropsToSpyOn??[],settersToSpyOn:e.settersToSpyOn??[],gettersToSpyOn:e.gettersToSpyOn??[]}:{...x}}function J(e,t){let{methodsToSpyOn:r,observablePropsToSpyOn:n,settersToSpyOn:o,gettersToSpyOn:s}=L(t),i=r.length>0?r:U(e.prototype),p={};return n.forEach(l=>{p[l]=M().createPropSpy();}),T(p,s,o),i.forEach(l=>{p[l]=a(l);}),p}function X(e={}){let t=new Map;for(let n of Reflect.ownKeys(e))t.set(n,Reflect.get(e,n));let r={get(n,o){if(t.has(o))return t.get(o);if(typeof o=="symbol"||o==="then"||o==="constructor")return;let s=a(String(o));return t.set(o,s),s},set(n,o,s){return t.set(o,s),true},has(n,o){return t.has(o)},ownKeys(){return [...t.keys()]},getOwnPropertyDescriptor(n,o){if(t.has(o))return {configurable:true,enumerable:true,value:t.get(o),writable:true}}};return new Proxy({},r)}S(w);exports.createAutoMock=X;exports.createFunctionSpy=a;exports.createSpyFromClass=J;exports.errorHandler=m;
|
package/dist/react.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, a as ClassSpyConfiguration, C as ClassType, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, O as OnlyMethodKeysOf, j as OnlyObservablePropsOf, k as OnlyPropsOf, S as Spy, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-
|
|
1
|
+
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, a as ClassSpyConfiguration, C as ClassType, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, O as OnlyMethodKeysOf, j as OnlyObservablePropsOf, k as OnlyPropsOf, S as Spy, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-Cv3L71P0.cjs';
|
|
2
2
|
export { createAutoMock, createFunctionSpy, createSpyFromClass, errorHandler } from './bun.cjs';
|
|
3
3
|
import 'rxjs';
|
|
4
4
|
import 'vitest';
|
package/dist/react.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, a as ClassSpyConfiguration, C as ClassType, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, O as OnlyMethodKeysOf, j as OnlyObservablePropsOf, k as OnlyPropsOf, S as Spy, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-
|
|
1
|
+
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, a as ClassSpyConfiguration, C as ClassType, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, O as OnlyMethodKeysOf, j as OnlyObservablePropsOf, k as OnlyPropsOf, S as Spy, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-Cv3L71P0.js';
|
|
2
2
|
export { createAutoMock, createFunctionSpy, createSpyFromClass, errorHandler } from './bun.js';
|
|
3
3
|
import 'rxjs';
|
|
4
4
|
import 'vitest';
|
package/dist/react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-6LFQMHSX.js';export{a as createAutoMock}from'./chunk-
|
|
1
|
+
import {a as a$1}from'./chunk-6LFQMHSX.js';export{a as createAutoMock}from'./chunk-HVN6A3AX.js';export{a as createSpyFromClass}from'./chunk-WP2TFS53.js';import {a}from'./chunk-MQCVIN2A.js';export{e as createFunctionSpy,d as errorHandler}from'./chunk-MQCVIN2A.js';import'./chunk-7IUYJ6ZW.js';a(a$1);
|
package/dist/rxjs.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Observable, ReplaySubject } from 'rxjs';
|
|
2
|
-
import { V as ValueConfig } from './types-
|
|
3
|
-
export { A as AddObservableSpyMethods, b as CompleteValueConfig, E as ErrorValueConfig, N as NextValueConfig, c as ValueConfigPerCall } from './types-
|
|
2
|
+
import { V as ValueConfig } from './types-Cv3L71P0.cjs';
|
|
3
|
+
export { A as AddObservableSpyMethods, b as CompleteValueConfig, E as ErrorValueConfig, N as NextValueConfig, c as ValueConfigPerCall } from './types-Cv3L71P0.cjs';
|
|
4
4
|
import 'vitest';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/rxjs.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Observable, ReplaySubject } from 'rxjs';
|
|
2
|
-
import { V as ValueConfig } from './types-
|
|
3
|
-
export { A as AddObservableSpyMethods, b as CompleteValueConfig, E as ErrorValueConfig, N as NextValueConfig, c as ValueConfigPerCall } from './types-
|
|
2
|
+
import { V as ValueConfig } from './types-Cv3L71P0.js';
|
|
3
|
+
export { A as AddObservableSpyMethods, b as CompleteValueConfig, E as ErrorValueConfig, N as NextValueConfig, c as ValueConfigPerCall } from './types-Cv3L71P0.js';
|
|
4
4
|
import 'vitest';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/svelte.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var vitest=require('vitest');var g;function S(e){g=e;}var
|
|
1
|
+
'use strict';var vitest=require('vitest');var g;function S(e){g=e;}var W="No mock adapter registered. Import a runtime entry once before creating spies \u2014 'vitest-auto-spy' (default, Vitest) or a runtime variant such as 'vitest-auto-spy/bun'.";function d(){if(!g)throw new Error(W);return g}var w={createMockFn(e,t){let r=e?vitest.vi.fn(e):vitest.vi.fn();return t!==void 0&&r.mockName(t),r},spyOnGetter(e,t){return vitest.vi.spyOn(e,t,"get")},spyOnSetter(e,t){return vitest.vi.spyOn(e,t,"set")},getCalls(e){return e.mock.calls},reset(e){e.mockReset();}};function h(e,t){Object.defineProperty(e,t,{get(){},set(r){},configurable:true});}function O(e,t,r){let n=d();return r==="setter"?n.spyOnSetter(e,t):n.spyOnGetter(e,t)}function T(e,t,r){let n={getters:{},setters:{}};e.accessorSpies=n,t.forEach(o=>{h(e,o),n.getters[o]=O(e,o,"getter");}),r.forEach(o=>{Object.prototype.hasOwnProperty.call(e,o)||h(e,o),n.setters[o]=O(e,o,"setter");});}function E(e){return `'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}'`}function _(e,t){return Object.entries(e).map(([r,n])=>`${r}:${u(n,t)}`).join(",")}function H(e,t){return `new Map([${[...e.entries()].map(([n,o])=>`[${u(n,t)},${u(o,t)}]`).join(",")}])`}function $(e,t){if(t.has(e))return "[Circular]";t.add(e);let r;return e instanceof Date?r=`new Date(${e.getTime()})`:e instanceof Map?r=H(e,t):e instanceof Set?r=`new Set([${[...e].map(n=>u(n,t)).join(",")}])`:Array.isArray(e)?r=`[${e.map(n=>u(n,t)).join(",")}]`:r=`{${_(e,t)}}`,t.delete(e),r}function u(e,t=new WeakSet){return typeof e=="string"?E(e):typeof e=="bigint"?`${e}n`:typeof e=="symbol"?e.toString():typeof e=="function"?`[Function: ${e.name}]`:typeof e=="object"&&e!==null?$(e,t):Object.is(e,-0)?"-0":String(e)}var y=class{#e={};set(t,r){this.#e[this.#t(t)]=r;}get(t){return this.#e[this.#t(t)]}#t(t){return u(t)}};var z=e=>`The function '${e}' was configured with 'mustBeCalledWith' and expects to be called with specific arguments. `,B="But the function was called without any arguments.",I=e=>{let t=u(e);return `But the actual arguments were: ${t.substring(1,t.length-1)}`},m={throwArgumentsError(e,t){let r=e.length===0?B:I(e);throw new Error(z(t)+r)}};var G="Observable spies require rxjs. Import 'vitest-auto-spy/rxjs' once (e.g. in your test setup) to enable observablePropsToSpyOn / nextWith / nextWithValues / throwWith / complete / returnSubject.";function M(){throw new Error(G);}function c(e,t){return Object.assign(e,t)}function K(e){return e.map(t=>({wrappedValue:t.delay===void 0?Promise.resolve(t.value):new Promise(r=>setTimeout(()=>r(t.value),t.delay))}))}function j(e,t){c(e,{resolveWith:r=>{t({value:Promise.resolve(r)});},rejectWith:r=>{t({value:r,_isRejectedPromise:true});},resolveWithPerCall:r=>{r.length!==0&&t({value:void 0,valuesPerCalls:K(r)});}});}function C(e,t){j(e,r=>{t.value=r.value,t._isRejectedPromise=r._isRejectedPromise??false,t.valuesPerCalls=r.valuesPerCalls??[];});}function v(e,t){j(e,r=>{e.argsToValuesMap.set(t,r);});}function D(e){return typeof e=="object"&&e!==null&&"value"in e}function A(e){if(e._isRejectedPromise)return Promise.reject(e.value);let t=e.valuesPerCalls?.shift();return t?t.wrappedValue:e.value}function F(e,t){let r=e.argsToValuesMap.get(t);return D(r)?{found:true,value:A(r)}:{found:false,value:void 0}}function q(e,t,r,n,o){if(e.wasConfigured){let s=F(e,n);if(s.found)return s.value}if(t.wasConfigured){let s=F(t,n);if(s.found)return s.value;m.throwArgumentsError(n,o);}return A(r)}function P(e,t){e.wasConfigured=true;let r=n=>{e.argsToValuesMap.set(t,{value:n});};return c(e,{mockReturnValue:r,returnValue:r}),v(e,t),e}function R(){return {wasConfigured:false,argsToValuesMap:new y}}function a(e){let t=R(),r=R(),n={value:void 0},o=d().createMockFn((...i)=>q(t,r,n,i,e),e);C(o,n);let s=c(o,{calledWith:(...i)=>P(t,i),mustBeCalledWith:(...i)=>P(r,i)});return s}var x={methodsToSpyOn:[],observablePropsToSpyOn:[],settersToSpyOn:[],gettersToSpyOn:[]};function N(e){let t=Object.getOwnPropertyDescriptors(e);return Object.keys(t).filter(r=>r!=="constructor"&&!t[r]?.get)}var V=new WeakMap;function U(e){let t=V.get(e);if(t)return t;let r=new Set,n=e;for(;n;){let s=Object.getPrototypeOf(n);s&&N(n).forEach(i=>r.add(i)),n=s;}let o=[...r];return V.set(e,o),o}function L(e){return e?Array.isArray(e)?{...x,methodsToSpyOn:e}:{methodsToSpyOn:e.methodsToSpyOn??[],observablePropsToSpyOn:e.observablePropsToSpyOn??[],settersToSpyOn:e.settersToSpyOn??[],gettersToSpyOn:e.gettersToSpyOn??[]}:{...x}}function J(e,t){let{methodsToSpyOn:r,observablePropsToSpyOn:n,settersToSpyOn:o,gettersToSpyOn:s}=L(t),i=r.length>0?r:U(e.prototype),p={};return n.forEach(l=>{p[l]=M().createPropSpy();}),T(p,s,o),i.forEach(l=>{p[l]=a(l);}),p}function X(e={}){let t=new Map;for(let n of Reflect.ownKeys(e))t.set(n,Reflect.get(e,n));let r={get(n,o){if(t.has(o))return t.get(o);if(typeof o=="symbol"||o==="then"||o==="constructor")return;let s=a(String(o));return t.set(o,s),s},set(n,o,s){return t.set(o,s),true},has(n,o){return t.has(o)},ownKeys(){return [...t.keys()]},getOwnPropertyDescriptor(n,o){if(t.has(o))return {configurable:true,enumerable:true,value:t.get(o),writable:true}}};return new Proxy({},r)}S(w);exports.createAutoMock=X;exports.createFunctionSpy=a;exports.createSpyFromClass=J;exports.errorHandler=m;
|
package/dist/svelte.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, a as ClassSpyConfiguration, C as ClassType, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, O as OnlyMethodKeysOf, j as OnlyObservablePropsOf, k as OnlyPropsOf, S as Spy, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-
|
|
1
|
+
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, a as ClassSpyConfiguration, C as ClassType, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, O as OnlyMethodKeysOf, j as OnlyObservablePropsOf, k as OnlyPropsOf, S as Spy, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-Cv3L71P0.cjs';
|
|
2
2
|
export { createAutoMock, createFunctionSpy, createSpyFromClass, errorHandler } from './bun.cjs';
|
|
3
3
|
import 'rxjs';
|
|
4
4
|
import 'vitest';
|
package/dist/svelte.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, a as ClassSpyConfiguration, C as ClassType, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, O as OnlyMethodKeysOf, j as OnlyObservablePropsOf, k as OnlyPropsOf, S as Spy, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-
|
|
1
|
+
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, a as ClassSpyConfiguration, C as ClassType, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, O as OnlyMethodKeysOf, j as OnlyObservablePropsOf, k as OnlyPropsOf, S as Spy, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-Cv3L71P0.js';
|
|
2
2
|
export { createAutoMock, createFunctionSpy, createSpyFromClass, errorHandler } from './bun.js';
|
|
3
3
|
import 'rxjs';
|
|
4
4
|
import 'vitest';
|
package/dist/svelte.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-6LFQMHSX.js';export{a as createAutoMock}from'./chunk-
|
|
1
|
+
import {a as a$1}from'./chunk-6LFQMHSX.js';export{a as createAutoMock}from'./chunk-HVN6A3AX.js';export{a as createSpyFromClass}from'./chunk-WP2TFS53.js';import {a}from'./chunk-MQCVIN2A.js';export{e as createFunctionSpy,d as errorHandler}from'./chunk-MQCVIN2A.js';import'./chunk-7IUYJ6ZW.js';a(a$1);
|
|
@@ -67,9 +67,14 @@ interface AddPromiseSpyMethods<T> {
|
|
|
67
67
|
rejectWith(value?: unknown): void;
|
|
68
68
|
resolveWithPerCall(valuesPerCall: ValueConfigPerCall<T>[]): void;
|
|
69
69
|
}
|
|
70
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* A configured return-value continuation for a `calledWith`/`mustBeCalledWith`
|
|
72
|
+
* chain. `mockReturnValue` is the native name; `returnValue` is the
|
|
73
|
+
* `jest-auto-spies` alias, kept so migrating tests are a pure import swap.
|
|
74
|
+
*/
|
|
71
75
|
type WithMockReturnValue<Method extends Func> = {
|
|
72
76
|
mockReturnValue: (value: ReturnType<Method>) => void;
|
|
77
|
+
returnValue: (value: ReturnType<Method>) => void;
|
|
73
78
|
};
|
|
74
79
|
/** Argument-matching helpers attached to a plain (sync) spy. */
|
|
75
80
|
interface AddCalledWithSpyMethods<Method extends Func> {
|
|
@@ -67,9 +67,14 @@ interface AddPromiseSpyMethods<T> {
|
|
|
67
67
|
rejectWith(value?: unknown): void;
|
|
68
68
|
resolveWithPerCall(valuesPerCall: ValueConfigPerCall<T>[]): void;
|
|
69
69
|
}
|
|
70
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* A configured return-value continuation for a `calledWith`/`mustBeCalledWith`
|
|
72
|
+
* chain. `mockReturnValue` is the native name; `returnValue` is the
|
|
73
|
+
* `jest-auto-spies` alias, kept so migrating tests are a pure import swap.
|
|
74
|
+
*/
|
|
71
75
|
type WithMockReturnValue<Method extends Func> = {
|
|
72
76
|
mockReturnValue: (value: ReturnType<Method>) => void;
|
|
77
|
+
returnValue: (value: ReturnType<Method>) => void;
|
|
73
78
|
};
|
|
74
79
|
/** Argument-matching helpers attached to a plain (sync) spy. */
|
|
75
80
|
interface AddCalledWithSpyMethods<Method extends Func> {
|
package/dist/vue.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var vitest=require('vitest');var g;function T(e){g=e;}var
|
|
1
|
+
'use strict';var vitest=require('vitest');var g;function T(e){g=e;}var E="No mock adapter registered. Import a runtime entry once before creating spies \u2014 'vitest-auto-spy' (default, Vitest) or a runtime variant such as 'vitest-auto-spy/bun'.";function d(){if(!g)throw new Error(E);return g}var h={createMockFn(e,t){let r=e?vitest.vi.fn(e):vitest.vi.fn();return t!==void 0&&r.mockName(t),r},spyOnGetter(e,t){return vitest.vi.spyOn(e,t,"get")},spyOnSetter(e,t){return vitest.vi.spyOn(e,t,"set")},getCalls(e){return e.mock.calls},reset(e){e.mockReset();}};function w(e,t){Object.defineProperty(e,t,{get(){},set(r){},configurable:true});}function O(e,t,r){let n=d();return r==="setter"?n.spyOnSetter(e,t):n.spyOnGetter(e,t)}function C(e,t,r){let n={getters:{},setters:{}};e.accessorSpies=n,t.forEach(o=>{w(e,o),n.getters[o]=O(e,o,"getter");}),r.forEach(o=>{Object.prototype.hasOwnProperty.call(e,o)||w(e,o),n.setters[o]=O(e,o,"setter");});}function _(e){return `'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}'`}function H(e,t){return Object.entries(e).map(([r,n])=>`${r}:${u(n,t)}`).join(",")}function $(e,t){return `new Map([${[...e.entries()].map(([n,o])=>`[${u(n,t)},${u(o,t)}]`).join(",")}])`}function I(e,t){if(t.has(e))return "[Circular]";t.add(e);let r;return e instanceof Date?r=`new Date(${e.getTime()})`:e instanceof Map?r=$(e,t):e instanceof Set?r=`new Set([${[...e].map(n=>u(n,t)).join(",")}])`:Array.isArray(e)?r=`[${e.map(n=>u(n,t)).join(",")}]`:r=`{${H(e,t)}}`,t.delete(e),r}function u(e,t=new WeakSet){return typeof e=="string"?_(e):typeof e=="bigint"?`${e}n`:typeof e=="symbol"?e.toString():typeof e=="function"?`[Function: ${e.name}]`:typeof e=="object"&&e!==null?I(e,t):Object.is(e,-0)?"-0":String(e)}var y=class{#e={};set(t,r){this.#e[this.#t(t)]=r;}get(t){return this.#e[this.#t(t)]}#t(t){return u(t)}};var z=e=>`The function '${e}' was configured with 'mustBeCalledWith' and expects to be called with specific arguments. `,K="But the function was called without any arguments.",B=e=>{let t=u(e);return `But the actual arguments were: ${t.substring(1,t.length-1)}`},m={throwArgumentsError(e,t){let r=e.length===0?K:B(e);throw new Error(z(t)+r)}};var G="Observable spies require rxjs. Import 'vitest-auto-spy/rxjs' once (e.g. in your test setup) to enable observablePropsToSpyOn / nextWith / nextWithValues / throwWith / complete / returnSubject.";function j(){throw new Error(G);}function a(e,t){return Object.assign(e,t)}function D(e){return e.map(t=>({wrappedValue:t.delay===void 0?Promise.resolve(t.value):new Promise(r=>setTimeout(()=>r(t.value),t.delay))}))}function M(e,t){a(e,{resolveWith:r=>{t({value:Promise.resolve(r)});},rejectWith:r=>{t({value:r,_isRejectedPromise:true});},resolveWithPerCall:r=>{r.length!==0&&t({value:void 0,valuesPerCalls:D(r)});}});}function v(e,t){M(e,r=>{t.value=r.value,t._isRejectedPromise=r._isRejectedPromise??false,t.valuesPerCalls=r.valuesPerCalls??[];});}function F(e,t){M(e,r=>{e.argsToValuesMap.set(t,r);});}function q(e){return typeof e=="object"&&e!==null&&"value"in e}function A(e){if(e._isRejectedPromise)return Promise.reject(e.value);let t=e.valuesPerCalls?.shift();return t?t.wrappedValue:e.value}function P(e,t){let r=e.argsToValuesMap.get(t);return q(r)?{found:true,value:A(r)}:{found:false,value:void 0}}function N(e,t,r,n,o){if(e.wasConfigured){let s=P(e,n);if(s.found)return s.value}if(t.wasConfigured){let s=P(t,n);if(s.found)return s.value;m.throwArgumentsError(n,o);}return A(r)}function x(e,t){e.wasConfigured=true;let r=n=>{e.argsToValuesMap.set(t,{value:n});};return a(e,{mockReturnValue:r,returnValue:r}),F(e,t),e}function R(){return {wasConfigured:false,argsToValuesMap:new y}}function c(e){let t=R(),r=R(),n={value:void 0},o=d().createMockFn((...i)=>N(t,r,n,i,e),e);v(o,n);let s=a(o,{calledWith:(...i)=>x(t,i),mustBeCalledWith:(...i)=>x(r,i)});return s}var V={methodsToSpyOn:[],observablePropsToSpyOn:[],settersToSpyOn:[],gettersToSpyOn:[]};function U(e){let t=Object.getOwnPropertyDescriptors(e);return Object.keys(t).filter(r=>r!=="constructor"&&!t[r]?.get)}var W=new WeakMap;function L(e){let t=W.get(e);if(t)return t;let r=new Set,n=e;for(;n;){let s=Object.getPrototypeOf(n);s&&U(n).forEach(i=>r.add(i)),n=s;}let o=[...r];return W.set(e,o),o}function J(e){return e?Array.isArray(e)?{...V,methodsToSpyOn:e}:{methodsToSpyOn:e.methodsToSpyOn??[],observablePropsToSpyOn:e.observablePropsToSpyOn??[],settersToSpyOn:e.settersToSpyOn??[],gettersToSpyOn:e.gettersToSpyOn??[]}:{...V}}function S(e,t){let{methodsToSpyOn:r,observablePropsToSpyOn:n,settersToSpyOn:o,gettersToSpyOn:s}=J(t),i=r.length>0?r:L(e.prototype),p={};return n.forEach(l=>{p[l]=j().createPropSpy();}),C(p,s,o),i.forEach(l=>{p[l]=c(l);}),p}function X(e,t,r){return {[e]:S(t,r)}}function Y(e={}){let t=new Map;for(let n of Reflect.ownKeys(e))t.set(n,Reflect.get(e,n));let r={get(n,o){if(t.has(o))return t.get(o);if(typeof o=="symbol"||o==="then"||o==="constructor")return;let s=c(String(o));return t.set(o,s),s},set(n,o,s){return t.set(o,s),true},has(n,o){return t.has(o)},ownKeys(){return [...t.keys()]},getOwnPropertyDescriptor(n,o){if(t.has(o))return {configurable:true,enumerable:true,value:t.get(o),writable:true}}};return new Proxy({},r)}T(h);exports.createAutoMock=Y;exports.createFunctionSpy=c;exports.createSpyFromClass=S;exports.errorHandler=m;exports.provideAutoSpy=X;
|
package/dist/vue.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Spy, C as ClassType, a as ClassSpyConfiguration, O as OnlyMethodKeysOf } from './types-
|
|
2
|
-
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, j as OnlyObservablePropsOf, k as OnlyPropsOf, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-
|
|
1
|
+
import { S as Spy, C as ClassType, a as ClassSpyConfiguration, O as OnlyMethodKeysOf } from './types-Cv3L71P0.cjs';
|
|
2
|
+
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, j as OnlyObservablePropsOf, k as OnlyPropsOf, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-Cv3L71P0.cjs';
|
|
3
3
|
export { createAutoMock, createFunctionSpy, createSpyFromClass, errorHandler } from './bun.cjs';
|
|
4
4
|
import 'rxjs';
|
|
5
5
|
import 'vitest';
|
package/dist/vue.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Spy, C as ClassType, a as ClassSpyConfiguration, O as OnlyMethodKeysOf } from './types-
|
|
2
|
-
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, j as OnlyObservablePropsOf, k as OnlyPropsOf, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-
|
|
1
|
+
import { S as Spy, C as ClassType, a as ClassSpyConfiguration, O as OnlyMethodKeysOf } from './types-Cv3L71P0.js';
|
|
2
|
+
export { d as AddAccessorsSpies, e as AddCalledWithObservable, f as AddCalledWithPromise, g as AddCalledWithSpyMethods, A as AddObservableSpyMethods, h as AddPromiseSpyMethods, i as AddSpyMethodsByReturnTypes, b as CompleteValueConfig, E as ErrorValueConfig, F as Func, N as NextValueConfig, j as OnlyObservablePropsOf, k as OnlyPropsOf, V as ValueConfig, c as ValueConfigPerCall, W as WithMockReturnValue } from './types-Cv3L71P0.js';
|
|
3
3
|
export { createAutoMock, createFunctionSpy, createSpyFromClass, errorHandler } from './bun.js';
|
|
4
4
|
import 'rxjs';
|
|
5
5
|
import 'vitest';
|
package/dist/vue.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-6LFQMHSX.js';export{a as createAutoMock}from'./chunk-
|
|
1
|
+
import {a as a$1}from'./chunk-6LFQMHSX.js';export{a as createAutoMock}from'./chunk-HVN6A3AX.js';import {a as a$2}from'./chunk-WP2TFS53.js';export{a as createSpyFromClass}from'./chunk-WP2TFS53.js';import {a}from'./chunk-MQCVIN2A.js';export{e as createFunctionSpy,d as errorHandler}from'./chunk-MQCVIN2A.js';import'./chunk-7IUYJ6ZW.js';function y(r,p,n){return {[r]:a$2(p,n)}}a(a$1);export{y as provideAutoSpy};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-auto-spy",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
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",
|
|
@@ -67,6 +67,11 @@
|
|
|
67
67
|
"import": "./dist/rxjs.js",
|
|
68
68
|
"require": "./dist/rxjs.cjs"
|
|
69
69
|
},
|
|
70
|
+
"./console": {
|
|
71
|
+
"types": "./dist/console.d.ts",
|
|
72
|
+
"import": "./dist/console.js",
|
|
73
|
+
"require": "./dist/console.cjs"
|
|
74
|
+
},
|
|
70
75
|
"./angular": {
|
|
71
76
|
"types": "./dist/angular.d.ts",
|
|
72
77
|
"import": "./dist/angular.js",
|
|
@@ -95,6 +100,7 @@
|
|
|
95
100
|
},
|
|
96
101
|
"files": [
|
|
97
102
|
"dist",
|
|
103
|
+
"assets",
|
|
98
104
|
"README.md",
|
|
99
105
|
"LICENSE"
|
|
100
106
|
],
|
|
@@ -116,7 +122,9 @@
|
|
|
116
122
|
"**/svelte.js",
|
|
117
123
|
"**/svelte.cjs",
|
|
118
124
|
"**/rxjs.js",
|
|
119
|
-
"**/rxjs.cjs"
|
|
125
|
+
"**/rxjs.cjs",
|
|
126
|
+
"**/console.js",
|
|
127
|
+
"**/console.cjs"
|
|
120
128
|
],
|
|
121
129
|
"engines": {
|
|
122
130
|
"node": ">=18"
|
|
@@ -130,6 +138,7 @@
|
|
|
130
138
|
"test": "vitest run",
|
|
131
139
|
"test:watch": "vitest",
|
|
132
140
|
"test:coverage": "vitest run --coverage",
|
|
141
|
+
"bench": "vitest bench --run --config vitest.bench.config.mts",
|
|
133
142
|
"lint": "eslint . --ext .ts",
|
|
134
143
|
"lint:fix": "eslint . --ext .ts --fix",
|
|
135
144
|
"format": "prettier -w \"src/**/*.ts\"",
|
package/dist/chunk-ACSYU277.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import {d}from'./chunk-VLNCYBUN.js';function s(u={}){let r=new Map;for(let t of Reflect.ownKeys(u))r.set(t,Reflect.get(u,t));let a={get(t,e){if(r.has(e))return r.get(e);if(typeof e=="symbol"||e==="then"||e==="constructor")return;let n=d(String(e));return r.set(e,n),n},set(t,e,n){return r.set(e,n),true},has(t,e){return r.has(e)},ownKeys(){return [...r.keys()]},getOwnPropertyDescriptor(t,e){if(r.has(e))return {configurable:true,enumerable:true,value:r.get(e),writable:true}}};return new Proxy({},a)}export{s as a};
|
package/dist/chunk-VLNCYBUN.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import {b as b$1,d as d$1,c}from'./chunk-7IUYJ6ZW.js';var y;function D(e){y=e;}var F="No mock adapter registered. Import a runtime entry once before creating spies \u2014 'vitest-auto-spy' (default, Vitest) or a runtime variant such as 'vitest-auto-spy/bun'.";function l(){if(!y)throw new Error(F);return y}function R(e){return `'${e.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}'`}function v(e,t){return Object.entries(e).map(([n,r])=>`${n}:${i(r,t)}`).join(",")}function V(e,t){return `new Map([${[...e.entries()].map(([r,o])=>`[${i(r,t)},${i(o,t)}]`).join(",")}])`}function W(e,t){if(t.has(e))return "[Circular]";t.add(e);let n;return e instanceof Date?n=`new Date(${e.getTime()})`:e instanceof Map?n=V(e,t):e instanceof Set?n=`new Set([${[...e].map(r=>i(r,t)).join(",")}])`:Array.isArray(e)?n=`[${e.map(r=>i(r,t)).join(",")}]`:n=`{${v(e,t)}}`,t.delete(e),n}function i(e,t=new WeakSet){return typeof e=="string"?R(e):typeof e=="bigint"?`${e}n`:typeof e=="symbol"?e.toString():typeof e=="function"?`[Function: ${e.name}]`:typeof e=="object"&&e!==null?W(e,t):Object.is(e,-0)?"-0":String(e)}var E=e=>`The function '${e}' was configured with 'mustBeCalledWith' and expects to be called with specific arguments. `,x="But the function was called without any arguments.",_=e=>{let t=i(e);return `But the actual arguments were: ${t.substring(1,t.length-1)}`},m={throwArgumentsError(e,t){let n=e.length===0?x:_(e);throw new Error(E(t)+n)}};var d=class{#e={};set(t,n){this.#e[this.#t(t)]=n;}get(t){return this.#e[this.#t(t)]}#t(t){return i(t)}};function $(e){return e.map(t=>({wrappedValue:t.delay===void 0?Promise.resolve(t.value):new Promise(n=>setTimeout(()=>n(t.value),t.delay))}))}function b(e,t){d$1(e,{resolveWith:n=>{t({value:Promise.resolve(n)});},rejectWith:n=>{t({value:n,_isRejectedPromise:true});},resolveWithPerCall:n=>{n.length!==0&&t({value:void 0,valuesPerCalls:$(n)});}});}function T(e,t){b(e,n=>{t.value=n.value,t._isRejectedPromise=n._isRejectedPromise??false,t.valuesPerCalls=n.valuesPerCalls??[];});}function k(e,t){b(e,n=>{e.argsToValuesMap.set(t,n);});}function z(e){return typeof e=="object"&&e!==null&&"value"in e}function h(e){if(e._isRejectedPromise)return Promise.reject(e.value);let t=e.valuesPerCalls?.shift();return t?t.wrappedValue:e.value}function S(e,t){let n=e.argsToValuesMap.get(t);return z(n)?{found:true,value:h(n)}:{found:false,value:void 0}}function B(e,t,n,r,o){if(e.wasConfigured){let s=S(e,r);if(s.found)return s.value}if(t.wasConfigured){let s=S(t,r);if(s.found)return s.value;m.throwArgumentsError(r,o);}return h(n)}function w(e,t){return e.wasConfigured=true,d$1(e,{mockReturnValue:n=>{e.argsToValuesMap.set(t,{value:n});}}),k(e,t),b$1()?.addToCalledWithObject(e,t),e}function C(){return {wasConfigured:false,argsToValuesMap:new d}}function O(e){let t=C(),n=C(),r={value:void 0},o=l().createMockFn((...u)=>B(t,n,r,u,e),e);T(o,r),b$1()?.addToFunctionSpy(o,r);let s=d$1(o,{calledWith:(...u)=>w(t,u),mustBeCalledWith:(...u)=>w(n,u)});return s}function j(e,t){Object.defineProperty(e,t,{get(){},set(n){},configurable:true});}function M(e,t,n){let r=l();return n==="setter"?r.spyOnSetter(e,t):r.spyOnGetter(e,t)}function P(e,t,n){let r={getters:{},setters:{}};e.accessorSpies=r,t.forEach(o=>{j(e,o),r.getters[o]=M(e,o,"getter");}),n.forEach(o=>{Object.prototype.hasOwnProperty.call(e,o)||j(e,o),r.setters[o]=M(e,o,"setter");});}var A={methodsToSpyOn:[],observablePropsToSpyOn:[],settersToSpyOn:[],gettersToSpyOn:[]};function H(e){let t=Object.getOwnPropertyDescriptors(e);return Object.keys(t).filter(n=>n!=="constructor"&&!t[n]?.get)}function G(e){let t=new Set,n=e;for(;n;){let r=Object.getPrototypeOf(n);r&&H(n).forEach(o=>t.add(o)),n=r;}return [...t]}function I(e){return e?Array.isArray(e)?{...A,methodsToSpyOn:e}:{methodsToSpyOn:e.methodsToSpyOn??[],observablePropsToSpyOn:e.observablePropsToSpyOn??[],settersToSpyOn:e.settersToSpyOn??[],gettersToSpyOn:e.gettersToSpyOn??[]}:{...A}}function pe(e,t){let{methodsToSpyOn:n,observablePropsToSpyOn:r,settersToSpyOn:o,gettersToSpyOn:s}=I(t),u=n.length>0?n:G(e.prototype),c$1={};return r.forEach(p=>{c$1[p]=c().createPropSpy();}),P(c$1,s,o),u.forEach(p=>{c$1[p]=O(p);}),c$1}export{D as a,l as b,m as c,O as d,pe as e};
|