vitest-auto-spy 5.32.1 → 5.32.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/CHANGELOG.md +16 -1
- package/dist/cli.js +1 -1
- package/dist/eslint-plugin.cjs +5 -0
- package/package.json +1 -1
- package/skills/vitest-auto-spy/SKILL.md +1 -1
package/AGENTS.md
CHANGED
|
@@ -4000,7 +4000,7 @@ blanket downgrade so those keep their severity; do not copy the two names into a
|
|
|
4000
4000
|
| `prefer-set-inputs` | `warn` | suggest | a run of `fixture.componentRef.setInput('title', v)` on one fixture → `await setInputs(fixture, { title: v })` — the name is resolved against the compiled definition before the first write (an undeclared one is an `NG0303` and no change) and the value is typed. The run collapses into one call and a `detectChanges()` under it goes; offered, not applied, because `stable()` ticks and a zone.js suite answers that with `NG0101` |
|
|
4001
4001
|
| `prefer-spy-on-own-method` | `warn` | `--fix` / suggest | `createSpyFromInstance(x, { onlyMethodsToSpyOn: ['m'], passthrough: true })` read for `m` alone — `.m` on the call, `const { m } = …`, a bare statement, or a name read only as `v.m` → `spyOnOwnMethod(x, 'm')`; the same whitelist with `returns: { m: undefined }` → `spyOnVoidMethod(x, 'm')`. Both fix, import and all; a `Spy<X>` annotation becomes `Spy<X>['m']` in a suggestion. A bare `returns: { m: undefined }` seed is a suggestion, offered only on a real event or element — `new MouseEvent(…)`, `document.createElement(…)`, `fixture.nativeElement` — never on a double |
|
|
4002
4002
|
| `prefer-observer-stub` | `error` | — | a hand-rolled observer global → `stubIntersectionObserver()` / `stubResizeObserver()` / `stubMutationObserver()`; the manual save-and-restore goes too, `restoreMockedProps()` runs the undo |
|
|
4003
|
-
| `no-hand-assigned-global` | `error` | `--fix` | a double assigned to a global (`global.fetch = vi.fn()`, `window.matchMedia = vi.fn()`, `window.localStorage = { getItem: vi.fn() }`) with no restore in `afterEach` / `afterAll` / `onTestFinished` → `mockValueProp(globalThis, name, value)` or `vi.stubGlobal` + `unstubGlobals`; `blockNetwork()` for network globals, `stubWebStorage()` for the storages
|
|
4003
|
+
| `no-hand-assigned-global` | `error` | `--fix` | a double assigned to a global (`global.fetch = vi.fn()`, `window.matchMedia = vi.fn()`, `window.localStorage = { getItem: vi.fn() }`) with no restore in `afterEach` / `afterAll` / `onTestFinished` → `mockValueProp(globalThis, name, value)` or `vi.stubGlobal` + `unstubGlobals`; `blockNetwork()` for network globals, `stubWebStorage()` for the storages, `stubWorker({ respond })` for `Worker`; the three observers stay with `prefer-observer-stub`; any value written into an imported object (`environment.production = true`) → `mockValueProp(environment, 'production', true)`, fixed in a test or `beforeEach` |
|
|
4004
4004
|
| `prefer-stub-response` | `error` | — | an object literal cast to `Response` (`as Response`, `as unknown as Response`, `<Response>{ … }`) or `createMock<Response>(…)` / `createAutoMock<Response>(…)` → `stubResponse({ body })` from `/setup`; the literal answers `undefined` for every member it does not list (`status`, `headers`, `text()`) and the cast is what makes that compile. `Response` must resolve to the **global**, so an Express handler's or a generated client's `Response` is never reported |
|
|
4005
4005
|
| `prefer-provide-activated-route` | `error` | — | a hand-built `ActivatedRoute` — any `useValue` / `useClass` / `useFactory` / `useExisting`, and `provideAutoSpy(ActivatedRoute)` too → `provideActivatedRoute({ … })`; the double knows either the streams or the snapshot, never both, and `injectActivatedRoute().setParams(…)` moves them together mid-test |
|
|
4006
4006
|
| `no-passthrough-console-spy` | `error` | suggest | `vi.spyOn(console, m)` nothing gives an implementation — it calls through and prints → `installConsoleSpies()` + `consoleXSpy`, or `.mockImplementation(() => undefined)` |
|
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,20 @@ The latest released version here must always match the one published on
|
|
|
10
10
|
|
|
11
11
|
## [Unreleased]
|
|
12
12
|
|
|
13
|
+
## [5.32.2] - 2026-09-25
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- **`no-hand-assigned-global` points a hand-assigned `Worker` at `stubWorker`.** `globalThis.Worker = …`
|
|
18
|
+
got the generic `handAssignedGlobal` message and the `stubConstructor` suggestion; it now gets its own
|
|
19
|
+
message naming `stubWorker({ respond })` from `/dom-stubs`, the way the storages name `stubWebStorage()`.
|
|
20
|
+
|
|
21
|
+
### Docs
|
|
22
|
+
|
|
23
|
+
- **The introduction no longer says the spy is powered by the runner's mock primitive.** Since 4.1 the
|
|
24
|
+
default engine is the library's own mock function; the introduction page and its Russian counterpart
|
|
25
|
+
now say so and name `setSpyEngine('runner')` as the way back to `vi.fn()`.
|
|
26
|
+
|
|
13
27
|
## [5.32.1] - 2026-09-25
|
|
14
28
|
|
|
15
29
|
### Fixed
|
|
@@ -8232,7 +8246,8 @@ by hand there, in more than one place, by more than one person.
|
|
|
8232
8246
|
`mockAccessorsProp`.
|
|
8233
8247
|
- Dual ESM + CJS build with type declarations; 100% test coverage.
|
|
8234
8248
|
|
|
8235
|
-
[Unreleased]: https://github.com/ASDAlexey/vitest-auto-spy/compare/v5.32.
|
|
8249
|
+
[Unreleased]: https://github.com/ASDAlexey/vitest-auto-spy/compare/v5.32.2...HEAD
|
|
8250
|
+
[5.32.2]: https://github.com/ASDAlexey/vitest-auto-spy/compare/v5.32.1...v5.32.2
|
|
8236
8251
|
[5.32.1]: https://github.com/ASDAlexey/vitest-auto-spy/compare/v5.32.0...v5.32.1
|
|
8237
8252
|
[5.32.0]: https://github.com/ASDAlexey/vitest-auto-spy/compare/v5.31.0...v5.32.0
|
|
8238
8253
|
[5.31.0]: https://github.com/ASDAlexey/vitest-auto-spy/compare/v5.30.0...v5.31.0
|
package/dist/cli.js
CHANGED
|
@@ -3204,7 +3204,7 @@ function checkForeignPragma(graph) {
|
|
|
3204
3204
|
}
|
|
3205
3205
|
|
|
3206
3206
|
// src/cli/checks/export-map.generated.ts
|
|
3207
|
-
var EXPORT_MAP_VERSION = "5.32.
|
|
3207
|
+
var EXPORT_MAP_VERSION = "5.32.1";
|
|
3208
3208
|
var ENTRY_SPECIFIERS = "vitest-auto-spy vitest-auto-spy/bun vitest-auto-spy/bun-angular vitest-auto-spy/node vitest-auto-spy/rstest vitest-auto-spy/rxjs vitest-auto-spy/console vitest-auto-spy/dom-stubs vitest-auto-spy/diagnostics vitest-auto-spy/jasmine vitest-auto-spy/jasmine-compat vitest-auto-spy/observer-spy vitest-auto-spy/angular vitest-auto-spy/angular/diagnostics vitest-auto-spy/angular/doubles vitest-auto-spy/angular/matchers vitest-auto-spy/angular-http vitest-auto-spy/angular-router vitest-auto-spy/signal-forms vitest-auto-spy/nestjs vitest-auto-spy/react vitest-auto-spy/vue vitest-auto-spy/svelte vitest-auto-spy/setup vitest-auto-spy/zone vitest-auto-spy/eslint-plugin vitest-auto-spy/perf-reporter";
|
|
3209
3209
|
var EXPORTED_BY = {
|
|
3210
3210
|
AccessorImplementations: "0 1 2 3 4 12 20 21 22",
|
package/dist/eslint-plugin.cjs
CHANGED
|
@@ -2091,6 +2091,7 @@ var preferObserverStub = defineRule({
|
|
|
2091
2091
|
// src/lib/eslint/global-assignment.ts
|
|
2092
2092
|
var NETWORK_GLOBALS = /* @__PURE__ */ new Set(["EventSource", "WebSocket", "XMLHttpRequest", "fetch"]);
|
|
2093
2093
|
var WEB_STORAGES = /* @__PURE__ */ new Set(["localStorage", "sessionStorage"]);
|
|
2094
|
+
var WORKER_GLOBALS = /* @__PURE__ */ new Set(["Worker"]);
|
|
2094
2095
|
var TEARDOWN_HOOKS = /* @__PURE__ */ new Set(["afterAll", "afterEach", "onTestFinished"]);
|
|
2095
2096
|
var PER_TEST = /* @__PURE__ */ new Set(["beforeEach", "it", "test"]);
|
|
2096
2097
|
function insideTeardown(node) {
|
|
@@ -2121,6 +2122,9 @@ function messageFor(name) {
|
|
|
2121
2122
|
if (NETWORK_GLOBALS.has(name)) {
|
|
2122
2123
|
return "networkGlobal";
|
|
2123
2124
|
}
|
|
2125
|
+
if (WORKER_GLOBALS.has(name)) {
|
|
2126
|
+
return "workerGlobal";
|
|
2127
|
+
}
|
|
2124
2128
|
return WEB_STORAGES.has(name) ? "webStorage" : "handAssignedGlobal";
|
|
2125
2129
|
}
|
|
2126
2130
|
function globalFix(name) {
|
|
@@ -2199,6 +2203,7 @@ var noHandAssignedGlobal = defineRule({
|
|
|
2199
2203
|
messages: {
|
|
2200
2204
|
networkGlobal: "`{{name}}` is replaced by assignment and nothing puts the real one back, so under `isolate: false` the fake answers every later test in the worker. Install it with `{{fix}}`, which restores the original after the test.",
|
|
2201
2205
|
webStorage: "`{{name}}` is replaced by assignment and nothing puts the real one back, so the fake storage, and whatever the test wrote into it, leaks into every later test. Use `stubWebStorage('{{name}}')` from `vitest-auto-spy/dom-stubs`, which is restored after every test.",
|
|
2206
|
+
workerGlobal: "`{{name}}` is replaced by assignment and nothing puts the real one back, so under `isolate: false` every later test in the worker constructs the double. Use `stubWorker({ respond })` from `vitest-auto-spy/dom-stubs`, which is restored after every test.",
|
|
2202
2207
|
handAssignedGlobal: "`{{name}}` is replaced by assignment and nothing puts the real one back, so under `isolate: false` the double stays installed for every later test in the worker. Install it with `{{fix}}`, which restores the original after the test.",
|
|
2203
2208
|
importedMember: "`{{object}}.{{name}}` is written into an imported module, which stays cached for the worker, so the value answers later tests that never set it. Use `mockValueProp({{object}}, '{{name}}', value)`, which restores it after the test.",
|
|
2204
2209
|
restoreInTest: "`{{name}}` is replaced and put back by hand outside a teardown hook, so the first failing assertion before the restore leaves the double installed for every later test. Use `mockValueProp(globalThis, '{{name}}', value)`, whose undo runs in a hook, or move the restore into `afterEach`."
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-auto-spy",
|
|
3
|
-
"version": "5.32.
|
|
3
|
+
"version": "5.32.2",
|
|
4
4
|
"description": "Auto-generate fully-typed test spies from a class — across Vitest, Bun, node:test and Rstest, with Angular/NestJS/React/Vue/Svelte recipes. Drop-in replacement for jest-auto-spies and jasmine-auto-spies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"auto-mock",
|
|
@@ -539,7 +539,7 @@ from `vitest-auto-spy/angular-router` rather than at `provideAutoSpy`.
|
|
|
539
539
|
|
|
540
540
|
**`no-unasserted-argument` reports a bare `expect(spy).toHaveBeenCalled()` where the file itself says the arguments are the point** — either the same subject is pinned with `toHaveBeenCalledWith(…)` in another test of the file, or the test's title says `with` and its body asserts nothing but bare calls. Narrower than `vitest/prefer-called-with` on purpose: on one 2032-file suite that reports 1941 times in 360 files and this one 175 in 90. `not.toHaveBeenCalled()` and the counting matchers are never reported. `warn` rather than `error`, because the repair is the argument list the test should have named — `toHaveBeenCalledWith(…)`, `toHaveBeenCalledExactlyOnceWith(…)`, or `mustBeCalledWith(…)` where the double is configured — and that is the one thing the rule cannot write.
|
|
541
541
|
|
|
542
|
-
**`no-hand-assigned-global` reports a double assigned straight to a global** — `global.fetch = vi.fn(…)`, `window.matchMedia = vi.fn()`, `window.localStorage = { getItem: vi.fn() }` — unless the file puts it back in `afterEach` / `afterAll` / `onTestFinished`. Replace the assignment with `mockValueProp(globalThis, 'fetch', vi.fn(…))` (undone by `restoreMockedProps()`, which `setupAutoSpy()` runs), use `blockNetwork()` when the spec only has to stay offline,
|
|
542
|
+
**`no-hand-assigned-global` reports a double assigned straight to a global** — `global.fetch = vi.fn(…)`, `window.matchMedia = vi.fn()`, `window.localStorage = { getItem: vi.fn() }` — unless the file puts it back in `afterEach` / `afterAll` / `onTestFinished`. Replace the assignment with `mockValueProp(globalThis, 'fetch', vi.fn(…))` (undone by `restoreMockedProps()`, which `setupAutoSpy()` runs), use `blockNetwork()` when the spec only has to stay offline, `stubWebStorage('localStorage')` for the storages, and `stubWorker({ respond })` for `globalThis.Worker`. Do not "fix" it by adding a restore as the last line of the `it`: that form is reported too, because a red assertion skips it. The same rule reports any value written into an imported object — `environment.production = true` — and `--fix` rewrites it to `mockValueProp(environment, 'production', true)` inside a test or `beforeEach`.
|
|
543
543
|
|
|
544
544
|
**`registerAutoSpyDefaults(Class, config)` puts a spy's composition with the class, once.** Call it
|
|
545
545
|
from the setup file for a class every suite doubles the same way (`Router` with
|