Socket
Socket
Sign inDemoInstall

tinyspy

Package Overview
Dependencies
0
Maintainers
3
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.1.0

LICENCE

5

dist/index.d.ts

@@ -25,4 +25,7 @@ declare let spies: Set<SpyImpl<any[], any>>;

(...args: A): R;
new (...args: A): R;
}
declare function spy<A extends any[], R>(cb?: (...args: A) => R): SpyFn<A, R>;
declare function spy<A extends any[], R>(cb?: ((...args: A) => R) | {
new (...args: A): R;
}): SpyFn<A, R>;

@@ -29,0 +32,0 @@ declare type Procedure = (...args: any[]) => any;

62

dist/index.js

@@ -9,3 +9,3 @@ // src/utils.ts

}
function v(t) {
function A(t) {
return t instanceof Promise;

@@ -18,25 +18,25 @@ }

// src/spy.ts
var x = /* @__PURE__ */ new Set();
function A(t) {
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")
let e = function(...n) {
if (e.called = !0, e.callCount++, e.calls.push(n), e.next) {
let [o, l] = e.next;
if (e.results.push(e.next), e.next = null, o === "ok")
return l;
throw l;
}
let r, n = "ok";
let r, s = "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;
r = new.target ? new e.impl(...n) : e.impl.apply(this, n), s = "ok";
} catch (o) {
throw r = o, s = "error", e.results.push([s, o]), o;
}
let c = [n, r];
if (v(r)) {
let s = r.then((l) => c[1] = l).catch((l) => {
let c = [s, r];
if (A(r)) {
let o = r.then((l) => c[1] = l).catch((l) => {
throw c[0] = "error", c[1] = l, l;
});
Object.assign(s, r), r = s;
Object.assign(o, r), r = o;
}

@@ -47,3 +47,3 @@ return e.results.push(c), r;

get() {
return this.results.map(([, o]) => o);
return this.results.map(([, n]) => n);
}

@@ -54,10 +54,10 @@ }), f(e, "name", { value: t && t.name || "spy" });

};
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;
return i(), e.impl = t, e.reset = i, e.nextError = (n) => (e.next = ["error", n], e), e.nextResult = (n) => (e.next = ["ok", n], e), e;
}
// src/spyOn.ts
var k = (t, e) => Object.getOwnPropertyDescriptor(t, e);
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 = () => {
let n = () => {
if (typeof e != "object")

@@ -72,16 +72,16 @@ return [e, "value"];

throw new Error("specify getter or setter to spy on");
}, [r, n] = o(), c = k(t, r), s = Object.getPrototypeOf(t), l = s && k(s, r), a = c || l;
}, [r, s] = n(), c = v(t, r), o = Object.getPrototypeOf(t), l = o && v(o, 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());
s === "value" && a && !a.value && a.get && (s = "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 = A(i), S = (m) => {
let { value: O, ...h } = a || {
a ? u = a[s] : s !== "value" ? u = () => t[r] : u = t[r], i || (i = u);
let p = S(i), h = (m) => {
let { value: O, ...w } = a || {
configurable: !0,
writable: !0
};
n !== "value" && delete h.writable, h[n] = m, f(t, r, h);
}, w = () => S(u);
return p.restore = w, p.getOriginal = () => T ? u() : u, p.willCall = (m) => (p.impl = m, p), S(T ? () => p : p), x.add(p), p;
s !== "value" && delete w.writable, w[s] = m, f(t, r, w);
}, k = () => h(u);
return p.restore = k, p.getOriginal = () => T ? u() : u, p.willCall = (m) => (p.impl = m, p), h(T ? () => p : p), g.add(p), p;
}

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

function q() {
for (let t of x)
for (let t of g)
t.restore();
x.clear();
g.clear();
}
export {
q as restoreAll,
x as spies,
A as spy,
g as spies,
S as spy,
C as spyOn
};
{
"name": "tinyspy",
"version": "1.0.2",
"version": "1.1.0",
"type": "module",

@@ -5,0 +5,0 @@ "main": "./dist/index.cjs",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc