Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tinyspy

Package Overview
Dependencies
Maintainers
3
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tinyspy - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

135

dist/index.js
// src/utils.ts
function d(e, t) {
function S(e, t) {
if (!e)
throw new Error(t);
}
function y(e, t) {
function u(e, t) {
return typeof t === e;

@@ -15,3 +15,3 @@ }

}
function p(e, t, n) {
function l(e, t, n) {
Object.defineProperty(e, t, { value: n });

@@ -21,3 +21,3 @@ }

// src/constants.ts
var u = Symbol.for("tinyspy:spy");
var y = Symbol.for("tinyspy:spy");

@@ -27,39 +27,39 @@ // src/internal.ts

e.called = !1, e.callCount = 0, e.calls = [], e.results = [], e.resolves = [], e.next = [];
}, K = (e) => (f(e, u, { value: { reset: () => P(e[u]) } }), e[u]), I = (e) => e[u] || K(e);
function g(e) {
d(
y("function", e) || y("undefined", e),
}, K = (e) => (f(e, y, { value: { reset: () => P(e[y]) } }), e[y]), T = (e) => e[y] || K(e);
function I(e) {
S(
u("function", e) || u("undefined", e),
"cannot spy on a non-function value"
);
let t = function(...s) {
let r = I(t);
r.called = !0, r.callCount++, r.calls.push(s);
let t = function(...o) {
let r = T(t);
r.called = !0, r.callCount++, r.calls.push(o);
let R = r.next.shift();
if (R) {
r.results.push(R);
let [o, l] = R;
if (o === "ok")
return l;
throw l;
let [s, m] = R;
if (s === "ok")
return m;
throw m;
}
let i, c = "ok", a = r.results.length;
let p, c = "ok", a = r.results.length;
if (r.impl)
try {
new.target ? i = Reflect.construct(r.impl, s, new.target) : i = r.impl.apply(this, s), c = "ok";
} catch (o) {
throw i = o, c = "error", r.results.push([c, o]), o;
new.target ? p = Reflect.construct(r.impl, o, new.target) : p = r.impl.apply(this, o), c = "ok";
} catch (s) {
throw p = s, c = "error", r.results.push([c, s]), s;
}
let S = [c, i];
return w(i) && i.then(
(o) => r.resolves[a] = ["ok", o],
(o) => r.resolves[a] = ["error", o]
), r.results.push(S), i;
let g = [c, p];
return w(p) && p.then(
(s) => r.resolves[a] = ["ok", s],
(s) => r.resolves[a] = ["error", s]
), r.results.push(g), p;
};
p(t, "_isMockFunction", !0), p(t, "length", e ? e.length : 0), p(t, "name", e && e.name || "spy");
let n = I(t);
l(t, "_isMockFunction", !0), l(t, "length", e ? e.length : 0), l(t, "name", e && e.name || "spy");
let n = T(t);
return n.reset(), n.impl = e, t;
}
function T(e) {
let t = I(e);
f(e, "returns", {
function A(e) {
let t = T(e);
"returns" in e || (f(e, "returns", {
get: () => t.results.map(([, n]) => n)

@@ -75,10 +75,10 @@ }), [

].forEach(
(n) => f(e, n, { get: () => t[n], set: (s) => t[n] = s })
), p(e, "nextError", (n) => (t.next.push(["error", n]), t)), p(e, "nextResult", (n) => (t.next.push(["ok", n]), t));
(n) => f(e, n, { get: () => t[n], set: (o) => t[n] = o })
), l(e, "nextError", (n) => (t.next.push(["error", n]), t)), l(e, "nextResult", (n) => (t.next.push(["ok", n]), t)));
}
// src/spy.ts
function L(e) {
let t = g(e);
return T(t), t;
function V(e) {
let t = I(e);
return A(t), t;
}

@@ -91,11 +91,11 @@

function C(e, t, n) {
d(
!y("undefined", e),
S(
!u("undefined", e),
"spyOn could not find an object to spy upon"
), d(
y("object", e) || y("function", e),
), S(
u("object", e) || u("function", e),
"cannot spyOn on a primitive value"
);
let [s, r] = (() => {
if (!y("object", t))
let [o, r] = (() => {
if (!u("object", t))
return [t, "value"];

@@ -109,29 +109,36 @@ if ("getter" in t && "setter" in t)

throw new Error("specify getter or setter to spy on");
})(), R = k(e, s), i = Object.getPrototypeOf(e), c = i && k(i, s), a = R || c;
d(
a || s in e,
`${String(s)} does not exist`
})(), R = k(e, o), p = Object.getPrototypeOf(e), c = p && k(p, o), a = R || c;
S(
a || o in e,
`${String(o)} does not exist`
);
let S = !1;
r === "value" && a && !a.value && a.get && (r = "get", S = !0, n = a.get());
let o;
a ? o = a[r] : r !== "value" ? o = () => e[s] : o = e[s], n || (n = o);
let l = g(n);
r === "value" && O(l, o);
let h = (A) => {
let { value: M, ...v } = a || {
let g = !1;
r === "value" && a && !a.value && a.get && (r = "get", g = !0, n = a.get());
let s;
a ? s = a[r] : r !== "value" ? s = () => e[o] : s = e[o];
let m = (d) => {
let { value: h, ...v } = a || {
configurable: !0,
writable: !0
};
r !== "value" && delete v.writable, v[r] = A, f(e, s, v);
}, b = () => a ? f(e, s, a) : h(o), m = l[u];
return p(m, "restore", b), p(m, "getOriginal", () => S ? o() : o), p(m, "willCall", (A) => (m.impl = A, l)), h(
S ? () => (O(l, n), l) : l
), x.add(l), l;
r !== "value" && delete v.writable, v[r] = d, f(e, o, v);
}, b = () => a ? f(e, o, a) : m(s);
n || (n = s);
let i;
if (s && y in s)
i = s;
else {
i = I(n), r === "value" && O(i, s);
let d = i[y];
l(d, "restore", b), l(d, "getOriginal", () => g ? s() : s), l(d, "willCall", (h) => (d.impl = h, i));
}
return m(
g ? () => (O(i, n), i) : i
), x.add(i), i;
}
function Q(e, t, n) {
let s = C(e, t, n);
return T(s), ["restore", "getOriginal", "willCall"].forEach((r) => {
p(s, r, s[u][r]);
}), s;
let o = C(e, t, n);
return A(o), ["restore", "getOriginal", "willCall"].forEach((r) => {
l(o, r, o[y][r]);
}), o;
}

@@ -146,9 +153,9 @@

export {
g as createInternalSpy,
I as getInternalState,
I as createInternalSpy,
T as getInternalState,
C as internalSpyOn,
X as restoreAll,
x as spies,
L as spy,
V as spy,
Q as spyOn
};
{
"name": "tinyspy",
"version": "3.0.0",
"type": "module",
"version": "3.0.1",
"packageManager": "pnpm@9.1.1",
"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/**"
],
"description": "A minimal fork of nanospy, with more features",
"license": "MIT",
"homepage": "https://github.com/tinylibs/tinyspy#readme",
"repository": {

@@ -22,7 +13,5 @@ "type": "git",

},
"license": "MIT",
"bugs": {
"url": "https://github.com/tinylibs/tinyspy/issues"
},
"homepage": "https://github.com/tinylibs/tinyspy#readme",
"keywords": [

@@ -34,2 +23,20 @@ "spy",

],
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"engines": {

@@ -36,0 +43,0 @@ "node": ">=14.0.0"

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc