aws-sdk-vitest-mock 1.0.0 → 1.0.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/index.cjs +6 -6
- package/index.js +191 -178
- package/package.json +3 -2
package/index.cjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
${
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("vitest"),D=require("./matchers-CNhdB_9q.cjs"),W=require("node:fs"),C=require("node:path"),A=require("node:stream");class d extends Error{constructor(r,o,c,n){super(r),this.name=o,this.code=o,this.statusCode=c,this.retryable=n}}const T=e=>new d(e?`The specified key does not exist. Key: ${e}`:"The specified key does not exist.","NoSuchKey",404,!1),I=e=>new d(e?`The specified bucket does not exist. Bucket: ${e}`:"The specified bucket does not exist.","NoSuchBucket",404,!1),M=e=>new d(e?`Access Denied for resource: ${e}`:"Access Denied","AccessDenied",403,!1),K=e=>new d(e?`Requested resource not found: ${e}`:"Requested resource not found","ResourceNotFoundException",400,!1),B=()=>new d("The conditional request failed","ConditionalCheckFailedException",400,!1),J=()=>new d("Rate exceeded","Throttling",400,!0),q=()=>new d("We encountered an internal error. Please try again.","InternalServerError",500,!0),_=e=>{try{return JSON.stringify(e,void 0,2)}catch{return typeof e=="object"&&e!==null?"[Complex Object]":typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):"[Non-serializable value]"}},j=(e,r)=>{const o=D.colors.magenta("aws-sdk-vitest-mock(debug):");if(r===void 0)console.log(`${o} ${e}`);else{const c=_(r);console.log(`${o} ${e}
|
|
2
|
+
${c}`)}},E=(e=!1)=>({enabled:e,explicitlySet:!1,log(r,o){this.enabled&&j(r,o)},logDirect(r,o){j(r,o)}}),z=e=>{e.enabled=!0,e.explicitlySet=!0},V=e=>{e.enabled=!1,e.explicitlySet=!0},G=e=>{const r=C.resolve(e);try{const o=W.readFileSync(r,"utf8");if(e.endsWith(".json"))try{return JSON.parse(o)}catch(c){const n=c instanceof Error?c.message:String(c);throw new Error(`Failed to parse JSON fixture at ${r}: ${n}`)}return o}catch(o){const c=o instanceof Error?o.message:String(o);throw new Error(`Failed to load fixture at ${r}: ${c}`)}},U=(e,r={})=>{const{pageSize:o=10,tokenKey:c="NextToken",itemsKey:n="Items"}=r;if(e.length===0)return[{[n]:[]}];const s=[];for(let t=0;t<e.length;t+=o){const i=e.slice(t,t+o),l=t+o<e.length,u={[n]:i};if(l){const a=u,f=i[i.length-1];a[c]=f}s.push(u)}return s},H=()=>typeof process<"u"&&process.versions?.node?"node":typeof process<"u"&&process.versions?.bun?"bun":"browser",Q=e=>{const r=typeof e=="string"?Buffer.from(e,"utf8"):Buffer.from(e);let o=!1;return new A.Readable({read(){o||(this.push(r),this.push(null),o=!0)}})},X=e=>{let r;return typeof e=="string"?r=new TextEncoder().encode(e):e instanceof Buffer?r=new Uint8Array(e):r=e,new ReadableStream({start(o){o.enqueue(r),o.close()}})},$=e=>{const r=H();return r==="node"||r==="bun"?Q(e):X(e)};let N=!1;function Y(e){N=e}function p(e){return e.explicitlySet?e.enabled:N}function m(e,r){return Object.keys(r).every(o=>{const c=r[o],n=e[o];return Array.isArray(c)?!Array.isArray(n)||c.length>n.length?!1:c.every((s,t)=>{const i=n[t];return s&&typeof s=="object"&&typeof i=="object"&&i!==null?m(i,s):i===s}):c&&typeof c=="object"&&!Array.isArray(c)?typeof n!="object"||n===null?!1:m(n,c):n===c})}function v(e,r){if(e===r)return!0;if(typeof e!="object"||e===null||typeof r!="object"||r===null)return e===r;if(Array.isArray(e)&&Array.isArray(r))return e.length!==r.length?!1:e.every((n,s)=>{const t=r[s];return typeof n=="object"&&n!==null&&typeof t=="object"&&t!==null?v(n,t):n===t});if(Array.isArray(e)!==Array.isArray(r))return!1;const o=Object.keys(e),c=Object.keys(r);return o.length!==c.length?!1:c.every(n=>{if(!Object.prototype.hasOwnProperty.call(e,n))return!1;const s=e,t=r,i=s[n],l=t[n];return typeof i=="object"&&i!==null&&typeof l=="object"&&l!==null?v(i,l):i===l})}function Z(e,r,o){const c=r.map((s,t)=>{const i=s.matcher?JSON.stringify(s.matcher,void 0,2):"any input",l=s.strict?" (strict mode)":"";return` Mock #${t+1}: ${i}${l}`}).join(`
|
|
3
3
|
`),n=JSON.stringify(o,void 0,2);return new Error(`No matching mock found for ${e}.
|
|
4
4
|
|
|
5
|
-
Found ${
|
|
5
|
+
Found ${r.length} mock(s) but none matched the input.
|
|
6
6
|
|
|
7
7
|
Configured mocks:
|
|
8
|
-
${
|
|
8
|
+
${c}
|
|
9
9
|
|
|
10
10
|
Received input:
|
|
11
11
|
${n}
|
|
12
12
|
|
|
13
|
-
Tip: Enable debug mode with enableDebug() for detailed matching information.`)}function ee(e,
|
|
13
|
+
Tip: Enable debug mode with enableDebug() for detailed matching information.`)}function ee(e,r){const o=JSON.stringify(r,void 0,2);return new Error(`No mock configured for command: ${e}.
|
|
14
14
|
|
|
15
15
|
Received input:
|
|
16
16
|
${o}
|
|
17
17
|
|
|
18
|
-
Did you forget to call mockClient.on(${e})?`)}function
|
|
18
|
+
Did you forget to call mockClient.on(${e})?`)}function re(e,r){return e.findIndex(o=>o.strict?o.matcher&&v(r,o.matcher):!o.matcher||m(r,o.matcher))}function x(e){return async function(r){const o=()=>this,c=p(e.debugLogger),n=r.constructor.name;c&&e.debugLogger.logDirect(`Received command: ${n}`,r.input);const s=e.map.get(r.constructor);if(!s)throw c&&e.debugLogger.logDirect(`No mocks configured for ${n}`),ee(n,r.input);c&&e.debugLogger.logDirect(`Found ${s.length} mock(s) for ${n}`);const t=re(s,r.input);if(t===-1)throw c&&e.debugLogger.logDirect(`No matching mock found for ${n}`,r.input),Z(n,s,r.input);const i=s[t];if(!i)throw new Error(`Mock at index ${t} not found`);return c&&e.debugLogger.logDirect(`Using mock at index ${t} for ${n}`),i.once&&(s.splice(t,1),c&&e.debugLogger.logDirect(`Removed one-time mock for ${n}`)),i.handler(r.input,o())}}const L=(e,r,o)=>({reset(){p(e.debugLogger)&&e.debugLogger.logDirect(o.reset),r.mockClear()},restore(){p(e.debugLogger)&&e.debugLogger.logDirect(o.restore),r.mockRestore(),e.map=new WeakMap},calls(){return r.mock.calls.map(c=>c[0])},__rawCalls(){return r.mock.calls},enableDebug(){z(e.debugLogger)},disableDebug(){V(e.debugLogger)}});function R(e,r,o,c={}){const n=(t,i,l)=>{const u={matcher:o,handler:t,once:i,strict:!!c.strict},a=e.map.get(r)??[],f=p(e.debugLogger);if(i){const g=a.findIndex(h=>!h.once);g===-1?a.push(u):a.splice(g,0,u),e.map.set(r,a),f&&e.debugLogger.logDirect(`Configured ${l}Once for ${r.name}`,o?{matcher:o,strict:!!c.strict}:void 0)}else{const g=a.filter(h=>h.once||JSON.stringify(h.matcher)!==JSON.stringify(o));g.push(u),e.map.set(r,g),f&&e.debugLogger.logDirect(`Configured ${l} for ${r.name}`,o?{matcher:o,strict:!!c.strict}:void 0)}},s={resolves(t){return n(()=>Promise.resolve(t),!1,"resolves"),s},rejects(t){return n(()=>{const i=typeof t=="string"?new Error(t):t;return Promise.reject(i)},!1,"rejects"),s},callsFake(t){return n(t,!1,"callsFake"),s},resolvesOnce(t){return n(()=>Promise.resolve(t),!0,"resolves"),s},rejectsOnce(t){return n(()=>{const i=typeof t=="string"?new Error(t):t;return Promise.reject(i)},!0,"rejects"),s},callsFakeOnce(t){return n(t,!0,"callsFake"),s},resolvesStream(t){return n(()=>Promise.resolve({Body:$(t)}),!1,"resolvesStream"),s},resolvesStreamOnce(t){return n(()=>Promise.resolve({Body:$(t)}),!0,"resolvesStream"),s},resolvesWithDelay(t,i){const l=u=>{setTimeout(()=>u(t),i)};return n(()=>new Promise(l),!1,"resolvesWithDelay"),s},rejectsWithDelay(t,i){const l=typeof t=="string"?new Error(t):t,u=(a,f)=>{setTimeout(()=>f(l),i)};return n(()=>new Promise(u),!1,"rejectsWithDelay"),s},rejectsWithNoSuchKey(t){return n(()=>Promise.reject(T(t)),!1,"rejectsWithNoSuchKey"),s},rejectsWithNoSuchBucket(t){return n(()=>Promise.reject(I(t)),!1,"rejectsWithNoSuchBucket"),s},rejectsWithAccessDenied(t){return n(()=>Promise.reject(M(t)),!1,"rejectsWithAccessDenied"),s},rejectsWithResourceNotFound(t){return n(()=>Promise.reject(K(t)),!1,"rejectsWithResourceNotFound"),s},rejectsWithConditionalCheckFailed(){return n(()=>Promise.reject(B()),!1,"rejectsWithConditionalCheckFailed"),s},rejectsWithThrottling(){return n(()=>Promise.reject(J()),!1,"rejectsWithThrottling"),s},rejectsWithInternalServerError(){return n(()=>Promise.reject(q()),!1,"rejectsWithInternalServerError"),s},resolvesPaginated(t,i={}){const l=U(t,i);let u=0;return e.debugLogger.log(`Configured resolvesPaginated for ${r.name}`,{pageSize:i.pageSize,itemsCount:t.length}),n(a=>{const f=i.tokenKey||"NextToken",g=i.inputTokenKey||f,b=a[g];if(b!=null){const F=i.itemsKey||"Items";let S=0;for(const O of l){const y=O[F];if(y&&y.length>0){const P=y[y.length-1];if(JSON.stringify(P)===JSON.stringify(b)){u=S+1;break}}S++}}else u=0;const k=l[u]||l[l.length-1]||l[0];if(!k)throw new Error("No paginated responses available");return u=Math.min(u+1,l.length-1),Promise.resolve(k)},!1,"resolvesPaginated"),s},resolvesFromFile(t){return e.debugLogger.log(`Configured resolvesFromFile for ${r.name}`,{filePath:t}),n(()=>{const i=G(t);return Promise.resolve(i)},!1,"resolvesFromFile"),s}};return s}const te=e=>{const r={map:new WeakMap,debugLogger:E()},o=e.prototype,c=w.vi.spyOn(o,"send").mockImplementation(x(r)),n=L(r,c,{reset:"Clearing call history (mocks preserved)",restore:"Restoring original client behavior and clearing all mocks"});return{client:void 0,on:(t,i,l)=>R(r,t,i,l),...n}},oe=e=>{const r={map:new WeakMap,debugLogger:E()},o=w.vi.spyOn(e,"send").mockImplementation(x(r)),c=L(r,o,{reset:"Clearing call history (mocks preserved) for client instance",restore:"Restoring original client behavior and clearing all mocks for client instance"});return{client:e,on:(s,t,i)=>R(r,s,t,i),...c}};exports.matchers=D.matchers;exports.mockClient=te;exports.mockClientInstance=oe;exports.setGlobalDebug=Y;
|
package/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { vi as
|
|
1
|
+
import { vi as w } from "vitest";
|
|
2
2
|
import { c as O } from "./matchers-DmTtFk31.js";
|
|
3
3
|
import { m as ge } from "./matchers-DmTtFk31.js";
|
|
4
4
|
import { readFileSync as P } from "node:fs";
|
|
5
|
-
import
|
|
6
|
-
import { Readable as
|
|
5
|
+
import A from "node:path";
|
|
6
|
+
import { Readable as C } from "node:stream";
|
|
7
7
|
class d extends Error {
|
|
8
|
-
constructor(
|
|
9
|
-
super(
|
|
8
|
+
constructor(r, o, c, n) {
|
|
9
|
+
super(r), this.name = o, this.code = o, this.statusCode = c, this.retryable = n;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
const T = (e) => new d(
|
|
@@ -14,17 +14,17 @@ const T = (e) => new d(
|
|
|
14
14
|
"NoSuchKey",
|
|
15
15
|
404,
|
|
16
16
|
!1
|
|
17
|
-
),
|
|
17
|
+
), I = (e) => new d(
|
|
18
18
|
e ? `The specified bucket does not exist. Bucket: ${e}` : "The specified bucket does not exist.",
|
|
19
19
|
"NoSuchBucket",
|
|
20
20
|
404,
|
|
21
21
|
!1
|
|
22
|
-
),
|
|
22
|
+
), M = (e) => new d(
|
|
23
23
|
e ? `Access Denied for resource: ${e}` : "Access Denied",
|
|
24
24
|
"AccessDenied",
|
|
25
25
|
403,
|
|
26
26
|
!1
|
|
27
|
-
),
|
|
27
|
+
), K = (e) => new d(
|
|
28
28
|
e ? `Requested resource not found: ${e}` : "Requested resource not found",
|
|
29
29
|
"ResourceNotFoundException",
|
|
30
30
|
400,
|
|
@@ -45,119 +45,132 @@ const T = (e) => new d(
|
|
|
45
45
|
} catch {
|
|
46
46
|
return typeof e == "object" && e !== null ? "[Complex Object]" : typeof e == "string" ? e : typeof e == "number" || typeof e == "boolean" ? String(e) : "[Non-serializable value]";
|
|
47
47
|
}
|
|
48
|
-
},
|
|
48
|
+
}, S = (e, r) => {
|
|
49
49
|
const o = O.magenta("aws-sdk-vitest-mock(debug):");
|
|
50
|
-
if (
|
|
50
|
+
if (r === void 0)
|
|
51
51
|
console.log(`${o} ${e}`);
|
|
52
52
|
else {
|
|
53
|
-
const
|
|
53
|
+
const c = z(r);
|
|
54
54
|
console.log(`${o} ${e}
|
|
55
|
-
${
|
|
55
|
+
${c}`);
|
|
56
56
|
}
|
|
57
|
-
},
|
|
57
|
+
}, E = (e = !1) => ({
|
|
58
58
|
enabled: e,
|
|
59
59
|
explicitlySet: !1,
|
|
60
|
-
log(
|
|
61
|
-
this.enabled &&
|
|
60
|
+
log(r, o) {
|
|
61
|
+
this.enabled && S(r, o);
|
|
62
62
|
},
|
|
63
|
-
logDirect(
|
|
64
|
-
|
|
63
|
+
logDirect(r, o) {
|
|
64
|
+
S(r, o);
|
|
65
65
|
}
|
|
66
66
|
}), V = (e) => {
|
|
67
67
|
e.enabled = !0, e.explicitlySet = !0;
|
|
68
68
|
}, _ = (e) => {
|
|
69
69
|
e.enabled = !1, e.explicitlySet = !0;
|
|
70
70
|
}, U = (e) => {
|
|
71
|
-
const
|
|
71
|
+
const r = A.resolve(e);
|
|
72
72
|
try {
|
|
73
|
-
const o = P(
|
|
73
|
+
const o = P(r, "utf8");
|
|
74
74
|
if (e.endsWith(".json"))
|
|
75
75
|
try {
|
|
76
76
|
return JSON.parse(o);
|
|
77
|
-
} catch (
|
|
78
|
-
const n =
|
|
77
|
+
} catch (c) {
|
|
78
|
+
const n = c instanceof Error ? c.message : String(c);
|
|
79
79
|
throw new Error(
|
|
80
|
-
`Failed to parse JSON fixture at ${
|
|
80
|
+
`Failed to parse JSON fixture at ${r}: ${n}`
|
|
81
81
|
);
|
|
82
82
|
}
|
|
83
83
|
return o;
|
|
84
84
|
} catch (o) {
|
|
85
|
-
const
|
|
86
|
-
throw new Error(`Failed to load fixture at ${
|
|
85
|
+
const c = o instanceof Error ? o.message : String(o);
|
|
86
|
+
throw new Error(`Failed to load fixture at ${r}: ${c}`);
|
|
87
87
|
}
|
|
88
|
-
}, G = (e,
|
|
89
|
-
const { pageSize: o = 10, tokenKey:
|
|
88
|
+
}, G = (e, r = {}) => {
|
|
89
|
+
const { pageSize: o = 10, tokenKey: c = "NextToken", itemsKey: n = "Items" } = r;
|
|
90
90
|
if (e.length === 0)
|
|
91
91
|
return [{ [n]: [] }];
|
|
92
|
-
const
|
|
93
|
-
for (let
|
|
94
|
-
const i = e.slice(
|
|
92
|
+
const s = [];
|
|
93
|
+
for (let t = 0; t < e.length; t += o) {
|
|
94
|
+
const i = e.slice(t, t + o), l = t + o < e.length, u = { [n]: i };
|
|
95
95
|
if (l) {
|
|
96
96
|
const a = u, f = i[i.length - 1];
|
|
97
|
-
a[
|
|
97
|
+
a[c] = f;
|
|
98
98
|
}
|
|
99
|
-
|
|
99
|
+
s.push(u);
|
|
100
100
|
}
|
|
101
|
-
return
|
|
101
|
+
return s;
|
|
102
102
|
}, H = () => typeof process < "u" && process.versions?.node ? "node" : typeof process < "u" && process.versions?.bun ? "bun" : "browser", Q = (e) => {
|
|
103
|
-
const
|
|
103
|
+
const r = typeof e == "string" ? Buffer.from(e, "utf8") : Buffer.from(e);
|
|
104
104
|
let o = !1;
|
|
105
|
-
return new
|
|
105
|
+
return new C({
|
|
106
106
|
read() {
|
|
107
|
-
o || (this.push(
|
|
107
|
+
o || (this.push(r), this.push(null), o = !0);
|
|
108
108
|
}
|
|
109
109
|
});
|
|
110
110
|
}, X = (e) => {
|
|
111
|
-
let
|
|
112
|
-
return typeof e == "string" ?
|
|
111
|
+
let r;
|
|
112
|
+
return typeof e == "string" ? r = new TextEncoder().encode(e) : e instanceof Buffer ? r = new Uint8Array(e) : r = e, new ReadableStream({
|
|
113
113
|
start(o) {
|
|
114
|
-
o.enqueue(
|
|
114
|
+
o.enqueue(r), o.close();
|
|
115
115
|
}
|
|
116
116
|
});
|
|
117
|
-
},
|
|
118
|
-
const
|
|
119
|
-
return
|
|
117
|
+
}, $ = (e) => {
|
|
118
|
+
const r = H();
|
|
119
|
+
return r === "node" || r === "bun" ? Q(e) : X(e);
|
|
120
120
|
};
|
|
121
|
-
let
|
|
121
|
+
let N = !1;
|
|
122
122
|
function ie(e) {
|
|
123
|
-
|
|
123
|
+
N = e;
|
|
124
124
|
}
|
|
125
|
-
function
|
|
126
|
-
return e.explicitlySet ? e.enabled :
|
|
125
|
+
function y(e) {
|
|
126
|
+
return e.explicitlySet ? e.enabled : N;
|
|
127
127
|
}
|
|
128
|
-
function
|
|
129
|
-
return Object.keys(
|
|
130
|
-
const
|
|
131
|
-
return
|
|
128
|
+
function m(e, r) {
|
|
129
|
+
return Object.keys(r).every((o) => {
|
|
130
|
+
const c = r[o], n = e[o];
|
|
131
|
+
return Array.isArray(c) ? !Array.isArray(n) || c.length > n.length ? !1 : c.every((s, t) => {
|
|
132
|
+
const i = n[t];
|
|
133
|
+
return s && typeof s == "object" && typeof i == "object" && i !== null ? m(
|
|
134
|
+
i,
|
|
135
|
+
s
|
|
136
|
+
) : i === s;
|
|
137
|
+
}) : c && typeof c == "object" && !Array.isArray(c) ? typeof n != "object" || n === null ? !1 : m(
|
|
132
138
|
n,
|
|
133
|
-
|
|
134
|
-
) : n ===
|
|
139
|
+
c
|
|
140
|
+
) : n === c;
|
|
135
141
|
});
|
|
136
142
|
}
|
|
137
|
-
function
|
|
138
|
-
if (e ===
|
|
139
|
-
if (typeof e != "object" || e === null || typeof
|
|
140
|
-
return e ===
|
|
141
|
-
|
|
142
|
-
|
|
143
|
+
function v(e, r) {
|
|
144
|
+
if (e === r) return !0;
|
|
145
|
+
if (typeof e != "object" || e === null || typeof r != "object" || r === null)
|
|
146
|
+
return e === r;
|
|
147
|
+
if (Array.isArray(e) && Array.isArray(r))
|
|
148
|
+
return e.length !== r.length ? !1 : e.every((n, s) => {
|
|
149
|
+
const t = r[s];
|
|
150
|
+
return typeof n == "object" && n !== null && typeof t == "object" && t !== null ? v(n, t) : n === t;
|
|
151
|
+
});
|
|
152
|
+
if (Array.isArray(e) !== Array.isArray(r))
|
|
153
|
+
return !1;
|
|
154
|
+
const o = Object.keys(e), c = Object.keys(r);
|
|
155
|
+
return o.length !== c.length ? !1 : c.every((n) => {
|
|
143
156
|
if (!Object.prototype.hasOwnProperty.call(e, n)) return !1;
|
|
144
|
-
const
|
|
145
|
-
return typeof i == "object" && i !== null && typeof l == "object" && l !== null ?
|
|
157
|
+
const s = e, t = r, i = s[n], l = t[n];
|
|
158
|
+
return typeof i == "object" && i !== null && typeof l == "object" && l !== null ? v(i, l) : i === l;
|
|
146
159
|
});
|
|
147
160
|
}
|
|
148
|
-
function Y(e,
|
|
149
|
-
const
|
|
150
|
-
const i =
|
|
151
|
-
return ` Mock #${
|
|
161
|
+
function Y(e, r, o) {
|
|
162
|
+
const c = r.map((s, t) => {
|
|
163
|
+
const i = s.matcher ? JSON.stringify(s.matcher, void 0, 2) : "any input", l = s.strict ? " (strict mode)" : "";
|
|
164
|
+
return ` Mock #${t + 1}: ${i}${l}`;
|
|
152
165
|
}).join(`
|
|
153
166
|
`), n = JSON.stringify(o, void 0, 2);
|
|
154
167
|
return new Error(
|
|
155
168
|
`No matching mock found for ${e}.
|
|
156
169
|
|
|
157
|
-
Found ${
|
|
170
|
+
Found ${r.length} mock(s) but none matched the input.
|
|
158
171
|
|
|
159
172
|
Configured mocks:
|
|
160
|
-
${
|
|
173
|
+
${c}
|
|
161
174
|
|
|
162
175
|
Received input:
|
|
163
176
|
${n}
|
|
@@ -165,8 +178,8 @@ ${n}
|
|
|
165
178
|
Tip: Enable debug mode with enableDebug() for detailed matching information.`
|
|
166
179
|
);
|
|
167
180
|
}
|
|
168
|
-
function Z(e,
|
|
169
|
-
const o = JSON.stringify(
|
|
181
|
+
function Z(e, r) {
|
|
182
|
+
const o = JSON.stringify(r, void 0, 2);
|
|
170
183
|
return new Error(
|
|
171
184
|
`No mock configured for command: ${e}.
|
|
172
185
|
|
|
@@ -176,54 +189,54 @@ ${o}
|
|
|
176
189
|
Did you forget to call mockClient.on(${e})?`
|
|
177
190
|
);
|
|
178
191
|
}
|
|
179
|
-
function ee(e,
|
|
180
|
-
return e.findIndex((o) => o.strict ? o.matcher &&
|
|
192
|
+
function ee(e, r) {
|
|
193
|
+
return e.findIndex((o) => o.strict ? o.matcher && v(r, o.matcher) : !o.matcher || m(r, o.matcher));
|
|
181
194
|
}
|
|
182
195
|
function x(e) {
|
|
183
|
-
return async function(
|
|
184
|
-
const o = () => this,
|
|
185
|
-
|
|
196
|
+
return async function(r) {
|
|
197
|
+
const o = () => this, c = y(e.debugLogger), n = r.constructor.name;
|
|
198
|
+
c && e.debugLogger.logDirect(
|
|
186
199
|
`Received command: ${n}`,
|
|
187
|
-
|
|
200
|
+
r.input
|
|
188
201
|
);
|
|
189
|
-
const
|
|
190
|
-
|
|
202
|
+
const s = e.map.get(
|
|
203
|
+
r.constructor
|
|
191
204
|
);
|
|
192
|
-
if (!
|
|
193
|
-
throw
|
|
205
|
+
if (!s)
|
|
206
|
+
throw c && e.debugLogger.logDirect(
|
|
194
207
|
`No mocks configured for ${n}`
|
|
195
|
-
), Z(n,
|
|
196
|
-
|
|
197
|
-
`Found ${
|
|
208
|
+
), Z(n, r.input);
|
|
209
|
+
c && e.debugLogger.logDirect(
|
|
210
|
+
`Found ${s.length} mock(s) for ${n}`
|
|
198
211
|
);
|
|
199
|
-
const
|
|
200
|
-
if (
|
|
201
|
-
throw
|
|
212
|
+
const t = ee(s, r.input);
|
|
213
|
+
if (t === -1)
|
|
214
|
+
throw c && e.debugLogger.logDirect(
|
|
202
215
|
`No matching mock found for ${n}`,
|
|
203
|
-
|
|
204
|
-
), Y(n,
|
|
205
|
-
const i =
|
|
216
|
+
r.input
|
|
217
|
+
), Y(n, s, r.input);
|
|
218
|
+
const i = s[t];
|
|
206
219
|
if (!i)
|
|
207
|
-
throw new Error(`Mock at index ${
|
|
208
|
-
return
|
|
209
|
-
`Using mock at index ${
|
|
210
|
-
), i.once && (
|
|
220
|
+
throw new Error(`Mock at index ${t} not found`);
|
|
221
|
+
return c && e.debugLogger.logDirect(
|
|
222
|
+
`Using mock at index ${t} for ${n}`
|
|
223
|
+
), i.once && (s.splice(t, 1), c && e.debugLogger.logDirect(
|
|
211
224
|
`Removed one-time mock for ${n}`
|
|
212
|
-
)), i.handler(
|
|
225
|
+
)), i.handler(r.input, o());
|
|
213
226
|
};
|
|
214
227
|
}
|
|
215
|
-
const D = (e,
|
|
228
|
+
const D = (e, r, o) => ({
|
|
216
229
|
reset() {
|
|
217
|
-
|
|
230
|
+
y(e.debugLogger) && e.debugLogger.logDirect(o.reset), r.mockClear();
|
|
218
231
|
},
|
|
219
232
|
restore() {
|
|
220
|
-
|
|
233
|
+
y(e.debugLogger) && e.debugLogger.logDirect(o.restore), r.mockRestore(), e.map = /* @__PURE__ */ new WeakMap();
|
|
221
234
|
},
|
|
222
235
|
calls() {
|
|
223
|
-
return
|
|
236
|
+
return r.mock.calls.map((c) => c[0]);
|
|
224
237
|
},
|
|
225
238
|
__rawCalls() {
|
|
226
|
-
return
|
|
239
|
+
return r.mock.calls;
|
|
227
240
|
},
|
|
228
241
|
enableDebug() {
|
|
229
242
|
V(e.debugLogger);
|
|
@@ -232,240 +245,240 @@ const D = (e, t, o) => ({
|
|
|
232
245
|
_(e.debugLogger);
|
|
233
246
|
}
|
|
234
247
|
});
|
|
235
|
-
function L(e,
|
|
236
|
-
const n = (
|
|
248
|
+
function L(e, r, o, c = {}) {
|
|
249
|
+
const n = (t, i, l) => {
|
|
237
250
|
const u = {
|
|
238
251
|
matcher: o,
|
|
239
|
-
handler:
|
|
252
|
+
handler: t,
|
|
240
253
|
once: i,
|
|
241
|
-
strict: !!
|
|
242
|
-
}, a = e.map.get(
|
|
254
|
+
strict: !!c.strict
|
|
255
|
+
}, a = e.map.get(r) ?? [], f = y(e.debugLogger);
|
|
243
256
|
if (i) {
|
|
244
257
|
const g = a.findIndex((h) => !h.once);
|
|
245
258
|
g === -1 ? a.push(u) : a.splice(g, 0, u), e.map.set(
|
|
246
|
-
|
|
259
|
+
r,
|
|
247
260
|
a
|
|
248
261
|
), f && e.debugLogger.logDirect(
|
|
249
|
-
`Configured ${l}Once for ${
|
|
250
|
-
o ? { matcher: o, strict: !!
|
|
262
|
+
`Configured ${l}Once for ${r.name}`,
|
|
263
|
+
o ? { matcher: o, strict: !!c.strict } : void 0
|
|
251
264
|
);
|
|
252
265
|
} else {
|
|
253
266
|
const g = a.filter(
|
|
254
267
|
(h) => h.once || JSON.stringify(h.matcher) !== JSON.stringify(o)
|
|
255
268
|
);
|
|
256
269
|
g.push(u), e.map.set(
|
|
257
|
-
|
|
270
|
+
r,
|
|
258
271
|
g
|
|
259
272
|
), f && e.debugLogger.logDirect(
|
|
260
|
-
`Configured ${l} for ${
|
|
261
|
-
o ? { matcher: o, strict: !!
|
|
273
|
+
`Configured ${l} for ${r.name}`,
|
|
274
|
+
o ? { matcher: o, strict: !!c.strict } : void 0
|
|
262
275
|
);
|
|
263
276
|
}
|
|
264
|
-
},
|
|
265
|
-
resolves(
|
|
266
|
-
return n(() => Promise.resolve(
|
|
277
|
+
}, s = {
|
|
278
|
+
resolves(t) {
|
|
279
|
+
return n(() => Promise.resolve(t), !1, "resolves"), s;
|
|
267
280
|
},
|
|
268
|
-
rejects(
|
|
281
|
+
rejects(t) {
|
|
269
282
|
return n(
|
|
270
283
|
() => {
|
|
271
|
-
const i = typeof
|
|
284
|
+
const i = typeof t == "string" ? new Error(t) : t;
|
|
272
285
|
return Promise.reject(i);
|
|
273
286
|
},
|
|
274
287
|
!1,
|
|
275
288
|
"rejects"
|
|
276
|
-
),
|
|
289
|
+
), s;
|
|
277
290
|
},
|
|
278
|
-
callsFake(
|
|
279
|
-
return n(
|
|
291
|
+
callsFake(t) {
|
|
292
|
+
return n(t, !1, "callsFake"), s;
|
|
280
293
|
},
|
|
281
|
-
resolvesOnce(
|
|
282
|
-
return n(() => Promise.resolve(
|
|
294
|
+
resolvesOnce(t) {
|
|
295
|
+
return n(() => Promise.resolve(t), !0, "resolves"), s;
|
|
283
296
|
},
|
|
284
|
-
rejectsOnce(
|
|
297
|
+
rejectsOnce(t) {
|
|
285
298
|
return n(
|
|
286
299
|
() => {
|
|
287
|
-
const i = typeof
|
|
300
|
+
const i = typeof t == "string" ? new Error(t) : t;
|
|
288
301
|
return Promise.reject(i);
|
|
289
302
|
},
|
|
290
303
|
!0,
|
|
291
304
|
"rejects"
|
|
292
|
-
),
|
|
305
|
+
), s;
|
|
293
306
|
},
|
|
294
|
-
callsFakeOnce(
|
|
295
|
-
return n(
|
|
307
|
+
callsFakeOnce(t) {
|
|
308
|
+
return n(t, !0, "callsFake"), s;
|
|
296
309
|
},
|
|
297
|
-
resolvesStream(
|
|
310
|
+
resolvesStream(t) {
|
|
298
311
|
return n(
|
|
299
312
|
() => Promise.resolve({
|
|
300
|
-
Body:
|
|
313
|
+
Body: $(t)
|
|
301
314
|
}),
|
|
302
315
|
!1,
|
|
303
316
|
"resolvesStream"
|
|
304
|
-
),
|
|
317
|
+
), s;
|
|
305
318
|
},
|
|
306
|
-
resolvesStreamOnce(
|
|
319
|
+
resolvesStreamOnce(t) {
|
|
307
320
|
return n(
|
|
308
321
|
() => Promise.resolve({
|
|
309
|
-
Body:
|
|
322
|
+
Body: $(t)
|
|
310
323
|
}),
|
|
311
324
|
!0,
|
|
312
325
|
"resolvesStream"
|
|
313
|
-
),
|
|
326
|
+
), s;
|
|
314
327
|
},
|
|
315
|
-
resolvesWithDelay(
|
|
328
|
+
resolvesWithDelay(t, i) {
|
|
316
329
|
const l = (u) => {
|
|
317
|
-
setTimeout(() => u(
|
|
330
|
+
setTimeout(() => u(t), i);
|
|
318
331
|
};
|
|
319
332
|
return n(
|
|
320
333
|
() => new Promise(l),
|
|
321
334
|
!1,
|
|
322
335
|
"resolvesWithDelay"
|
|
323
|
-
),
|
|
336
|
+
), s;
|
|
324
337
|
},
|
|
325
|
-
rejectsWithDelay(
|
|
326
|
-
const l = typeof
|
|
338
|
+
rejectsWithDelay(t, i) {
|
|
339
|
+
const l = typeof t == "string" ? new Error(t) : t, u = (a, f) => {
|
|
327
340
|
setTimeout(() => f(l), i);
|
|
328
341
|
};
|
|
329
|
-
return n(() => new Promise(u), !1, "rejectsWithDelay"),
|
|
342
|
+
return n(() => new Promise(u), !1, "rejectsWithDelay"), s;
|
|
330
343
|
},
|
|
331
|
-
rejectsWithNoSuchKey(
|
|
344
|
+
rejectsWithNoSuchKey(t) {
|
|
332
345
|
return n(
|
|
333
|
-
() => Promise.reject(T(
|
|
346
|
+
() => Promise.reject(T(t)),
|
|
334
347
|
!1,
|
|
335
348
|
"rejectsWithNoSuchKey"
|
|
336
|
-
),
|
|
349
|
+
), s;
|
|
337
350
|
},
|
|
338
|
-
rejectsWithNoSuchBucket(
|
|
351
|
+
rejectsWithNoSuchBucket(t) {
|
|
339
352
|
return n(
|
|
340
|
-
() => Promise.reject(
|
|
353
|
+
() => Promise.reject(I(t)),
|
|
341
354
|
!1,
|
|
342
355
|
"rejectsWithNoSuchBucket"
|
|
343
|
-
),
|
|
356
|
+
), s;
|
|
344
357
|
},
|
|
345
|
-
rejectsWithAccessDenied(
|
|
358
|
+
rejectsWithAccessDenied(t) {
|
|
346
359
|
return n(
|
|
347
|
-
() => Promise.reject(
|
|
360
|
+
() => Promise.reject(M(t)),
|
|
348
361
|
!1,
|
|
349
362
|
"rejectsWithAccessDenied"
|
|
350
|
-
),
|
|
363
|
+
), s;
|
|
351
364
|
},
|
|
352
|
-
rejectsWithResourceNotFound(
|
|
365
|
+
rejectsWithResourceNotFound(t) {
|
|
353
366
|
return n(
|
|
354
|
-
() => Promise.reject(
|
|
367
|
+
() => Promise.reject(K(t)),
|
|
355
368
|
!1,
|
|
356
369
|
"rejectsWithResourceNotFound"
|
|
357
|
-
),
|
|
370
|
+
), s;
|
|
358
371
|
},
|
|
359
372
|
rejectsWithConditionalCheckFailed() {
|
|
360
373
|
return n(
|
|
361
374
|
() => Promise.reject(B()),
|
|
362
375
|
!1,
|
|
363
376
|
"rejectsWithConditionalCheckFailed"
|
|
364
|
-
),
|
|
377
|
+
), s;
|
|
365
378
|
},
|
|
366
379
|
rejectsWithThrottling() {
|
|
367
380
|
return n(
|
|
368
381
|
() => Promise.reject(J()),
|
|
369
382
|
!1,
|
|
370
383
|
"rejectsWithThrottling"
|
|
371
|
-
),
|
|
384
|
+
), s;
|
|
372
385
|
},
|
|
373
386
|
rejectsWithInternalServerError() {
|
|
374
387
|
return n(
|
|
375
388
|
() => Promise.reject(q()),
|
|
376
389
|
!1,
|
|
377
390
|
"rejectsWithInternalServerError"
|
|
378
|
-
),
|
|
391
|
+
), s;
|
|
379
392
|
},
|
|
380
|
-
resolvesPaginated(
|
|
381
|
-
const l = G(
|
|
393
|
+
resolvesPaginated(t, i = {}) {
|
|
394
|
+
const l = G(t, i);
|
|
382
395
|
let u = 0;
|
|
383
396
|
return e.debugLogger.log(
|
|
384
|
-
`Configured resolvesPaginated for ${
|
|
385
|
-
{ pageSize: i.pageSize, itemsCount:
|
|
397
|
+
`Configured resolvesPaginated for ${r.name}`,
|
|
398
|
+
{ pageSize: i.pageSize, itemsCount: t.length }
|
|
386
399
|
), n(
|
|
387
400
|
(a) => {
|
|
388
401
|
const f = i.tokenKey || "NextToken", g = i.inputTokenKey || f, b = a[g];
|
|
389
402
|
if (b != null) {
|
|
390
403
|
const R = i.itemsKey || "Items";
|
|
391
|
-
let
|
|
404
|
+
let j = 0;
|
|
392
405
|
for (const F of l) {
|
|
393
406
|
const p = F[R];
|
|
394
407
|
if (p && p.length > 0) {
|
|
395
408
|
const W = p[p.length - 1];
|
|
396
409
|
if (JSON.stringify(W) === JSON.stringify(b)) {
|
|
397
|
-
u =
|
|
410
|
+
u = j + 1;
|
|
398
411
|
break;
|
|
399
412
|
}
|
|
400
413
|
}
|
|
401
|
-
|
|
414
|
+
j++;
|
|
402
415
|
}
|
|
403
416
|
} else
|
|
404
417
|
u = 0;
|
|
405
|
-
const
|
|
418
|
+
const k = (
|
|
406
419
|
// eslint-disable-next-line security/detect-object-injection
|
|
407
420
|
l[u] || // eslint-disable-next-line unicorn/prefer-at -- TypeScript target doesn't support Array.at() method
|
|
408
421
|
l[l.length - 1] || l[0]
|
|
409
422
|
);
|
|
410
|
-
if (!
|
|
423
|
+
if (!k)
|
|
411
424
|
throw new Error("No paginated responses available");
|
|
412
|
-
return u = Math.min(u + 1, l.length - 1), Promise.resolve(
|
|
425
|
+
return u = Math.min(u + 1, l.length - 1), Promise.resolve(k);
|
|
413
426
|
},
|
|
414
427
|
!1,
|
|
415
428
|
"resolvesPaginated"
|
|
416
|
-
),
|
|
429
|
+
), s;
|
|
417
430
|
},
|
|
418
|
-
resolvesFromFile(
|
|
431
|
+
resolvesFromFile(t) {
|
|
419
432
|
return e.debugLogger.log(
|
|
420
|
-
`Configured resolvesFromFile for ${
|
|
421
|
-
{ filePath:
|
|
433
|
+
`Configured resolvesFromFile for ${r.name}`,
|
|
434
|
+
{ filePath: t }
|
|
422
435
|
), n(
|
|
423
436
|
() => {
|
|
424
|
-
const i = U(
|
|
437
|
+
const i = U(t);
|
|
425
438
|
return Promise.resolve(i);
|
|
426
439
|
},
|
|
427
440
|
!1,
|
|
428
441
|
"resolvesFromFile"
|
|
429
|
-
),
|
|
442
|
+
), s;
|
|
430
443
|
}
|
|
431
444
|
};
|
|
432
|
-
return
|
|
445
|
+
return s;
|
|
433
446
|
}
|
|
434
447
|
const le = (e) => {
|
|
435
|
-
const
|
|
448
|
+
const r = {
|
|
436
449
|
map: /* @__PURE__ */ new WeakMap(),
|
|
437
|
-
debugLogger:
|
|
438
|
-
}, o = e.prototype,
|
|
450
|
+
debugLogger: E()
|
|
451
|
+
}, o = e.prototype, c = w.spyOn(o, "send").mockImplementation(x(r)), n = D(r, c, {
|
|
439
452
|
reset: "Clearing call history (mocks preserved)",
|
|
440
453
|
restore: "Restoring original client behavior and clearing all mocks"
|
|
441
454
|
});
|
|
442
455
|
return {
|
|
443
456
|
client: void 0,
|
|
444
|
-
on: (
|
|
445
|
-
t,
|
|
457
|
+
on: (t, i, l) => L(
|
|
446
458
|
r,
|
|
459
|
+
t,
|
|
447
460
|
i,
|
|
448
461
|
l
|
|
449
462
|
),
|
|
450
463
|
...n
|
|
451
464
|
};
|
|
452
465
|
}, ue = (e) => {
|
|
453
|
-
const
|
|
466
|
+
const r = {
|
|
454
467
|
map: /* @__PURE__ */ new WeakMap(),
|
|
455
|
-
debugLogger:
|
|
456
|
-
}, o =
|
|
468
|
+
debugLogger: E()
|
|
469
|
+
}, o = w.spyOn(e, "send").mockImplementation(x(r)), c = D(r, o, {
|
|
457
470
|
reset: "Clearing call history (mocks preserved) for client instance",
|
|
458
471
|
restore: "Restoring original client behavior and clearing all mocks for client instance"
|
|
459
472
|
});
|
|
460
473
|
return {
|
|
461
474
|
client: e,
|
|
462
|
-
on: (
|
|
463
|
-
t,
|
|
464
|
-
c,
|
|
475
|
+
on: (s, t, i) => L(
|
|
465
476
|
r,
|
|
477
|
+
s,
|
|
478
|
+
t,
|
|
466
479
|
i
|
|
467
480
|
),
|
|
468
|
-
...
|
|
481
|
+
...c
|
|
469
482
|
};
|
|
470
483
|
};
|
|
471
484
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aws-sdk-vitest-mock",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.cjs",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {},
|
|
42
42
|
"devDependencies": {
|
|
43
|
+
"@aws-sdk/client-cognito-identity-provider": "^3.970.0",
|
|
43
44
|
"@aws-sdk/client-dynamodb": "3.964.0",
|
|
44
45
|
"@aws-sdk/client-s3": "3.967.0",
|
|
45
46
|
"@aws-sdk/lib-dynamodb": "3.967.0",
|
|
@@ -56,7 +57,7 @@
|
|
|
56
57
|
"@swc/core": "1.15.8",
|
|
57
58
|
"@swc/helpers": "0.5.18",
|
|
58
59
|
"@types/eslint-plugin-security": "3.0.0",
|
|
59
|
-
"@types/node": "24.10.
|
|
60
|
+
"@types/node": "24.10.9",
|
|
60
61
|
"@typescript-eslint/parser": "8.53.0",
|
|
61
62
|
"@vitest/coverage-v8": "4.0.16",
|
|
62
63
|
"@vitest/eslint-plugin": "1.6.6",
|