first commit

This commit is contained in:
Warunee Tamkoo 2023-09-06 14:51:44 +07:00
commit eb2f504652
32490 changed files with 5731109 additions and 0 deletions

21
node_modules/tinyspy/LICENCE generated vendored Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Tinylibs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

11
node_modules/tinyspy/README.md generated vendored Normal file
View file

@ -0,0 +1,11 @@
# tinyspy
> minimal fork of nanospy, with more features 🕵🏻‍♂️
A `9KB` package for minimal and easy testing with no dependencies.
This package was created for having a tiny spy library to use in `vitest`, but it can also be used in `jest` and other test environments.
_In case you need more tiny libraries like tinypool or tinyspy, please consider submitting an [RFC](https://github.com/tinylibs/rfcs)_
## Docs
Read **[full docs](https://github.com/tinylibs/tinyspy#readme)** on GitHub.

122
node_modules/tinyspy/dist/index.cjs generated vendored Normal file
View file

@ -0,0 +1,122 @@
"use strict";
var h = Object.defineProperty;
var O = Object.getOwnPropertyDescriptor;
var P = Object.getOwnPropertyNames;
var K = Object.prototype.hasOwnProperty;
var b = (t, e) => {
for (var n in e)
h(t, n, { get: e[n], enumerable: !0 });
}, M = (t, e, n, s) => {
if (e && typeof e == "object" || typeof e == "function")
for (let r of P(e))
!K.call(t, r) && r !== n && h(t, r, { get: () => e[r], enumerable: !(s = O(e, r)) || s.enumerable });
return t;
};
var F = (t) => M(h({}, "__esModule", { value: !0 }), t);
// src/index.ts
var E = {};
b(E, {
restoreAll: () => C,
spies: () => g,
spy: () => A,
spyOn: () => I
});
module.exports = F(E);
// src/utils.ts
function d(t, e) {
if (!t)
throw new Error(e);
}
function y(t, e) {
return typeof e === t;
}
function S(t) {
return t instanceof Promise;
}
function f(t, e, n) {
Object.defineProperty(t, e, n);
}
// src/spy.ts
var g = /* @__PURE__ */ new Set();
function A(t) {
d(y("function", t) || y("undefined", t), "cannot spy on a non-function value");
let e = function(...s) {
if (e.called = !0, e.callCount++, e.calls.push(s), e.next) {
let [i, l] = e.next;
if (e.results.push(e.next), e.next = null, i === "ok")
return l;
throw l;
}
let r, o = "ok";
if (e.impl)
try {
r = e.impl.apply(this, s), o = "ok";
} catch (i) {
throw r = i, o = "error", e.results.push([o, i]), i;
}
let c = [o, r];
if (S(r)) {
let i = r.then((l) => c[1] = l).catch((l) => {
throw c[0] = "error", c[1] = l, l;
});
Object.assign(i, r), r = i;
}
return e.results.push(c), r;
};
f(e, "_isMockFunction", { get: () => !0 }), f(e, "length", { value: t ? t.length : 0 }), f(e, "returns", {
get() {
return this.results.map(([, s]) => s);
}
}), f(e, "name", { value: t && t.name || "spy" });
let n = () => {
e.called = !1, e.callCount = 0, e.results = [], e.calls = [];
};
return n(), e.impl = t, e.reset = n, e.nextError = (s) => (e.next = ["error", s], e), e.nextResult = (s) => (e.next = ["ok", s], e), e;
}
// src/spyOn.ts
var v = (t, e) => Object.getOwnPropertyDescriptor(t, e);
function I(t, e, n) {
d(!y("undefined", t), "spyOn could not find an object to spy upon"), d(y("object", t) || y("function", t), "cannot spyOn on a primitive value");
let s = () => {
if (typeof e != "object")
return [e, "value"];
if ("getter" in e && "setter" in e)
throw new Error("cannot spy on both getter and setter");
if ("getter" in e)
return [e.getter, "get"];
if ("setter" in e)
return [e.setter, "set"];
throw new Error("specify getter or setter to spy on");
}, [r, o] = s(), c = v(t, r), i = Object.getPrototypeOf(t), l = i && v(i, r), a = c || l;
d(a || r in t, `${String(r)} does not exist`);
let R = !1;
o === "value" && a && !a.value && a.get && (o = "get", R = !0, n = a.get());
let u;
a ? u = a[o] : o !== "value" ? u = () => t[r] : u = t[r], n || (n = u);
let p = A(n), w = (T) => {
let { value: G, ...m } = a || {
configurable: !0,
writable: !0
};
o !== "value" && delete m.writable, m[o] = T, f(t, r, m);
}, k = () => w(u);
return p.restore = k, p.getOriginal = () => R ? u() : u, p.willCall = (T) => (p.impl = T, p), w(R ? () => p : p), g.add(p), p;
}
// src/restoreAll.ts
function C() {
for (let t of g)
t.restore();
g.clear();
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
restoreAll,
spies,
spy,
spyOn
});

52
node_modules/tinyspy/dist/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,52 @@
declare let spies: Set<SpyImpl<any[], any>>;
declare type ReturnError = ['error', any];
declare type ReturnOk<R> = ['ok', R];
declare type ResultFn<R> = ReturnError | ReturnOk<R>;
interface Spy<A extends any[] = any[], R = any> {
called: boolean;
callCount: number;
calls: A[];
length: number;
results: ResultFn<R>[];
returns: R[];
nextError(error: any): this;
nextResult(result: R): this;
reset(): void;
impl: ((...args: A) => R) | undefined;
next: ResultFn<R> | null;
}
interface SpyImpl<A extends any[] = any[], R = any> extends Spy<A, R> {
getOriginal(): (...args: A) => R;
willCall(cb: (...args: A) => R): this;
restore(): void;
}
interface SpyFn<A extends any[] = any[], R = any> extends Spy<A, R> {
(...args: A): R;
new (...args: A): R;
}
declare function spy<A extends any[], R>(cb?: ((...args: A) => R) | {
new (...args: A): R;
}): SpyFn<A, R>;
declare type Procedure = (...args: any[]) => any;
declare type Methods<T> = {
[K in keyof T]: T[K] extends Procedure ? K : never;
}[keyof T];
declare type Getters<T> = {
[K in keyof T]: T[K] extends Procedure ? never : K;
}[keyof T];
declare type Classes<T> = {
[K in keyof T]: T[K] extends new (...args: any[]) => any ? K : never;
}[keyof T];
declare function spyOn<T, S extends Getters<Required<T>>>(obj: T, methodName: {
setter: S;
}, mock?: (arg: T[S]) => void): SpyImpl<[T[S]], void>;
declare function spyOn<T, G extends Getters<Required<T>>>(obj: T, methodName: {
getter: G;
}, mock?: () => T[G]): SpyImpl<[], T[G]>;
declare function spyOn<T, M extends Classes<Required<T>>>(object: T, method: M): Required<T>[M] extends new (...args: infer A) => infer R ? SpyImpl<A, R> : never;
declare function spyOn<T, M extends Methods<Required<T>>>(obj: T, methodName: M, mock?: T[M]): Required<T>[M] extends (...args: infer A) => infer R ? SpyImpl<A, R> : never;
declare function restoreAll(): void;
export { Spy, SpyFn, SpyImpl, restoreAll, spies, spy, spyOn };

95
node_modules/tinyspy/dist/index.js generated vendored Normal file
View file

@ -0,0 +1,95 @@
// src/utils.ts
function d(t, e) {
if (!t)
throw new Error(e);
}
function y(t, e) {
return typeof e === t;
}
function w(t) {
return t instanceof Promise;
}
function f(t, e, i) {
Object.defineProperty(t, e, i);
}
// src/spy.ts
var g = /* @__PURE__ */ new Set();
function S(t) {
d(y("function", t) || y("undefined", t), "cannot spy on a non-function value");
let e = function(...o) {
if (e.called = !0, e.callCount++, e.calls.push(o), e.next) {
let [s, l] = e.next;
if (e.results.push(e.next), e.next = null, s === "ok")
return l;
throw l;
}
let r, n = "ok";
if (e.impl)
try {
r = e.impl.apply(this, o), n = "ok";
} catch (s) {
throw r = s, n = "error", e.results.push([n, s]), s;
}
let c = [n, r];
if (w(r)) {
let s = r.then((l) => c[1] = l).catch((l) => {
throw c[0] = "error", c[1] = l, l;
});
Object.assign(s, r), r = s;
}
return e.results.push(c), r;
};
f(e, "_isMockFunction", { get: () => !0 }), f(e, "length", { value: t ? t.length : 0 }), f(e, "returns", {
get() {
return this.results.map(([, o]) => o);
}
}), f(e, "name", { value: t && t.name || "spy" });
let i = () => {
e.called = !1, e.callCount = 0, e.results = [], e.calls = [];
};
return i(), e.impl = t, e.reset = i, e.nextError = (o) => (e.next = ["error", o], e), e.nextResult = (o) => (e.next = ["ok", o], e), e;
}
// src/spyOn.ts
var v = (t, e) => Object.getOwnPropertyDescriptor(t, e);
function C(t, e, i) {
d(!y("undefined", t), "spyOn could not find an object to spy upon"), d(y("object", t) || y("function", t), "cannot spyOn on a primitive value");
let o = () => {
if (typeof e != "object")
return [e, "value"];
if ("getter" in e && "setter" in e)
throw new Error("cannot spy on both getter and setter");
if ("getter" in e)
return [e.getter, "get"];
if ("setter" in e)
return [e.setter, "set"];
throw new Error("specify getter or setter to spy on");
}, [r, n] = o(), c = v(t, r), s = Object.getPrototypeOf(t), l = s && v(s, r), a = c || l;
d(a || r in t, `${String(r)} does not exist`);
let T = !1;
n === "value" && a && !a.value && a.get && (n = "get", T = !0, i = a.get());
let u;
a ? u = a[n] : n !== "value" ? u = () => t[r] : u = t[r], i || (i = u);
let p = S(i), A = (m) => {
let { value: O, ...h } = a || {
configurable: !0,
writable: !0
};
n !== "value" && delete h.writable, h[n] = m, f(t, r, h);
}, k = () => A(u);
return p.restore = k, p.getOriginal = () => T ? u() : u, p.willCall = (m) => (p.impl = m, p), A(T ? () => p : p), g.add(p), p;
}
// src/restoreAll.ts
function q() {
for (let t of g)
t.restore();
g.clear();
}
export {
q as restoreAll,
g as spies,
S as spy,
C as spyOn
};

38
node_modules/tinyspy/package.json generated vendored Normal file
View file

@ -0,0 +1,38 @@
{
"name": "tinyspy",
"version": "1.1.1",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"default": "./dist/index.cjs"
},
"files": [
"dist/**"
],
"repository": {
"type": "git",
"url": "git+https://github.com/tinylibs/tinyspy.git"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/tinylibs/tinyspy/issues"
},
"homepage": "https://github.com/tinylibs/tinyspy#readme",
"keywords": [
"spy",
"mock",
"typescript",
"method"
],
"engines": {
"node": ">=14.0.0"
},
"scripts": {
"publish": "npm run build && clean-publish"
}
}