vitest-auto-spy 3.15.0 → 3.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/angular.js +105 -77
- package/dist/bun-angular.js +7 -8
- package/dist/bun.js +5 -5
- package/dist/chunk-4K5F2NVN.js +91 -0
- package/dist/{chunk-AQSVZK2R.js → chunk-52DZMI55.js} +88 -145
- package/dist/{chunk-3OX44LME.js → chunk-GEXYXX4P.js} +2 -1
- package/dist/{chunk-CR5Q3YMQ.js → chunk-IZO7U34R.js} +4 -3
- package/dist/{chunk-DMOJ4NZH.js → chunk-MMKKLL5J.js} +1 -1
- package/dist/{chunk-LIOV4WZK.js → chunk-VPRUMHEL.js} +2 -2
- package/dist/console.js +2 -2
- package/dist/index.js +105 -77
- package/dist/jasmine.js +3 -3
- package/dist/nestjs.js +4 -4
- package/dist/node.cjs +111 -75
- package/dist/node.js +5 -5
- package/dist/react.js +5 -5
- package/dist/rxjs.d.ts +0 -8
- package/dist/rxjs.js +118 -76
- package/dist/setup.js +3 -3
- package/dist/svelte.js +5 -5
- package/dist/vue.js +6 -6
- package/package.json +4 -2
- package/dist/chunk-J5O72UHX.js +0 -6
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ identical API, with **RxJS** spies and **Angular / NestJS / React / Vue·Pinia /
|
|
|
19
19
|
[](https://www.npmjs.com/package/vitest-auto-spy)
|
|
20
20
|
[](https://www.npmjs.com/package/vitest-auto-spy)
|
|
21
21
|
[](https://github.com/ASDAlexey/vitest-auto-spy/actions/workflows/ci.yml)
|
|
22
|
-
[](#install)
|
|
23
23
|
[](https://www.npmjs.com/package/vitest-auto-spy)
|
|
24
24
|
[](https://github.com/ASDAlexey/vitest-auto-spy/actions/workflows/ci.yml)
|
|
25
25
|
[](./LICENSE)
|
package/dist/angular.js
CHANGED
|
@@ -380,6 +380,14 @@ Actual: ${actualCall(functionName, actualArgs)}`;
|
|
|
380
380
|
};
|
|
381
381
|
|
|
382
382
|
// src/lib/spy-decoration.ts
|
|
383
|
+
function detachedHelperError(helper) {
|
|
384
|
+
return new Error(
|
|
385
|
+
withDocs(
|
|
386
|
+
`[vitest-auto-spy] ${helper} was called off its spy: \`const { ${helper} } = spy.method\` loses the spy it configures. Call it as a method \u2014 spy.method.${helper}(\u2026) \u2014 or bind it first.`,
|
|
387
|
+
DOCS_LINKS.controlHelpers
|
|
388
|
+
)
|
|
389
|
+
);
|
|
390
|
+
}
|
|
383
391
|
function decorate(target, helpers) {
|
|
384
392
|
return Object.assign(target, helpers);
|
|
385
393
|
}
|
|
@@ -390,34 +398,35 @@ function toResolvedPerCallValues(valueConfigsPerCall) {
|
|
|
390
398
|
wrappedValue: config.delay === void 0 ? Promise.resolve(config.value) : new Promise((resolve) => setTimeout(() => resolve(config.value), config.delay))
|
|
391
399
|
}));
|
|
392
400
|
}
|
|
393
|
-
function
|
|
394
|
-
|
|
395
|
-
resolveWith
|
|
396
|
-
store({ value: Promise.resolve(value) });
|
|
401
|
+
function promiseHelpers(store) {
|
|
402
|
+
return {
|
|
403
|
+
resolveWith(value) {
|
|
404
|
+
store(this, { value: Promise.resolve(value) }, "resolveWith");
|
|
397
405
|
},
|
|
398
|
-
rejectWith
|
|
399
|
-
store({ value, _isRejectedPromise: true });
|
|
406
|
+
rejectWith(value) {
|
|
407
|
+
store(this, { value, _isRejectedPromise: true }, "rejectWith");
|
|
400
408
|
},
|
|
401
|
-
resolveWithPerCall
|
|
409
|
+
resolveWithPerCall(valueConfigsPerCall) {
|
|
402
410
|
if (valueConfigsPerCall.length === 0) {
|
|
403
411
|
return;
|
|
404
412
|
}
|
|
405
|
-
store({ value: void 0, valuesPerCalls: toResolvedPerCallValues(valueConfigsPerCall) });
|
|
413
|
+
store(this, { value: void 0, valuesPerCalls: toResolvedPerCallValues(valueConfigsPerCall) }, "resolveWithPerCall");
|
|
406
414
|
}
|
|
407
|
-
}
|
|
415
|
+
};
|
|
408
416
|
}
|
|
409
|
-
function
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
valueContainer.valuesPerCalls = container.valuesPerCalls ?? [];
|
|
415
|
-
});
|
|
417
|
+
function storePromiseConfig(valueContainer, container) {
|
|
418
|
+
valueContainer.value = container.value;
|
|
419
|
+
valueContainer._isRejectedPromise = container._isRejectedPromise ?? false;
|
|
420
|
+
valueContainer._isThrown = false;
|
|
421
|
+
valueContainer.valuesPerCalls = container.valuesPerCalls ?? [];
|
|
416
422
|
}
|
|
417
423
|
function addPromiseHelpersToCalledWithObject(calledWithObject, calledWithArgs) {
|
|
418
|
-
|
|
419
|
-
calledWithObject
|
|
420
|
-
|
|
424
|
+
decorate(
|
|
425
|
+
calledWithObject,
|
|
426
|
+
promiseHelpers((_self, container) => {
|
|
427
|
+
calledWithObject.argsToValuesMap.set(calledWithArgs, container);
|
|
428
|
+
})
|
|
429
|
+
);
|
|
421
430
|
}
|
|
422
431
|
|
|
423
432
|
// src/lib/settled-results.ts
|
|
@@ -467,11 +476,16 @@ function installSettledResultsPolyfill(mockFn) {
|
|
|
467
476
|
|
|
468
477
|
// src/lib/spy-mark.ts
|
|
469
478
|
var AUTO_SPY_MARK = /* @__PURE__ */ Symbol.for("vitest-auto-spy.mock");
|
|
470
|
-
var RESET_CONFIG = /* @__PURE__ */ Symbol.for("vitest-auto-spy.resetConfig");
|
|
471
|
-
var CLEAR_HOOK = /* @__PURE__ */ Symbol.for("vitest-auto-spy.clearHook");
|
|
472
479
|
var DEEP_CHILDREN = /* @__PURE__ */ Symbol.for("vitest-auto-spy.deepChildren");
|
|
473
|
-
function markAsMock(mock) {
|
|
474
|
-
Object.defineProperty(mock, AUTO_SPY_MARK, { value:
|
|
480
|
+
function markAsMock(mock, mark = true) {
|
|
481
|
+
Object.defineProperty(mock, AUTO_SPY_MARK, { value: mark, enumerable: false, configurable: true });
|
|
482
|
+
}
|
|
483
|
+
function isMarkHooks(value) {
|
|
484
|
+
return typeof value === "object" && value !== null && "reset" in value && "clear" in value;
|
|
485
|
+
}
|
|
486
|
+
function hooksOf(mock) {
|
|
487
|
+
const mark = Reflect.get(mock, AUTO_SPY_MARK);
|
|
488
|
+
return isMarkHooks(mark) ? mark : void 0;
|
|
475
489
|
}
|
|
476
490
|
function isAutoSpyLike(value) {
|
|
477
491
|
if (typeof value !== "object" || value === null) {
|
|
@@ -493,29 +507,11 @@ function readDeepChildren(value) {
|
|
|
493
507
|
}
|
|
494
508
|
return [...children.values()].filter(isMarkedMock);
|
|
495
509
|
}
|
|
496
|
-
function attachConfigReset(spy, reset2) {
|
|
497
|
-
Object.defineProperty(spy, RESET_CONFIG, { value: reset2, enumerable: false, configurable: true });
|
|
498
|
-
}
|
|
499
510
|
function runConfigReset(mock) {
|
|
500
|
-
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
const reset2 = Reflect.get(mock, RESET_CONFIG);
|
|
504
|
-
if (typeof reset2 === "function") {
|
|
505
|
-
reset2();
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
function attachClearHook(spy, clear) {
|
|
509
|
-
Object.defineProperty(spy, CLEAR_HOOK, { value: clear, enumerable: false, configurable: true });
|
|
511
|
+
hooksOf(mock)?.reset();
|
|
510
512
|
}
|
|
511
513
|
function runClearHook(mock) {
|
|
512
|
-
|
|
513
|
-
return;
|
|
514
|
-
}
|
|
515
|
-
const clear = Reflect.get(mock, CLEAR_HOOK);
|
|
516
|
-
if (typeof clear === "function") {
|
|
517
|
-
clear();
|
|
518
|
-
}
|
|
514
|
+
hooksOf(mock)?.clear();
|
|
519
515
|
}
|
|
520
516
|
|
|
521
517
|
// src/lib/function-spy.ts
|
|
@@ -610,6 +606,68 @@ function ensureCalledWithObject(state, chain) {
|
|
|
610
606
|
state[chain] = created;
|
|
611
607
|
return created;
|
|
612
608
|
}
|
|
609
|
+
var FunctionSpyInternals = class {
|
|
610
|
+
constructor(state, valueContainer, host, dispatch, recorder) {
|
|
611
|
+
this.state = state;
|
|
612
|
+
this.valueContainer = valueContainer;
|
|
613
|
+
this.host = host;
|
|
614
|
+
this.dispatch = dispatch;
|
|
615
|
+
this.recorder = recorder;
|
|
616
|
+
this.observable = void 0;
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* `resetAutoSpy` reverts this spy's configuration; the state lives here, where the host runner's
|
|
620
|
+
* own reset cannot reach it. Clearing the container in place keeps the reference the mock
|
|
621
|
+
* implementation closed over.
|
|
622
|
+
*/
|
|
623
|
+
reset() {
|
|
624
|
+
const { state, valueContainer } = this;
|
|
625
|
+
delete state.calledWith;
|
|
626
|
+
delete state.mustBeCalledWith;
|
|
627
|
+
valueContainer.value = void 0;
|
|
628
|
+
delete valueContainer._isRejectedPromise;
|
|
629
|
+
delete valueContainer._isThrown;
|
|
630
|
+
delete valueContainer.valuesPerCalls;
|
|
631
|
+
this.observable?.reset();
|
|
632
|
+
getMockAdapter().restoreImplementation(this.host, this.dispatch);
|
|
633
|
+
}
|
|
634
|
+
/** Empties the polyfilled `settledResults` on `clearAutoSpy` / `resetAutoSpy` (a no-op on Vitest, where the host clears its native array). */
|
|
635
|
+
clear() {
|
|
636
|
+
this.recorder.clear();
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
function internalsOf(self, helper) {
|
|
640
|
+
const mark = typeof self === "function" || typeof self === "object" && self !== null ? Reflect.get(self, AUTO_SPY_MARK) : void 0;
|
|
641
|
+
if (mark instanceof FunctionSpyInternals) {
|
|
642
|
+
return mark;
|
|
643
|
+
}
|
|
644
|
+
throw detachedHelperError(helper);
|
|
645
|
+
}
|
|
646
|
+
var SPY_HELPERS = /* @__PURE__ */ Object.assign(
|
|
647
|
+
// The inner call carries its own mark: a pure annotation covers the call it precedes, not its
|
|
648
|
+
// arguments, and an unmarked argument call is evaluated — and everything it reaches kept.
|
|
649
|
+
/* @__PURE__ */ promiseHelpers((self, container, helper) => {
|
|
650
|
+
storePromiseConfig(internalsOf(self, helper).valueContainer, container);
|
|
651
|
+
}),
|
|
652
|
+
{
|
|
653
|
+
failWith(error) {
|
|
654
|
+
const { valueContainer } = internalsOf(this, "failWith");
|
|
655
|
+
valueContainer.value = error;
|
|
656
|
+
valueContainer._isThrown = true;
|
|
657
|
+
valueContainer._isRejectedPromise = false;
|
|
658
|
+
valueContainer.valuesPerCalls = [];
|
|
659
|
+
},
|
|
660
|
+
calledWith(...calledWithArgs) {
|
|
661
|
+
return addMethodsToCalledWith(ensureCalledWithObject(internalsOf(this, "calledWith").state, "calledWith"), calledWithArgs);
|
|
662
|
+
},
|
|
663
|
+
mustBeCalledWith(...calledWithArgs) {
|
|
664
|
+
return addMethodsToCalledWith(
|
|
665
|
+
ensureCalledWithObject(internalsOf(this, "mustBeCalledWith").state, "mustBeCalledWith"),
|
|
666
|
+
calledWithArgs
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
);
|
|
613
671
|
function createFunctionSpy(name, unstubbed) {
|
|
614
672
|
const valueContainer = { value: void 0 };
|
|
615
673
|
const state = { valueContainer };
|
|
@@ -621,46 +679,16 @@ function createFunctionSpy(name, unstubbed) {
|
|
|
621
679
|
const functionSpy = getMockAdapter().createMockFn(dispatch, name);
|
|
622
680
|
const recorder = installSettledResultsPolyfill(functionSpy);
|
|
623
681
|
settledResultsRecorder = recorder;
|
|
624
|
-
|
|
625
|
-
const
|
|
626
|
-
|
|
627
|
-
// The sync twin of `resolveWith` / `nextWith`, and the reason it is here rather than left to
|
|
628
|
-
// the runner: Vitest 4.1 grew `mockThrow`, but Bun and `node:test` have nothing like it, and
|
|
629
|
-
// no runtime has a way to make a *`calledWith` chain* throw — `mockImplementation` replaces the
|
|
630
|
-
// whole dispatch, which is the opposite of configuring one set of arguments.
|
|
631
|
-
//
|
|
632
|
-
// `failWith` and not `throwWith`, which is the name the shape asks for: `throwWith` is already
|
|
633
|
-
// the observable helper that *errors the stream*, it is attached to every spy at runtime (the
|
|
634
|
-
// return type that tells the two apart exists only in the types), and whichever is installed
|
|
635
|
-
// last wins. Sharing the name therefore breaks one of them on every spy in the run — which it
|
|
636
|
-
// did, loudly, the first time this was written that way.
|
|
637
|
-
failWith: (error) => {
|
|
638
|
-
valueContainer.value = error;
|
|
639
|
-
valueContainer._isThrown = true;
|
|
640
|
-
valueContainer._isRejectedPromise = false;
|
|
641
|
-
valueContainer.valuesPerCalls = [];
|
|
642
|
-
},
|
|
643
|
-
calledWith: (...calledWithArgs) => addMethodsToCalledWith(ensureCalledWithObject(state, "calledWith"), calledWithArgs),
|
|
644
|
-
mustBeCalledWith: (...calledWithArgs) => addMethodsToCalledWith(ensureCalledWithObject(state, "mustBeCalledWith"), calledWithArgs)
|
|
645
|
-
});
|
|
682
|
+
const internals = new FunctionSpyInternals(state, valueContainer, functionSpy, dispatch, recorder);
|
|
683
|
+
const spy = decorate(functionSpy, SPY_HELPERS);
|
|
684
|
+
internals.observable = getObservableSupport()?.addToFunctionSpy(spy, valueContainer);
|
|
646
685
|
getJasmineSupport()?.addToFunctionSpy(spy, {
|
|
647
686
|
name,
|
|
648
687
|
restoreDispatch: () => {
|
|
649
688
|
getMockAdapter().restoreImplementation(functionSpy, dispatch);
|
|
650
689
|
}
|
|
651
690
|
});
|
|
652
|
-
|
|
653
|
-
delete state.calledWith;
|
|
654
|
-
delete state.mustBeCalledWith;
|
|
655
|
-
valueContainer.value = void 0;
|
|
656
|
-
delete valueContainer._isRejectedPromise;
|
|
657
|
-
delete valueContainer._isThrown;
|
|
658
|
-
delete valueContainer.valuesPerCalls;
|
|
659
|
-
resetObservableStream?.();
|
|
660
|
-
getMockAdapter().restoreImplementation(functionSpy, dispatch);
|
|
661
|
-
});
|
|
662
|
-
attachClearHook(spy, () => recorder.clear());
|
|
663
|
-
markAsMock(spy);
|
|
691
|
+
markAsMock(spy, internals);
|
|
664
692
|
return exposeAsSpy(spy);
|
|
665
693
|
}
|
|
666
694
|
function exposeAsSpy(spy) {
|
package/dist/bun-angular.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import './chunk-Y4YG7UOK.js';
|
|
2
|
-
import { createSpyForToken } from './chunk-
|
|
2
|
+
import { createSpyForToken } from './chunk-VPRUMHEL.js';
|
|
3
3
|
import './chunk-NQXXUJPS.js';
|
|
4
|
-
export { asInstance, asInstances, asSpy, assertMocked, captureArg, compareTestRuns, createFixture, createFixtureFactory, createMock, createSpyClass, describeDuplicateCopies, diffByField, expectCompletion, expectEmission, expectEmissions, expectError, expectNoEmission, flushEventLoop, flushEventLoopUntil, formatTestRunComparison, getPackageCopies, intersectionEntry, mockConstructor, mockDeep, moduleNamespace, mutationRecord, narrow, resizeEntry, setEmissionTimeout, settleDynamicImport, stubAbortController, stubConstructor, stubIntersectionObserver, stubMediaElement, stubMutationObserver, stubObserver, stubResizeObserver, summarizeTestRun, withOverrides } from './chunk-
|
|
5
|
-
export { countMockedProps, mockAccessorsProp, mockReadonlyProp, mockReadonlyPropGetter, mockValueProp, restoreMockedProps } from './chunk-
|
|
6
|
-
import { createSpyFromClass } from './chunk-
|
|
7
|
-
export { autoMocked, clearAutoSpy, createAutoMock, createSpyFromClass, resetAutoSpy } from './chunk-
|
|
4
|
+
export { asInstance, asInstances, asSpy, assertMocked, captureArg, compareTestRuns, createFixture, createFixtureFactory, createMock, createSpyClass, describeDuplicateCopies, diffByField, expectCompletion, expectEmission, expectEmissions, expectError, expectNoEmission, flushEventLoop, flushEventLoopUntil, formatTestRunComparison, getPackageCopies, intersectionEntry, mockConstructor, mockDeep, moduleNamespace, mutationRecord, narrow, resizeEntry, setEmissionTimeout, settleDynamicImport, stubAbortController, stubConstructor, stubIntersectionObserver, stubMediaElement, stubMutationObserver, stubObserver, stubResizeObserver, summarizeTestRun, withOverrides } from './chunk-IZO7U34R.js';
|
|
5
|
+
export { countMockedProps, mockAccessorsProp, mockReadonlyProp, mockReadonlyPropGetter, mockValueProp, restoreMockedProps } from './chunk-MMKKLL5J.js';
|
|
6
|
+
import { createSpyFromClass } from './chunk-GEXYXX4P.js';
|
|
7
|
+
export { autoMocked, clearAutoSpy, createAutoMock, createSpyFromClass, resetAutoSpy } from './chunk-GEXYXX4P.js';
|
|
8
8
|
import './chunk-PC3FAZT3.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import './chunk-J5O72UHX.js';
|
|
9
|
+
export { createFunctionSpy, errorHandler } from './chunk-52DZMI55.js';
|
|
10
|
+
import { withDocs, DOCS_LINKS, isAutoSpyLike } from './chunk-4K5F2NVN.js';
|
|
12
11
|
import '@angular/compiler';
|
|
13
12
|
import { NgModule, provideZonelessChangeDetection, Injector, runInInjectionContext, NO_ERRORS_SCHEMA, ApplicationRef, ɵSIGNAL as _SIGNAL } from '@angular/core';
|
|
14
13
|
import { getTestBed, TestBed } from '@angular/core/testing';
|
package/dist/bun.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import './chunk-Y4YG7UOK.js';
|
|
2
2
|
import './chunk-NQXXUJPS.js';
|
|
3
|
-
export { asInstance, asInstances, asSpy, assertMocked, captureArg, compareTestRuns, createFixture, createFixtureFactory, createMock, createSpyClass, describeDuplicateCopies, diffByField, expectCompletion, expectEmission, expectEmissions, expectError, expectNoEmission, flushEventLoop, flushEventLoopUntil, formatTestRunComparison, getPackageCopies, intersectionEntry, mockConstructor, mockDeep, moduleNamespace, mutationRecord, narrow, resizeEntry, setEmissionTimeout, settleDynamicImport, stubAbortController, stubConstructor, stubIntersectionObserver, stubMediaElement, stubMutationObserver, stubObserver, stubResizeObserver, summarizeTestRun, withOverrides } from './chunk-
|
|
4
|
-
export { countMockedProps, mockAccessorsProp, mockReadonlyProp, mockReadonlyPropGetter, mockValueProp, restoreMockedProps } from './chunk-
|
|
5
|
-
export { autoMocked, clearAutoSpy, createAutoMock, createSpyFromClass, resetAutoSpy } from './chunk-
|
|
3
|
+
export { asInstance, asInstances, asSpy, assertMocked, captureArg, compareTestRuns, createFixture, createFixtureFactory, createMock, createSpyClass, describeDuplicateCopies, diffByField, expectCompletion, expectEmission, expectEmissions, expectError, expectNoEmission, flushEventLoop, flushEventLoopUntil, formatTestRunComparison, getPackageCopies, intersectionEntry, mockConstructor, mockDeep, moduleNamespace, mutationRecord, narrow, resizeEntry, setEmissionTimeout, settleDynamicImport, stubAbortController, stubConstructor, stubIntersectionObserver, stubMediaElement, stubMutationObserver, stubObserver, stubResizeObserver, summarizeTestRun, withOverrides } from './chunk-IZO7U34R.js';
|
|
4
|
+
export { countMockedProps, mockAccessorsProp, mockReadonlyProp, mockReadonlyPropGetter, mockValueProp, restoreMockedProps } from './chunk-MMKKLL5J.js';
|
|
5
|
+
export { autoMocked, clearAutoSpy, createAutoMock, createSpyFromClass, resetAutoSpy } from './chunk-GEXYXX4P.js';
|
|
6
6
|
import './chunk-PC3FAZT3.js';
|
|
7
|
-
export { createFunctionSpy, errorHandler } from './chunk-
|
|
8
|
-
import './chunk-
|
|
7
|
+
export { createFunctionSpy, errorHandler } from './chunk-52DZMI55.js';
|
|
8
|
+
import './chunk-4K5F2NVN.js';
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// src/lib/docs-links.ts
|
|
2
|
+
var DOCS = "https://asdalexey.github.io/vitest-auto-spy";
|
|
3
|
+
var DOCS_LINKS = {
|
|
4
|
+
angular: `${DOCS}/adapters/angular`,
|
|
5
|
+
// Their own pages rather than anchors on `adapters/angular`: a reader who hits one of these arrived
|
|
6
|
+
// from a failure, not from reading, and the page they want is the one about that check — not the
|
|
7
|
+
// one about the adapter that hosts it.
|
|
8
|
+
angularDiagnostics: `${DOCS}/adapters/angular-diagnostics`,
|
|
9
|
+
angularOverrides: `${DOCS}/adapters/angular-overrides`,
|
|
10
|
+
autoMockByType: `${DOCS}/core/auto-mock-by-type`,
|
|
11
|
+
bunAngular: `${DOCS}/runtimes/bun-angular`,
|
|
12
|
+
createSpyFromClass: `${DOCS}/core/create-spy-from-class`,
|
|
13
|
+
constructorSpy: `${DOCS}/utilities/constructor-doubles`,
|
|
14
|
+
controlHelpers: `${DOCS}/core/control-helpers`,
|
|
15
|
+
eventLoop: `${DOCS}/utilities/event-loop`,
|
|
16
|
+
fakeTimers: `${DOCS}/utilities/fake-timers`,
|
|
17
|
+
installation: `${DOCS}/core/installation`,
|
|
18
|
+
mediaElement: `${DOCS}/utilities/media-element`,
|
|
19
|
+
moduleMocks: `${DOCS}/utilities/module-mocks`,
|
|
20
|
+
observerStubs: `${DOCS}/utilities/observer-stubs`,
|
|
21
|
+
// The recipe for the one failure no spy library can work around: a binding the bundler already
|
|
22
|
+
// inlined. Deep-linked to the section rather than the page, because the page's first half is
|
|
23
|
+
// about the *silent* half of the same problem and the reader arriving here has the loud one.
|
|
24
|
+
realSeam: `${DOCS}/utilities/module-mocks#provide-a-real-seam`,
|
|
25
|
+
rxjs: `${DOCS}/runtimes/rxjs`,
|
|
26
|
+
setup: `${DOCS}/utilities/setup`,
|
|
27
|
+
// Its own page rather than a section of the factory's: the reader arriving here was thrown at by a
|
|
28
|
+
// double they configured somewhere else entirely, and the question they have is what counts as
|
|
29
|
+
// configured — which is the whole page, not a paragraph of another one.
|
|
30
|
+
strictMode: `${DOCS}/core/strict-mode`,
|
|
31
|
+
trackInjections: `${DOCS}/utilities/track-injections`
|
|
32
|
+
};
|
|
33
|
+
function withDocs(message, link) {
|
|
34
|
+
return `${message}
|
|
35
|
+
Docs: ${link}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/lib/spy-mark.ts
|
|
39
|
+
var AUTO_SPY_MARK = /* @__PURE__ */ Symbol.for("vitest-auto-spy.mock");
|
|
40
|
+
var DEEP_CHILDREN = /* @__PURE__ */ Symbol.for("vitest-auto-spy.deepChildren");
|
|
41
|
+
function markAsMock(mock, mark = true) {
|
|
42
|
+
Object.defineProperty(mock, AUTO_SPY_MARK, { value: mark, enumerable: false, configurable: true });
|
|
43
|
+
}
|
|
44
|
+
function isMarkHooks(value) {
|
|
45
|
+
return typeof value === "object" && value !== null && "reset" in value && "clear" in value;
|
|
46
|
+
}
|
|
47
|
+
function hooksOf(mock) {
|
|
48
|
+
const mark = Reflect.get(mock, AUTO_SPY_MARK);
|
|
49
|
+
return isMarkHooks(mark) ? mark : void 0;
|
|
50
|
+
}
|
|
51
|
+
function isAutoSpyLike(value) {
|
|
52
|
+
if (typeof value !== "object" || value === null) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
if (AUTO_SPY_MARK in value) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
const accessorSpies = Reflect.get(value, "accessorSpies");
|
|
59
|
+
return typeof accessorSpies === "object" && accessorSpies !== null;
|
|
60
|
+
}
|
|
61
|
+
function isMarkedMock(value) {
|
|
62
|
+
return typeof value === "function" && AUTO_SPY_MARK in value;
|
|
63
|
+
}
|
|
64
|
+
function readDeepChildren(value) {
|
|
65
|
+
const children = Reflect.get(value, DEEP_CHILDREN);
|
|
66
|
+
if (!(children instanceof Map)) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
return [...children.values()].filter(isMarkedMock);
|
|
70
|
+
}
|
|
71
|
+
function runConfigReset(mock) {
|
|
72
|
+
hooksOf(mock)?.reset();
|
|
73
|
+
}
|
|
74
|
+
function runClearHook(mock) {
|
|
75
|
+
hooksOf(mock)?.clear();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/lib/spy-decoration.ts
|
|
79
|
+
function detachedHelperError(helper) {
|
|
80
|
+
return new Error(
|
|
81
|
+
withDocs(
|
|
82
|
+
`[vitest-auto-spy] ${helper} was called off its spy: \`const { ${helper} } = spy.method\` loses the spy it configures. Call it as a method \u2014 spy.method.${helper}(\u2026) \u2014 or bind it first.`,
|
|
83
|
+
DOCS_LINKS.controlHelpers
|
|
84
|
+
)
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
function decorate(target, helpers) {
|
|
88
|
+
return Object.assign(target, helpers);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { AUTO_SPY_MARK, DEEP_CHILDREN, DOCS_LINKS, decorate, detachedHelperError, hooksOf, isAutoSpyLike, isMarkedMock, markAsMock, readDeepChildren, runClearHook, runConfigReset, withDocs };
|