@mauroandre/velojs 0.0.55 → 0.0.57
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 +423 -3
- package/agent/AGENTS.md +216 -0
- package/agent/skills/velojs-live-loader/SKILL.md +410 -0
- package/dist/channels.d.ts +370 -0
- package/dist/channels.js +376 -0
- package/dist/client.js +56 -45
- package/dist/components.js +7 -6
- package/dist/events.d.ts +6 -0
- package/dist/events.js +1 -0
- package/dist/hooks.d.ts +26 -21
- package/dist/hooks.js +117 -98
- package/dist/live-loader.d.ts +120 -0
- package/dist/live-loader.js +141 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +144 -118
- package/dist/testing/index.d.ts +5 -1
- package/dist/testing/index.js +495 -412
- package/dist/testing/subscription.d.ts +18 -2
- package/dist/testing/types.d.ts +85 -0
- package/dist/types.d.ts +9 -0
- package/dist/vite.d.ts +15 -0
- package/dist/vite.js +431 -340
- package/package.json +1 -1
package/dist/testing/index.js
CHANGED
|
@@ -1,336 +1,337 @@
|
|
|
1
|
-
import { getRegisteredStreams as
|
|
2
|
-
import { trackSocketSession as
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { getRegisteredStreams as W } from "../events.js";
|
|
2
|
+
import { trackSocketSession as L, getAppSockets as M, injectWebSocketServer as B, abortAllSocketSessions as F } from "../sockets.js";
|
|
3
|
+
import { registerChannels as N, getChannelMap as G, __resetChannels as z } from "../channels.js";
|
|
4
|
+
import { createIsolatedContext as Q, withAppContext as K } from "../app-context.js";
|
|
5
|
+
function q(e) {
|
|
5
6
|
if (!e) return;
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
8
|
-
return
|
|
7
|
+
const s = Object.entries(e);
|
|
8
|
+
if (s.length !== 0)
|
|
9
|
+
return s.map(([t, l]) => `${encodeURIComponent(t)}=${encodeURIComponent(l)}`).join("; ");
|
|
9
10
|
}
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
for (const
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
const
|
|
16
|
-
|
|
11
|
+
function X(e) {
|
|
12
|
+
const s = {}, t = e.getSetCookie?.() ?? [];
|
|
13
|
+
for (const l of t) {
|
|
14
|
+
const c = l.indexOf(";"), f = c === -1 ? l : l.slice(0, c), u = f.indexOf("=");
|
|
15
|
+
if (u === -1) continue;
|
|
16
|
+
const p = f.slice(0, u).trim(), o = f.slice(u + 1).trim();
|
|
17
|
+
p && (s[p] = decodeURIComponent(o));
|
|
17
18
|
}
|
|
18
|
-
return
|
|
19
|
+
return s;
|
|
19
20
|
}
|
|
20
|
-
function
|
|
21
|
+
function H(e) {
|
|
21
22
|
if (!e) return "";
|
|
22
|
-
const
|
|
23
|
-
for (const [
|
|
24
|
-
if (Array.isArray(
|
|
25
|
-
for (const
|
|
23
|
+
const s = new URLSearchParams();
|
|
24
|
+
for (const [l, c] of Object.entries(e))
|
|
25
|
+
if (Array.isArray(c))
|
|
26
|
+
for (const f of c) s.append(l, f);
|
|
26
27
|
else
|
|
27
|
-
|
|
28
|
-
const t =
|
|
28
|
+
s.set(l, c);
|
|
29
|
+
const t = s.toString();
|
|
29
30
|
return t ? `?${t}` : "";
|
|
30
31
|
}
|
|
31
|
-
function
|
|
32
|
-
const
|
|
33
|
-
return e.forEach((t,
|
|
34
|
-
|
|
35
|
-
}),
|
|
32
|
+
function Y(e) {
|
|
33
|
+
const s = {};
|
|
34
|
+
return e.forEach((t, l) => {
|
|
35
|
+
s[l] = t;
|
|
36
|
+
}), s;
|
|
36
37
|
}
|
|
37
|
-
function
|
|
38
|
+
function Z(e) {
|
|
38
39
|
return e == null ? { body: null, contentType: null } : typeof e == "string" || e instanceof FormData || e instanceof URLSearchParams || e instanceof Blob || e instanceof ArrayBuffer || ArrayBuffer.isView(e) ? { body: e, contentType: null } : {
|
|
39
40
|
body: JSON.stringify(e),
|
|
40
41
|
contentType: "application/json"
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
|
-
const
|
|
44
|
-
function
|
|
45
|
-
const t =
|
|
46
|
-
return e.startsWith("http://") || e.startsWith("https://") ? e + t : (e.startsWith("/") || (e = "/" + e),
|
|
44
|
+
const V = "http://velojs.test";
|
|
45
|
+
function O(e, s) {
|
|
46
|
+
const t = H(s);
|
|
47
|
+
return e.startsWith("http://") || e.startsWith("https://") ? e + t : (e.startsWith("/") || (e = "/" + e), V + e + t);
|
|
47
48
|
}
|
|
48
|
-
function
|
|
49
|
-
const { user:
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
method:
|
|
53
|
-
headers:
|
|
49
|
+
function D(e = {}) {
|
|
50
|
+
const { user: s, params: t = {}, query: l = {}, body: c, headers: f = {}, cookies: u } = e, p = q(u), o = new Headers(f);
|
|
51
|
+
p && !o.has("cookie") && o.set("cookie", p);
|
|
52
|
+
const n = V + "/_mock" + H(l), i = {
|
|
53
|
+
method: c == null ? "GET" : "POST",
|
|
54
|
+
headers: o
|
|
54
55
|
};
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
return
|
|
56
|
+
c != null && (typeof c == "string" || c instanceof FormData || c instanceof Blob ? i.body = c : (i.body = JSON.stringify(c), o.has("content-type") || o.set("content-type", "application/json")));
|
|
57
|
+
const d = new Request(n, i), a = /* @__PURE__ */ new Map();
|
|
58
|
+
return s !== void 0 && a.set("user", s), {
|
|
58
59
|
req: {
|
|
59
|
-
raw:
|
|
60
|
-
url:
|
|
61
|
-
method:
|
|
62
|
-
param(
|
|
63
|
-
return
|
|
60
|
+
raw: d,
|
|
61
|
+
url: d.url,
|
|
62
|
+
method: d.method,
|
|
63
|
+
param(r) {
|
|
64
|
+
return r === void 0 ? t : t[r];
|
|
64
65
|
},
|
|
65
|
-
query(
|
|
66
|
-
if (
|
|
67
|
-
const
|
|
68
|
-
for (const [
|
|
69
|
-
|
|
70
|
-
return
|
|
66
|
+
query(r) {
|
|
67
|
+
if (r === void 0) {
|
|
68
|
+
const h = {};
|
|
69
|
+
for (const [v, j] of Object.entries(l))
|
|
70
|
+
h[v] = String(j);
|
|
71
|
+
return h;
|
|
71
72
|
}
|
|
72
|
-
return
|
|
73
|
+
return l[r];
|
|
73
74
|
},
|
|
74
|
-
queries(
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
return Array.isArray(
|
|
75
|
+
queries(r) {
|
|
76
|
+
const h = l[r];
|
|
77
|
+
if (h !== void 0)
|
|
78
|
+
return Array.isArray(h) ? h : [h];
|
|
78
79
|
},
|
|
79
|
-
header(
|
|
80
|
-
if (
|
|
81
|
-
const
|
|
82
|
-
return
|
|
83
|
-
|
|
84
|
-
}),
|
|
80
|
+
header(r) {
|
|
81
|
+
if (r === void 0) {
|
|
82
|
+
const h = {};
|
|
83
|
+
return o.forEach((v, j) => {
|
|
84
|
+
h[j] = v;
|
|
85
|
+
}), h;
|
|
85
86
|
}
|
|
86
|
-
return
|
|
87
|
+
return o.get(r) ?? void 0;
|
|
87
88
|
},
|
|
88
89
|
async json() {
|
|
89
|
-
return
|
|
90
|
+
return c == null ? null : typeof c == "object" ? c : JSON.parse(String(c));
|
|
90
91
|
},
|
|
91
92
|
async text() {
|
|
92
|
-
return
|
|
93
|
+
return c == null ? "" : typeof c == "string" ? c : JSON.stringify(c);
|
|
93
94
|
},
|
|
94
95
|
async parseBody() {
|
|
95
|
-
return
|
|
96
|
+
return c ?? {};
|
|
96
97
|
},
|
|
97
98
|
path: "/_mock"
|
|
98
99
|
},
|
|
99
100
|
res: void 0,
|
|
100
101
|
env: {},
|
|
101
102
|
finalized: !1,
|
|
102
|
-
get(
|
|
103
|
-
return
|
|
103
|
+
get(r) {
|
|
104
|
+
return a.get(r);
|
|
104
105
|
},
|
|
105
|
-
set(
|
|
106
|
-
|
|
106
|
+
set(r, h) {
|
|
107
|
+
a.set(r, h);
|
|
107
108
|
},
|
|
108
109
|
var: new Proxy({}, {
|
|
109
|
-
get(
|
|
110
|
-
return
|
|
110
|
+
get(r, h) {
|
|
111
|
+
return a.get(h);
|
|
111
112
|
}
|
|
112
113
|
}),
|
|
113
|
-
json(
|
|
114
|
-
return new Response(JSON.stringify(
|
|
115
|
-
status:
|
|
114
|
+
json(r, h = 200) {
|
|
115
|
+
return new Response(JSON.stringify(r), {
|
|
116
|
+
status: h,
|
|
116
117
|
headers: { "content-type": "application/json" }
|
|
117
118
|
});
|
|
118
119
|
},
|
|
119
|
-
text(
|
|
120
|
-
return new Response(
|
|
120
|
+
text(r, h = 200) {
|
|
121
|
+
return new Response(r, { status: h });
|
|
121
122
|
},
|
|
122
|
-
html(
|
|
123
|
-
return new Response(
|
|
124
|
-
status:
|
|
123
|
+
html(r, h = 200) {
|
|
124
|
+
return new Response(r, {
|
|
125
|
+
status: h,
|
|
125
126
|
headers: { "content-type": "text/html; charset=UTF-8" }
|
|
126
127
|
});
|
|
127
128
|
},
|
|
128
|
-
body(
|
|
129
|
-
return new Response(
|
|
129
|
+
body(r, h = 200) {
|
|
130
|
+
return new Response(r, { status: h });
|
|
130
131
|
},
|
|
131
|
-
redirect(
|
|
132
|
-
return new Response(null, { status:
|
|
132
|
+
redirect(r, h = 302) {
|
|
133
|
+
return new Response(null, { status: h, headers: { location: r } });
|
|
133
134
|
},
|
|
134
|
-
header(
|
|
135
|
+
header(r, h) {
|
|
135
136
|
},
|
|
136
|
-
status(
|
|
137
|
+
status(r) {
|
|
137
138
|
}
|
|
138
139
|
};
|
|
139
140
|
}
|
|
140
|
-
function
|
|
141
|
-
if (typeof
|
|
142
|
-
const t =
|
|
141
|
+
function ee(e, s) {
|
|
142
|
+
if (typeof s == "string") {
|
|
143
|
+
const t = M(e).get(s);
|
|
143
144
|
if (!t)
|
|
144
145
|
throw new Error(
|
|
145
|
-
`[velojs/testing] no socket handler registered at "${
|
|
146
|
+
`[velojs/testing] no socket handler registered at "${s}". Make sure the route exports a socket_* handler and routes are wired.`
|
|
146
147
|
);
|
|
147
|
-
return { handler: t.handler, path:
|
|
148
|
+
return { handler: t.handler, path: s };
|
|
148
149
|
}
|
|
149
|
-
if (typeof
|
|
150
|
-
const t =
|
|
150
|
+
if (typeof s == "function") {
|
|
151
|
+
const t = s.__path;
|
|
151
152
|
if (!t)
|
|
152
153
|
throw new Error(
|
|
153
154
|
"[velojs/testing] socket handler has no __path. Make sure your vitest.config.ts loads veloPlugin() and your routes are registered."
|
|
154
155
|
);
|
|
155
|
-
return { handler:
|
|
156
|
+
return { handler: s, path: t };
|
|
156
157
|
}
|
|
157
|
-
if (
|
|
158
|
-
const t =
|
|
159
|
-
if (!
|
|
158
|
+
if (s && typeof s == "object" && typeof s.__path == "string") {
|
|
159
|
+
const t = s.__path, l = M(e).get(t);
|
|
160
|
+
if (!l)
|
|
160
161
|
throw new Error(
|
|
161
162
|
`[velojs/testing] stub with __path="${t}" has no matching server handler.`
|
|
162
163
|
);
|
|
163
|
-
return { handler:
|
|
164
|
+
return { handler: l.handler, path: t };
|
|
164
165
|
}
|
|
165
166
|
throw new Error("[velojs/testing] socket(): unrecognized handler argument");
|
|
166
167
|
}
|
|
167
|
-
async function
|
|
168
|
-
const { handler:
|
|
168
|
+
async function te(e, s, t = {}) {
|
|
169
|
+
const { handler: l, path: c } = ee(e, s), f = {
|
|
169
170
|
params: t.params ?? {},
|
|
170
171
|
query: {
|
|
171
172
|
...t.query,
|
|
172
173
|
...t.channel ? { channel: t.channel } : {}
|
|
173
174
|
}
|
|
174
175
|
};
|
|
175
|
-
t.user !== void 0 && (
|
|
176
|
-
const
|
|
177
|
-
let
|
|
176
|
+
t.user !== void 0 && (f.user = t.user), t.headers && (f.headers = t.headers), t.cookies && (f.cookies = t.cookies);
|
|
177
|
+
const u = D(f), p = [];
|
|
178
|
+
let o = null, n = !1;
|
|
178
179
|
const i = {
|
|
179
180
|
async *[Symbol.asyncIterator]() {
|
|
180
181
|
for (; ; ) {
|
|
181
|
-
for (;
|
|
182
|
-
yield
|
|
183
|
-
if (
|
|
184
|
-
await new Promise((
|
|
182
|
+
for (; p.length > 0; )
|
|
183
|
+
yield p.shift();
|
|
184
|
+
if (n) return;
|
|
185
|
+
await new Promise((y) => o = y), o = null;
|
|
185
186
|
}
|
|
186
187
|
}
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
},
|
|
190
|
-
|
|
191
|
-
},
|
|
192
|
-
let
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
for (const
|
|
188
|
+
}, d = (y) => {
|
|
189
|
+
n || (p.push(y), o?.());
|
|
190
|
+
}, a = () => {
|
|
191
|
+
n || (n = !0, o?.());
|
|
192
|
+
}, w = [];
|
|
193
|
+
let r = [];
|
|
194
|
+
const h = (y) => {
|
|
195
|
+
w.push(y);
|
|
196
|
+
const P = r;
|
|
197
|
+
r = [];
|
|
198
|
+
for (const R of P)
|
|
198
199
|
try {
|
|
199
|
-
|
|
200
|
+
R();
|
|
200
201
|
} catch {
|
|
201
202
|
}
|
|
202
|
-
},
|
|
203
|
-
let
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
},
|
|
207
|
-
|
|
208
|
-
},
|
|
209
|
-
|
|
210
|
-
},
|
|
211
|
-
if (
|
|
212
|
-
if (
|
|
203
|
+
}, v = new AbortController(), j = L(e, v);
|
|
204
|
+
let m = !1, g = !1;
|
|
205
|
+
const k = (y) => {
|
|
206
|
+
g || (typeof y == "string" || y instanceof Uint8Array ? h(y) : h(JSON.stringify(y)));
|
|
207
|
+
}, E = (y, P) => {
|
|
208
|
+
C();
|
|
209
|
+
}, _ = () => {
|
|
210
|
+
m = !0;
|
|
211
|
+
}, C = () => {
|
|
212
|
+
if (g) return;
|
|
213
|
+
if (g = !0, !v.signal.aborted)
|
|
213
214
|
try {
|
|
214
|
-
|
|
215
|
+
v.abort();
|
|
215
216
|
} catch {
|
|
216
217
|
}
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
for (const
|
|
218
|
+
j(), a();
|
|
219
|
+
const y = r;
|
|
220
|
+
r = [];
|
|
221
|
+
for (const P of y)
|
|
221
222
|
try {
|
|
222
|
-
|
|
223
|
+
P();
|
|
223
224
|
} catch {
|
|
224
225
|
}
|
|
225
|
-
},
|
|
226
|
+
}, b = {
|
|
226
227
|
incoming: i,
|
|
227
|
-
send:
|
|
228
|
-
close:
|
|
229
|
-
keepOpen:
|
|
230
|
-
abortSignal:
|
|
231
|
-
c:
|
|
228
|
+
send: k,
|
|
229
|
+
close: E,
|
|
230
|
+
keepOpen: _,
|
|
231
|
+
abortSignal: v.signal,
|
|
232
|
+
c: u,
|
|
232
233
|
params: t.params ?? {},
|
|
233
234
|
query: {
|
|
234
235
|
...t.query ?? {},
|
|
235
236
|
...t.channel ? { channel: t.channel } : {}
|
|
236
237
|
}
|
|
237
|
-
},
|
|
238
|
+
}, T = (async () => {
|
|
238
239
|
try {
|
|
239
|
-
await
|
|
240
|
-
} catch (
|
|
241
|
-
console.error("[velojs/testing] socket handler threw:",
|
|
240
|
+
await l(b);
|
|
241
|
+
} catch (y) {
|
|
242
|
+
console.error("[velojs/testing] socket handler threw:", y);
|
|
242
243
|
}
|
|
243
|
-
|
|
244
|
-
})(),
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
},
|
|
248
|
-
clearTimeout(
|
|
244
|
+
m || C();
|
|
245
|
+
})(), x = (y) => new Promise((P, R) => {
|
|
246
|
+
const $ = setTimeout(() => {
|
|
247
|
+
r = r.filter((U) => U !== I), R(new Error(`[velojs/testing] socket.next() timed out after ${y}ms`));
|
|
248
|
+
}, y), I = () => {
|
|
249
|
+
clearTimeout($), P();
|
|
249
250
|
};
|
|
250
|
-
|
|
251
|
+
r.push(I);
|
|
251
252
|
});
|
|
252
|
-
let
|
|
253
|
+
let S = 0;
|
|
253
254
|
return {
|
|
254
|
-
send(
|
|
255
|
-
|
|
255
|
+
send(y) {
|
|
256
|
+
g || (typeof y == "string" || y instanceof Uint8Array ? d(y) : d(JSON.stringify(y)));
|
|
256
257
|
},
|
|
257
258
|
get messages() {
|
|
258
|
-
return
|
|
259
|
+
return w;
|
|
259
260
|
},
|
|
260
261
|
get closed() {
|
|
261
|
-
return
|
|
262
|
+
return g;
|
|
262
263
|
},
|
|
263
|
-
async next(
|
|
264
|
-
for (;
|
|
265
|
-
if (
|
|
264
|
+
async next(y) {
|
|
265
|
+
for (; S >= w.length; ) {
|
|
266
|
+
if (g)
|
|
266
267
|
throw new Error("[velojs/testing] socket closed before next()");
|
|
267
|
-
await
|
|
268
|
+
await x(y.timeoutMs);
|
|
268
269
|
}
|
|
269
|
-
return
|
|
270
|
+
return w[S++];
|
|
270
271
|
},
|
|
271
|
-
async nextN(
|
|
272
|
-
const
|
|
273
|
-
for (;
|
|
274
|
-
if (
|
|
275
|
-
|
|
272
|
+
async nextN(y, P) {
|
|
273
|
+
const R = Date.now() + P.timeoutMs, $ = [];
|
|
274
|
+
for (; $.length < y; ) {
|
|
275
|
+
if (S < w.length) {
|
|
276
|
+
$.push(w[S++]);
|
|
276
277
|
continue;
|
|
277
278
|
}
|
|
278
|
-
if (
|
|
279
|
+
if (g)
|
|
279
280
|
throw new Error("[velojs/testing] socket closed before nextN()");
|
|
280
|
-
const
|
|
281
|
-
if (
|
|
281
|
+
const I = R - Date.now();
|
|
282
|
+
if (I <= 0)
|
|
282
283
|
throw new Error(
|
|
283
|
-
`[velojs/testing] socket.nextN() timed out after ${
|
|
284
|
+
`[velojs/testing] socket.nextN() timed out after ${P.timeoutMs}ms`
|
|
284
285
|
);
|
|
285
|
-
await
|
|
286
|
+
await x(I);
|
|
286
287
|
}
|
|
287
|
-
return
|
|
288
|
+
return $;
|
|
288
289
|
},
|
|
289
|
-
async close(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
new Promise((
|
|
290
|
+
async close(y, P) {
|
|
291
|
+
C(), await Promise.race([
|
|
292
|
+
T,
|
|
293
|
+
new Promise((R) => setTimeout(R, 50))
|
|
293
294
|
]);
|
|
294
295
|
},
|
|
295
|
-
done:
|
|
296
|
+
done: T
|
|
296
297
|
};
|
|
297
298
|
}
|
|
298
|
-
function
|
|
299
|
-
const
|
|
300
|
-
function c
|
|
301
|
-
for (const
|
|
302
|
-
const
|
|
303
|
-
if (
|
|
304
|
-
for (const
|
|
305
|
-
if (!
|
|
306
|
-
const i =
|
|
299
|
+
function ne(e) {
|
|
300
|
+
const s = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
|
|
301
|
+
function l(c) {
|
|
302
|
+
for (const f of c) {
|
|
303
|
+
const u = f.module?.metadata?.moduleId, p = f.module?.metadata?.fullPath;
|
|
304
|
+
if (f.module && u) {
|
|
305
|
+
for (const n of Object.keys(f.module)) {
|
|
306
|
+
if (!n.startsWith("action_")) continue;
|
|
307
|
+
const i = f.module[n];
|
|
307
308
|
if (typeof i != "function") continue;
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
name:
|
|
309
|
+
const d = n.replace("action_", "");
|
|
310
|
+
s.set(i, {
|
|
311
|
+
name: d,
|
|
311
312
|
fn: i,
|
|
312
|
-
moduleId:
|
|
313
|
-
url: `/_action/${
|
|
313
|
+
moduleId: u,
|
|
314
|
+
url: `/_action/${u}/${d}`
|
|
314
315
|
});
|
|
315
316
|
}
|
|
316
|
-
const
|
|
317
|
-
if (typeof
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
fn:
|
|
321
|
-
moduleId:
|
|
322
|
-
paths: [
|
|
317
|
+
const o = f.module.loader;
|
|
318
|
+
if (typeof o == "function" && p) {
|
|
319
|
+
const n = t.get(o);
|
|
320
|
+
n ? n.paths.push(p) : t.set(o, {
|
|
321
|
+
fn: o,
|
|
322
|
+
moduleId: u,
|
|
323
|
+
paths: [p]
|
|
323
324
|
});
|
|
324
325
|
}
|
|
325
326
|
}
|
|
326
|
-
|
|
327
|
+
f.children && l(f.children);
|
|
327
328
|
}
|
|
328
329
|
}
|
|
329
|
-
return
|
|
330
|
+
return l(e), { actions: s, loaders: t };
|
|
330
331
|
}
|
|
331
|
-
function
|
|
332
|
-
if (typeof
|
|
333
|
-
const t = e.actions.get(
|
|
332
|
+
function se(e, s) {
|
|
333
|
+
if (typeof s == "string") return s;
|
|
334
|
+
const t = e.actions.get(s);
|
|
334
335
|
if (!t)
|
|
335
336
|
throw new Error(
|
|
336
337
|
`[velojs/testing] action_* function was not found in the route tree.
|
|
@@ -338,159 +339,204 @@ Make sure your Vitest config loads the VeloJS Vite plugin so that metadata is in
|
|
|
338
339
|
);
|
|
339
340
|
return t.url;
|
|
340
341
|
}
|
|
341
|
-
function
|
|
342
|
-
if (typeof
|
|
343
|
-
const
|
|
344
|
-
if (!
|
|
342
|
+
function oe(e, s, t) {
|
|
343
|
+
if (typeof s == "string") return s;
|
|
344
|
+
const l = e.loaders.get(s);
|
|
345
|
+
if (!l)
|
|
345
346
|
throw new Error(
|
|
346
347
|
`[velojs/testing] loader function was not found in the route tree.
|
|
347
348
|
Make sure your Vitest config loads the VeloJS Vite plugin so that metadata is injected.`
|
|
348
349
|
);
|
|
349
|
-
let
|
|
350
|
+
let c = l.paths[0];
|
|
350
351
|
if (t)
|
|
351
|
-
for (const [
|
|
352
|
-
|
|
353
|
-
return
|
|
352
|
+
for (const [f, u] of Object.entries(t))
|
|
353
|
+
c = c.replace(`:${f}`, encodeURIComponent(u));
|
|
354
|
+
return c;
|
|
354
355
|
}
|
|
355
|
-
class
|
|
356
|
+
class re {
|
|
356
357
|
buffer = "";
|
|
357
358
|
current = {
|
|
358
359
|
event: "message",
|
|
359
360
|
data: []
|
|
360
361
|
};
|
|
361
|
-
push(
|
|
362
|
-
this.buffer +=
|
|
362
|
+
push(s) {
|
|
363
|
+
this.buffer += s;
|
|
363
364
|
const t = [];
|
|
364
|
-
let
|
|
365
|
-
for (; (
|
|
365
|
+
let l;
|
|
366
|
+
for (; (l = this.buffer.indexOf(`
|
|
366
367
|
`)) !== -1; ) {
|
|
367
|
-
const
|
|
368
|
-
if (this.buffer = this.buffer.slice(
|
|
368
|
+
const c = this.buffer.slice(0, l);
|
|
369
|
+
if (this.buffer = this.buffer.slice(l + 1), c === "") {
|
|
369
370
|
if (this.current.data.length > 0 || this.current.event !== "message") {
|
|
370
|
-
const
|
|
371
|
+
const o = {
|
|
371
372
|
event: this.current.event,
|
|
372
373
|
data: this.current.data.join(`
|
|
373
374
|
`)
|
|
374
375
|
};
|
|
375
|
-
this.current.id !== void 0 && (
|
|
376
|
+
this.current.id !== void 0 && (o.id = this.current.id), t.push(o);
|
|
376
377
|
}
|
|
377
378
|
this.current = { event: "message", data: [] };
|
|
378
379
|
continue;
|
|
379
380
|
}
|
|
380
|
-
if (
|
|
381
|
-
const
|
|
382
|
-
if (
|
|
383
|
-
const
|
|
384
|
-
let
|
|
385
|
-
|
|
381
|
+
if (c.startsWith(":")) continue;
|
|
382
|
+
const f = c.indexOf(":");
|
|
383
|
+
if (f === -1) continue;
|
|
384
|
+
const u = c.slice(0, f);
|
|
385
|
+
let p = c.slice(f + 1);
|
|
386
|
+
p.startsWith(" ") && (p = p.slice(1)), u === "event" ? this.current.event = p : u === "data" ? this.current.data.push(p) : u === "id" && (this.current.id = p);
|
|
386
387
|
}
|
|
387
388
|
return t;
|
|
388
389
|
}
|
|
389
390
|
}
|
|
390
|
-
async function
|
|
391
|
-
const { response:
|
|
392
|
-
let
|
|
393
|
-
const
|
|
394
|
-
let r = null,
|
|
395
|
-
const
|
|
396
|
-
for (;
|
|
397
|
-
const
|
|
398
|
-
|
|
391
|
+
async function J(e) {
|
|
392
|
+
const { response: s, snapshotEvents: t = !1, channelEvents: l = !1 } = e, c = s.status, f = [], u = [];
|
|
393
|
+
let p = null, o = !1, n = null, i = 0, d = 0;
|
|
394
|
+
const a = [], w = [];
|
|
395
|
+
let r = null, h = Promise.resolve(void 0);
|
|
396
|
+
const v = (m) => {
|
|
397
|
+
for (; a.length > 0; ) {
|
|
398
|
+
const g = a.shift();
|
|
399
|
+
m ? g.reject(m) : g.reject(new Error("[velojs/testing] subscription closed before next event"));
|
|
400
|
+
}
|
|
401
|
+
for (; w.length > 0; ) {
|
|
402
|
+
const g = w.shift();
|
|
403
|
+
m ? g.reject(m) : g.reject(new Error("[velojs/testing] subscription closed before next event"));
|
|
399
404
|
}
|
|
400
405
|
};
|
|
401
|
-
if (
|
|
402
|
-
r =
|
|
403
|
-
const
|
|
404
|
-
|
|
406
|
+
if (c >= 200 && c < 300 && s.body) {
|
|
407
|
+
r = s.body.getReader();
|
|
408
|
+
const m = new TextDecoder(), g = new re();
|
|
409
|
+
h = (async () => {
|
|
405
410
|
try {
|
|
406
411
|
for (; ; ) {
|
|
407
|
-
const { value:
|
|
408
|
-
if (
|
|
409
|
-
|
|
412
|
+
const { value: k, done: E } = await r.read();
|
|
413
|
+
if (E) {
|
|
414
|
+
o || (o = !0), v();
|
|
410
415
|
return;
|
|
411
416
|
}
|
|
412
|
-
const
|
|
413
|
-
for (const
|
|
414
|
-
|
|
417
|
+
const _ = m.decode(k, { stream: !0 }), C = g.push(_);
|
|
418
|
+
for (const b of C) {
|
|
419
|
+
const T = b.event === "slice";
|
|
420
|
+
if (b.event === "snapshot" || l && T) {
|
|
421
|
+
let x;
|
|
415
422
|
try {
|
|
416
|
-
|
|
417
|
-
} catch (
|
|
418
|
-
|
|
423
|
+
x = JSON.parse(b.data);
|
|
424
|
+
} catch (S) {
|
|
425
|
+
n = S;
|
|
426
|
+
}
|
|
427
|
+
if (x !== void 0) {
|
|
428
|
+
if (T || (p = x), t || l && T) {
|
|
429
|
+
const S = x;
|
|
430
|
+
f.push(S);
|
|
431
|
+
const A = a.shift();
|
|
432
|
+
A && A.resolve(S);
|
|
433
|
+
}
|
|
434
|
+
if (l) {
|
|
435
|
+
const S = {
|
|
436
|
+
type: T ? "slice" : "snapshot",
|
|
437
|
+
data: x
|
|
438
|
+
};
|
|
439
|
+
u.push(S);
|
|
440
|
+
const A = w.shift();
|
|
441
|
+
A && A.resolve(S);
|
|
442
|
+
}
|
|
419
443
|
}
|
|
420
444
|
continue;
|
|
421
445
|
}
|
|
422
|
-
if (
|
|
423
|
-
|
|
446
|
+
if (b.event === "close") {
|
|
447
|
+
o = !0, v(), r.cancel().catch(() => {
|
|
424
448
|
});
|
|
425
449
|
return;
|
|
426
450
|
}
|
|
427
|
-
if (
|
|
451
|
+
if (b.event !== "heartbeat")
|
|
428
452
|
try {
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
} catch (
|
|
434
|
-
|
|
453
|
+
const x = JSON.parse(b.data);
|
|
454
|
+
f.push(x);
|
|
455
|
+
const S = a.shift();
|
|
456
|
+
S && S.resolve(x);
|
|
457
|
+
} catch (x) {
|
|
458
|
+
n = x;
|
|
435
459
|
}
|
|
436
460
|
}
|
|
437
461
|
}
|
|
438
|
-
} catch (
|
|
439
|
-
if (
|
|
440
|
-
|
|
462
|
+
} catch (k) {
|
|
463
|
+
if (k?.name === "AbortError") {
|
|
464
|
+
v();
|
|
441
465
|
return;
|
|
442
466
|
}
|
|
443
|
-
|
|
467
|
+
v(k);
|
|
444
468
|
}
|
|
445
469
|
})();
|
|
446
470
|
} else
|
|
447
|
-
await
|
|
448
|
-
const
|
|
471
|
+
await s.text().catch(() => ""), o = !0;
|
|
472
|
+
const j = {
|
|
449
473
|
get status() {
|
|
450
|
-
return
|
|
474
|
+
return c;
|
|
451
475
|
},
|
|
452
476
|
get events() {
|
|
453
|
-
return
|
|
477
|
+
return f;
|
|
454
478
|
},
|
|
455
479
|
get snapshot() {
|
|
456
|
-
return
|
|
480
|
+
return p;
|
|
457
481
|
},
|
|
458
482
|
get closed() {
|
|
459
|
-
return
|
|
483
|
+
return o;
|
|
484
|
+
},
|
|
485
|
+
async next({ timeoutMs: m }) {
|
|
486
|
+
if (n) throw n;
|
|
487
|
+
if (f.length > i) {
|
|
488
|
+
const g = f[i];
|
|
489
|
+
return i++, g;
|
|
490
|
+
}
|
|
491
|
+
if (o)
|
|
492
|
+
throw new Error("[velojs/testing] subscription is closed");
|
|
493
|
+
return new Promise((g, k) => {
|
|
494
|
+
const E = setTimeout(() => {
|
|
495
|
+
const b = a.findIndex((T) => T.resolve === _);
|
|
496
|
+
b !== -1 && a.splice(b, 1), k(new Error(
|
|
497
|
+
`[velojs/testing] timed out after ${m}ms waiting for next event`
|
|
498
|
+
));
|
|
499
|
+
}, m), _ = (b) => {
|
|
500
|
+
clearTimeout(E), i++, g(b);
|
|
501
|
+
}, C = (b) => {
|
|
502
|
+
clearTimeout(E), k(b);
|
|
503
|
+
};
|
|
504
|
+
a.push({ resolve: _, reject: C });
|
|
505
|
+
});
|
|
460
506
|
},
|
|
461
|
-
async
|
|
462
|
-
if (
|
|
463
|
-
if (
|
|
464
|
-
const
|
|
465
|
-
return d++,
|
|
507
|
+
async nextEvent({ timeoutMs: m }) {
|
|
508
|
+
if (n) throw n;
|
|
509
|
+
if (u.length > d) {
|
|
510
|
+
const g = u[d];
|
|
511
|
+
return d++, g;
|
|
466
512
|
}
|
|
467
|
-
if (
|
|
513
|
+
if (o)
|
|
468
514
|
throw new Error("[velojs/testing] subscription is closed");
|
|
469
|
-
return new Promise((
|
|
470
|
-
const
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
`[velojs/testing] timed out after ${
|
|
515
|
+
return new Promise((g, k) => {
|
|
516
|
+
const E = setTimeout(() => {
|
|
517
|
+
const b = w.findIndex((T) => T.resolve === _);
|
|
518
|
+
b !== -1 && w.splice(b, 1), k(new Error(
|
|
519
|
+
`[velojs/testing] timed out after ${m}ms waiting for next event`
|
|
474
520
|
));
|
|
475
|
-
},
|
|
476
|
-
clearTimeout(
|
|
477
|
-
},
|
|
478
|
-
clearTimeout(
|
|
521
|
+
}, m), _ = (b) => {
|
|
522
|
+
clearTimeout(E), d++, g(b);
|
|
523
|
+
}, C = (b) => {
|
|
524
|
+
clearTimeout(E), k(b);
|
|
479
525
|
};
|
|
480
|
-
|
|
526
|
+
w.push({ resolve: _, reject: C });
|
|
481
527
|
});
|
|
482
528
|
},
|
|
483
|
-
async nextN(
|
|
484
|
-
const
|
|
485
|
-
for (let
|
|
486
|
-
const
|
|
487
|
-
if (
|
|
529
|
+
async nextN(m, { timeoutMs: g }) {
|
|
530
|
+
const k = Date.now(), E = [];
|
|
531
|
+
for (let _ = 0; _ < m; _++) {
|
|
532
|
+
const C = g - (Date.now() - k);
|
|
533
|
+
if (C <= 0)
|
|
488
534
|
throw new Error(
|
|
489
|
-
`[velojs/testing] timed out after ${
|
|
535
|
+
`[velojs/testing] timed out after ${g}ms waiting for ${m} events (got ${E.length})`
|
|
490
536
|
);
|
|
491
|
-
|
|
537
|
+
E.push(await j.next({ timeoutMs: C }));
|
|
492
538
|
}
|
|
493
|
-
return
|
|
539
|
+
return E;
|
|
494
540
|
},
|
|
495
541
|
async close() {
|
|
496
542
|
if (r)
|
|
@@ -498,200 +544,237 @@ async function te(e) {
|
|
|
498
544
|
await r.cancel();
|
|
499
545
|
} catch {
|
|
500
546
|
}
|
|
501
|
-
|
|
547
|
+
o = !0, v(), await h.catch(() => {
|
|
502
548
|
});
|
|
503
549
|
}
|
|
504
550
|
};
|
|
505
|
-
|
|
506
|
-
return w;
|
|
551
|
+
return j;
|
|
507
552
|
}
|
|
508
|
-
async function
|
|
509
|
-
const
|
|
510
|
-
return await
|
|
553
|
+
async function ge(e) {
|
|
554
|
+
const s = Q();
|
|
555
|
+
return await K(s, async () => {
|
|
511
556
|
e.bootstrap && await e.bootstrap();
|
|
512
|
-
const
|
|
513
|
-
|
|
557
|
+
const t = {
|
|
558
|
+
...e.channelOptions,
|
|
559
|
+
coalesceMs: e.channelOptions?.coalesceMs ?? 0,
|
|
560
|
+
idleMs: e.channelOptions?.idleMs ?? 0,
|
|
561
|
+
heartbeatMs: e.channelOptions?.heartbeatMs ?? 0
|
|
562
|
+
};
|
|
563
|
+
e.channels ? N(e.channels, t) : N(G(), t);
|
|
564
|
+
const { createApp: l } = await import("../server.js"), c = await l(e.routes), f = ne(e.routes), u = e.port !== void 0 ? await ie(c, e.port, e.hostname) : void 0;
|
|
565
|
+
return ae(c, s, f, e, void 0, u);
|
|
514
566
|
});
|
|
515
567
|
}
|
|
516
|
-
async function
|
|
517
|
-
const { serve:
|
|
568
|
+
async function ie(e, s, t) {
|
|
569
|
+
const { serve: l } = await import("@hono/node-server"), { flushServerCallbacks: c, clearActiveServer: f } = await import("../server.js"), u = l({
|
|
518
570
|
fetch: e.fetch,
|
|
519
|
-
port:
|
|
571
|
+
port: s,
|
|
520
572
|
...t ? { hostname: t } : {}
|
|
521
|
-
}),
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
}), await
|
|
525
|
-
const
|
|
526
|
-
let
|
|
573
|
+
}), p = /* @__PURE__ */ new Set();
|
|
574
|
+
u.on("connection", (a) => {
|
|
575
|
+
p.add(a), a.on("close", () => p.delete(a));
|
|
576
|
+
}), await ce(u, s, t), await B(e, u), c(u);
|
|
577
|
+
const o = u.address(), n = o && typeof o == "object" ? o.port : s, i = t && t !== "0.0.0.0" && t !== "::" ? t : "localhost";
|
|
578
|
+
let d = !1;
|
|
527
579
|
return {
|
|
528
|
-
port:
|
|
529
|
-
url: `http://${i}:${
|
|
580
|
+
port: n,
|
|
581
|
+
url: `http://${i}:${n}`,
|
|
530
582
|
async close() {
|
|
531
|
-
if (
|
|
532
|
-
|
|
533
|
-
const
|
|
534
|
-
|
|
583
|
+
if (d) return;
|
|
584
|
+
d = !0;
|
|
585
|
+
const a = new Promise((w) => {
|
|
586
|
+
u.close(() => w());
|
|
535
587
|
});
|
|
536
|
-
for (const
|
|
537
|
-
|
|
588
|
+
for (const w of p) w.destroy();
|
|
589
|
+
p.clear(), u.closeAllConnections(), await a, f(u);
|
|
538
590
|
}
|
|
539
591
|
};
|
|
540
592
|
}
|
|
541
|
-
function
|
|
542
|
-
return e.listening ? Promise.resolve() : new Promise((
|
|
543
|
-
const
|
|
544
|
-
e.off("listening",
|
|
545
|
-
},
|
|
546
|
-
|
|
547
|
-
},
|
|
548
|
-
|
|
549
|
-
const i =
|
|
550
|
-
|
|
551
|
-
`[velojs/testing] could not bind the test server on ${
|
|
593
|
+
function ce(e, s, t) {
|
|
594
|
+
return e.listening ? Promise.resolve() : new Promise((l, c) => {
|
|
595
|
+
const f = `${t ?? "0.0.0.0"}:${s}`, u = () => {
|
|
596
|
+
e.off("listening", p), e.off("error", o);
|
|
597
|
+
}, p = () => {
|
|
598
|
+
u(), l();
|
|
599
|
+
}, o = (n) => {
|
|
600
|
+
u();
|
|
601
|
+
const i = n.code ? `${n.code}: ${n.message}` : n.message;
|
|
602
|
+
c(new Error(
|
|
603
|
+
`[velojs/testing] could not bind the test server on ${f} — ${i}`
|
|
552
604
|
));
|
|
553
605
|
};
|
|
554
|
-
e.once("listening",
|
|
606
|
+
e.once("listening", p), e.once("error", o);
|
|
555
607
|
});
|
|
556
608
|
}
|
|
557
|
-
function
|
|
558
|
-
async function
|
|
559
|
-
const
|
|
560
|
-
|
|
561
|
-
let
|
|
562
|
-
if (
|
|
563
|
-
const
|
|
564
|
-
|
|
609
|
+
function ae(e, s, t, l, c, f) {
|
|
610
|
+
async function u(n, i, d = {}) {
|
|
611
|
+
const a = O(i, d.query), w = new Headers(d.headers ?? {}), r = { ...d.cookies ?? {} }, h = q(r);
|
|
612
|
+
h && w.set("cookie", h);
|
|
613
|
+
let v = null;
|
|
614
|
+
if (d.body !== void 0) {
|
|
615
|
+
const k = Z(d.body);
|
|
616
|
+
v = k.body, k.contentType && !w.has("content-type") && w.set("content-type", k.contentType);
|
|
565
617
|
}
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
const
|
|
569
|
-
return await
|
|
618
|
+
const j = { method: n, headers: w };
|
|
619
|
+
v !== null && (j.body = v);
|
|
620
|
+
const m = new Request(a, j), g = await e.fetch(m);
|
|
621
|
+
return await le(g);
|
|
570
622
|
}
|
|
571
|
-
async function
|
|
572
|
-
const
|
|
573
|
-
...
|
|
574
|
-
...
|
|
575
|
-
}),
|
|
576
|
-
|
|
577
|
-
const
|
|
578
|
-
return await e.fetch(
|
|
623
|
+
async function p(n, i, d = {}) {
|
|
624
|
+
const a = O(i, {
|
|
625
|
+
...d.query ?? {},
|
|
626
|
+
...d.channel ? { channel: d.channel } : {}
|
|
627
|
+
}), w = new Headers(d.headers ?? {}), r = { ...d.cookies ?? {} }, h = q(r);
|
|
628
|
+
h && w.set("cookie", h);
|
|
629
|
+
const v = new Request(a, { method: n, headers: w });
|
|
630
|
+
return await e.fetch(v);
|
|
579
631
|
}
|
|
580
|
-
const
|
|
632
|
+
const o = {
|
|
581
633
|
hono: e,
|
|
582
634
|
// `undefined` unless `port` was passed — no listener, no behavior change.
|
|
583
|
-
port:
|
|
584
|
-
url:
|
|
635
|
+
port: f?.port,
|
|
636
|
+
url: f?.url,
|
|
585
637
|
// HTTP
|
|
586
|
-
get: (
|
|
587
|
-
post: (
|
|
588
|
-
put: (
|
|
589
|
-
patch: (
|
|
590
|
-
delete: (
|
|
591
|
-
async action(
|
|
592
|
-
const
|
|
593
|
-
return await
|
|
638
|
+
get: (n, i) => u("GET", n, i ?? {}),
|
|
639
|
+
post: (n, i) => u("POST", n, i ?? {}),
|
|
640
|
+
put: (n, i) => u("PUT", n, i ?? {}),
|
|
641
|
+
patch: (n, i) => u("PATCH", n, i ?? {}),
|
|
642
|
+
delete: (n, i) => u("DELETE", n, i ?? {}),
|
|
643
|
+
async action(n, i = {}) {
|
|
644
|
+
const d = se(t, n);
|
|
645
|
+
return await u("POST", d, {
|
|
594
646
|
...i,
|
|
595
647
|
body: i.body ?? {}
|
|
596
648
|
});
|
|
597
649
|
},
|
|
598
|
-
async loader(
|
|
599
|
-
const
|
|
650
|
+
async loader(n, i = {}) {
|
|
651
|
+
const d = oe(t, n, i.params), a = await u("GET", d, {
|
|
600
652
|
...i,
|
|
601
653
|
query: { ...i.query ?? {}, _data: "1" }
|
|
602
654
|
});
|
|
603
|
-
if (
|
|
604
|
-
const
|
|
605
|
-
return
|
|
655
|
+
if (a.status >= 300 && a.status < 400 || a.status >= 400) return a;
|
|
656
|
+
const w = typeof n == "function" ? t.loaders.get(n)?.moduleId : void 0, r = await a.json();
|
|
657
|
+
return w && r && typeof r == "object" && w in r ? r[w] : r;
|
|
658
|
+
},
|
|
659
|
+
async subscribe(n, i = {}) {
|
|
660
|
+
const d = typeof n == "string" ? n : n.__path ?? fe(), a = await p("GET", d, i);
|
|
661
|
+
return await J({ response: a });
|
|
606
662
|
},
|
|
607
|
-
async
|
|
608
|
-
const
|
|
609
|
-
|
|
663
|
+
async channel(n, i, d = {}) {
|
|
664
|
+
const a = typeof n == "string" ? n : n?.metadata?.moduleId;
|
|
665
|
+
a || ue(n);
|
|
666
|
+
const w = d.params ? { _route: JSON.stringify(d.params) } : {}, r = await p(
|
|
667
|
+
"GET",
|
|
668
|
+
`/_channel/${a}/${i}`,
|
|
669
|
+
{
|
|
670
|
+
...d,
|
|
671
|
+
query: { ...d.query ?? {}, ...w }
|
|
672
|
+
}
|
|
673
|
+
);
|
|
674
|
+
return await J({
|
|
675
|
+
response: r,
|
|
676
|
+
snapshotEvents: !0,
|
|
677
|
+
channelEvents: !0
|
|
678
|
+
});
|
|
610
679
|
},
|
|
611
|
-
async socket(
|
|
612
|
-
return await
|
|
680
|
+
async socket(n, i = {}) {
|
|
681
|
+
return await te(e, n, i);
|
|
613
682
|
},
|
|
614
|
-
async sessionCookies({ user:
|
|
615
|
-
if (!
|
|
683
|
+
async sessionCookies({ user: n }) {
|
|
684
|
+
if (!l.getSessionCookie)
|
|
616
685
|
throw new Error(
|
|
617
686
|
"[velojs/testing] sessionCookies/as requires `getSessionCookie` in createTestApp options."
|
|
618
687
|
);
|
|
619
|
-
return await
|
|
688
|
+
return await l.getSessionCookie({ user: n });
|
|
620
689
|
},
|
|
621
|
-
as({ user:
|
|
622
|
-
if (!
|
|
690
|
+
as({ user: n }) {
|
|
691
|
+
if (!l.getSessionCookie)
|
|
623
692
|
throw new Error(
|
|
624
693
|
"[velojs/testing] app.as() requires `getSessionCookie` in createTestApp options."
|
|
625
694
|
);
|
|
626
695
|
let i = null;
|
|
627
|
-
const
|
|
628
|
-
const
|
|
629
|
-
...
|
|
630
|
-
cookies: { ...
|
|
696
|
+
const d = () => (i || (i = Promise.resolve(l.getSessionCookie({ user: n }))), i), a = (h) => (async (...v) => {
|
|
697
|
+
const j = await d(), [m, g] = v, k = {
|
|
698
|
+
...g ?? {},
|
|
699
|
+
cookies: { ...j, ...g?.cookies ?? {} }
|
|
631
700
|
};
|
|
632
|
-
return await
|
|
701
|
+
return await h.call(o, m, k);
|
|
702
|
+
}), w = (h) => (async (v, j, m = {}) => {
|
|
703
|
+
const g = await d();
|
|
704
|
+
return await h.call(o, v, j, {
|
|
705
|
+
...m,
|
|
706
|
+
cookies: { ...g, ...m?.cookies ?? {} }
|
|
707
|
+
});
|
|
633
708
|
});
|
|
634
709
|
return {
|
|
635
710
|
hono: e,
|
|
636
|
-
port:
|
|
637
|
-
url:
|
|
638
|
-
get:
|
|
639
|
-
post:
|
|
640
|
-
put:
|
|
641
|
-
patch:
|
|
642
|
-
delete:
|
|
643
|
-
action:
|
|
644
|
-
loader:
|
|
645
|
-
subscribe:
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
711
|
+
port: o.port,
|
|
712
|
+
url: o.url,
|
|
713
|
+
get: a(o.get),
|
|
714
|
+
post: a(o.post),
|
|
715
|
+
put: a(o.put),
|
|
716
|
+
patch: a(o.patch),
|
|
717
|
+
delete: a(o.delete),
|
|
718
|
+
action: a(o.action),
|
|
719
|
+
loader: a(o.loader),
|
|
720
|
+
subscribe: a(o.subscribe),
|
|
721
|
+
channel: w(o.channel),
|
|
722
|
+
socket: a(o.socket),
|
|
723
|
+
sessionCookies: o.sessionCookies,
|
|
724
|
+
as: o.as,
|
|
649
725
|
// chaining .as.as works — last wins
|
|
650
|
-
mockContext:
|
|
651
|
-
reset:
|
|
652
|
-
close:
|
|
726
|
+
mockContext: o.mockContext,
|
|
727
|
+
reset: o.reset,
|
|
728
|
+
close: o.close
|
|
653
729
|
};
|
|
654
730
|
},
|
|
655
|
-
mockContext(
|
|
656
|
-
return
|
|
731
|
+
mockContext(n = {}) {
|
|
732
|
+
return D(n);
|
|
657
733
|
},
|
|
658
734
|
async reset() {
|
|
659
|
-
for (const
|
|
735
|
+
for (const n of W())
|
|
660
736
|
try {
|
|
661
|
-
|
|
737
|
+
n.__reset();
|
|
662
738
|
} catch (i) {
|
|
663
739
|
console.error("[velojs/testing] stream.__reset failed:", i);
|
|
664
740
|
}
|
|
741
|
+
z();
|
|
665
742
|
},
|
|
666
743
|
async close() {
|
|
667
|
-
await
|
|
668
|
-
for (const
|
|
744
|
+
await o.reset(), F(e);
|
|
745
|
+
for (const n of s.disposers)
|
|
669
746
|
try {
|
|
670
|
-
|
|
747
|
+
n();
|
|
671
748
|
} catch (i) {
|
|
672
749
|
console.error("[velojs/testing] disposer failed:", i);
|
|
673
750
|
}
|
|
674
|
-
|
|
751
|
+
s.disposers.clear(), await f?.close();
|
|
675
752
|
}
|
|
676
753
|
};
|
|
677
|
-
return
|
|
754
|
+
return o;
|
|
678
755
|
}
|
|
679
|
-
async function
|
|
756
|
+
async function le(e) {
|
|
680
757
|
return {
|
|
681
758
|
status: e.status,
|
|
682
|
-
headers:
|
|
683
|
-
cookies:
|
|
759
|
+
headers: Y(e.headers),
|
|
760
|
+
cookies: X(e.headers),
|
|
684
761
|
json: () => e.clone().json(),
|
|
685
762
|
text: () => e.clone().text(),
|
|
686
763
|
blob: () => e.clone().blob(),
|
|
687
764
|
raw: e
|
|
688
765
|
};
|
|
689
766
|
}
|
|
690
|
-
function
|
|
767
|
+
function ue(e) {
|
|
768
|
+
const s = typeof e == "string" ? e : "(a module without metadata)";
|
|
769
|
+
throw new Error(
|
|
770
|
+
`[velojs/testing] channel(module, name) needs the module's metadata.moduleId — got ${s}. Pass the imported route module (the Vite plugin injects the metadata) or the moduleId string.`
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
function fe(e) {
|
|
691
774
|
throw new Error(
|
|
692
775
|
"[velojs/testing] subscribe(stream) — stream has no __path. If this is a stream_* declaration, make sure your routes import is processed by the VeloJS Vite plugin (your vitest.config.ts must include `veloPlugin()`)."
|
|
693
776
|
);
|
|
694
777
|
}
|
|
695
778
|
export {
|
|
696
|
-
|
|
779
|
+
ge as createTestApp
|
|
697
780
|
};
|