@mauroandre/velojs 0.0.54 → 0.0.56
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 +332 -3
- package/agent/AGENTS.md +149 -0
- package/agent/skills/velojs-getting-started/SKILL.md +2 -0
- package/agent/skills/velojs-live-loader/SKILL.md +329 -0
- package/agent/skills/velojs-production-deploy/SKILL.md +6 -0
- package/agent/skills/velojs-server-api/SKILL.md +1 -0
- package/agent/skills/velojs-type-reference/SKILL.md +1 -0
- package/dist/channels.d.ts +289 -0
- package/dist/channels.js +283 -0
- package/dist/client.js +55 -45
- package/dist/components.js +7 -6
- package/dist/config.d.ts +5 -3
- 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 +87 -0
- package/dist/live-loader.js +131 -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 +507 -427
- package/dist/testing/subscription.d.ts +18 -2
- package/dist/testing/types.d.ts +68 -0
- package/dist/types.d.ts +9 -0
- package/dist/vite.d.ts +16 -1
- package/dist/vite.js +458 -359
- 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 q, 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 M(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 w = f.slice(0, u).trim(), o = f.slice(u + 1).trim();
|
|
17
|
+
w && (s[w] = 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, w = M(u), o = new Headers(f);
|
|
51
|
+
w && !o.has("cookie") && o.set("cookie", w);
|
|
52
|
+
const n = V + "/_mock" + H(l), r = {
|
|
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 ? r.body = c : (r.body = JSON.stringify(c), o.has("content-type") || o.set("content-type", "application/json")));
|
|
57
|
+
const h = new Request(n, r), 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: h,
|
|
61
|
+
url: h.url,
|
|
62
|
+
method: h.method,
|
|
63
|
+
param(i) {
|
|
64
|
+
return i === void 0 ? t : t[i];
|
|
64
65
|
},
|
|
65
|
-
query(
|
|
66
|
-
if (
|
|
67
|
-
const
|
|
68
|
-
for (const [
|
|
69
|
-
|
|
70
|
-
return
|
|
66
|
+
query(i) {
|
|
67
|
+
if (i === void 0) {
|
|
68
|
+
const d = {};
|
|
69
|
+
for (const [v, j] of Object.entries(l))
|
|
70
|
+
d[v] = String(j);
|
|
71
|
+
return d;
|
|
71
72
|
}
|
|
72
|
-
return
|
|
73
|
+
return l[i];
|
|
73
74
|
},
|
|
74
|
-
queries(
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
return Array.isArray(
|
|
75
|
+
queries(i) {
|
|
76
|
+
const d = l[i];
|
|
77
|
+
if (d !== void 0)
|
|
78
|
+
return Array.isArray(d) ? d : [d];
|
|
78
79
|
},
|
|
79
|
-
header(
|
|
80
|
-
if (
|
|
81
|
-
const
|
|
82
|
-
return
|
|
83
|
-
|
|
84
|
-
}),
|
|
80
|
+
header(i) {
|
|
81
|
+
if (i === void 0) {
|
|
82
|
+
const d = {};
|
|
83
|
+
return o.forEach((v, j) => {
|
|
84
|
+
d[j] = v;
|
|
85
|
+
}), d;
|
|
85
86
|
}
|
|
86
|
-
return
|
|
87
|
+
return o.get(i) ?? 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(i) {
|
|
104
|
+
return a.get(i);
|
|
104
105
|
},
|
|
105
|
-
set(
|
|
106
|
-
|
|
106
|
+
set(i, d) {
|
|
107
|
+
a.set(i, d);
|
|
107
108
|
},
|
|
108
109
|
var: new Proxy({}, {
|
|
109
|
-
get(
|
|
110
|
-
return
|
|
110
|
+
get(i, d) {
|
|
111
|
+
return a.get(d);
|
|
111
112
|
}
|
|
112
113
|
}),
|
|
113
|
-
json(
|
|
114
|
-
return new Response(JSON.stringify(
|
|
115
|
-
status:
|
|
114
|
+
json(i, d = 200) {
|
|
115
|
+
return new Response(JSON.stringify(i), {
|
|
116
|
+
status: d,
|
|
116
117
|
headers: { "content-type": "application/json" }
|
|
117
118
|
});
|
|
118
119
|
},
|
|
119
|
-
text(
|
|
120
|
-
return new Response(
|
|
120
|
+
text(i, d = 200) {
|
|
121
|
+
return new Response(i, { status: d });
|
|
121
122
|
},
|
|
122
|
-
html(
|
|
123
|
-
return new Response(
|
|
124
|
-
status:
|
|
123
|
+
html(i, d = 200) {
|
|
124
|
+
return new Response(i, {
|
|
125
|
+
status: d,
|
|
125
126
|
headers: { "content-type": "text/html; charset=UTF-8" }
|
|
126
127
|
});
|
|
127
128
|
},
|
|
128
|
-
body(
|
|
129
|
-
return new Response(
|
|
129
|
+
body(i, d = 200) {
|
|
130
|
+
return new Response(i, { status: d });
|
|
130
131
|
},
|
|
131
|
-
redirect(
|
|
132
|
-
return new Response(null, { status:
|
|
132
|
+
redirect(i, d = 302) {
|
|
133
|
+
return new Response(null, { status: d, headers: { location: i } });
|
|
133
134
|
},
|
|
134
|
-
header(
|
|
135
|
+
header(i, d) {
|
|
135
136
|
},
|
|
136
|
-
status(
|
|
137
|
+
status(i) {
|
|
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 = q(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 = q(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
|
|
178
|
-
const
|
|
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), w = [];
|
|
178
|
+
let o = null, n = !1;
|
|
179
|
+
const r = {
|
|
179
180
|
async *[Symbol.asyncIterator]() {
|
|
180
181
|
for (; ; ) {
|
|
181
|
-
for (;
|
|
182
|
-
yield
|
|
183
|
-
if (
|
|
184
|
-
await new Promise((
|
|
182
|
+
for (; w.length > 0; )
|
|
183
|
+
yield w.shift();
|
|
184
|
+
if (n) return;
|
|
185
|
+
await new Promise((m) => o = m), o = null;
|
|
185
186
|
}
|
|
186
187
|
}
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
},
|
|
190
|
-
|
|
191
|
-
},
|
|
192
|
-
let
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
for (const
|
|
188
|
+
}, h = (m) => {
|
|
189
|
+
n || (w.push(m), o?.());
|
|
190
|
+
}, a = () => {
|
|
191
|
+
n || (n = !0, o?.());
|
|
192
|
+
}, p = [];
|
|
193
|
+
let i = [];
|
|
194
|
+
const d = (m) => {
|
|
195
|
+
p.push(m);
|
|
196
|
+
const P = i;
|
|
197
|
+
i = [];
|
|
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 y = !1, g = !1;
|
|
205
|
+
const k = (m) => {
|
|
206
|
+
g || (typeof m == "string" || m instanceof Uint8Array ? d(m) : d(JSON.stringify(m)));
|
|
207
|
+
}, E = (m, P) => {
|
|
208
|
+
_();
|
|
209
|
+
}, C = () => {
|
|
210
|
+
y = !0;
|
|
211
|
+
}, _ = () => {
|
|
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 m = i;
|
|
220
|
+
i = [];
|
|
221
|
+
for (const P of m)
|
|
221
222
|
try {
|
|
222
|
-
|
|
223
|
+
P();
|
|
223
224
|
} catch {
|
|
224
225
|
}
|
|
225
|
-
},
|
|
226
|
-
incoming:
|
|
227
|
-
send:
|
|
228
|
-
close:
|
|
229
|
-
keepOpen:
|
|
230
|
-
abortSignal:
|
|
231
|
-
c:
|
|
226
|
+
}, b = {
|
|
227
|
+
incoming: r,
|
|
228
|
+
send: k,
|
|
229
|
+
close: E,
|
|
230
|
+
keepOpen: C,
|
|
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 (m) {
|
|
242
|
+
console.error("[velojs/testing] socket handler threw:", m);
|
|
242
243
|
}
|
|
243
|
-
|
|
244
|
-
})(),
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
},
|
|
248
|
-
clearTimeout(
|
|
244
|
+
y || _();
|
|
245
|
+
})(), x = (m) => new Promise((P, R) => {
|
|
246
|
+
const $ = setTimeout(() => {
|
|
247
|
+
i = i.filter((U) => U !== I), R(new Error(`[velojs/testing] socket.next() timed out after ${m}ms`));
|
|
248
|
+
}, m), I = () => {
|
|
249
|
+
clearTimeout($), P();
|
|
249
250
|
};
|
|
250
|
-
|
|
251
|
+
i.push(I);
|
|
251
252
|
});
|
|
252
|
-
let
|
|
253
|
+
let S = 0;
|
|
253
254
|
return {
|
|
254
|
-
send(
|
|
255
|
-
|
|
255
|
+
send(m) {
|
|
256
|
+
g || (typeof m == "string" || m instanceof Uint8Array ? h(m) : h(JSON.stringify(m)));
|
|
256
257
|
},
|
|
257
258
|
get messages() {
|
|
258
|
-
return
|
|
259
|
+
return p;
|
|
259
260
|
},
|
|
260
261
|
get closed() {
|
|
261
|
-
return
|
|
262
|
+
return g;
|
|
262
263
|
},
|
|
263
|
-
async next(
|
|
264
|
-
for (;
|
|
265
|
-
if (
|
|
264
|
+
async next(m) {
|
|
265
|
+
for (; S >= p.length; ) {
|
|
266
|
+
if (g)
|
|
266
267
|
throw new Error("[velojs/testing] socket closed before next()");
|
|
267
|
-
await
|
|
268
|
+
await x(m.timeoutMs);
|
|
268
269
|
}
|
|
269
|
-
return
|
|
270
|
+
return p[S++];
|
|
270
271
|
},
|
|
271
|
-
async nextN(
|
|
272
|
-
const
|
|
273
|
-
for (;
|
|
274
|
-
if (
|
|
275
|
-
|
|
272
|
+
async nextN(m, P) {
|
|
273
|
+
const R = Date.now() + P.timeoutMs, $ = [];
|
|
274
|
+
for (; $.length < m; ) {
|
|
275
|
+
if (S < p.length) {
|
|
276
|
+
$.push(p[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(m, P) {
|
|
291
|
+
_(), 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
|
|
307
|
-
if (typeof
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
name:
|
|
311
|
-
fn:
|
|
312
|
-
moduleId:
|
|
313
|
-
url: `/_action/${
|
|
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, w = 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 r = f.module[n];
|
|
308
|
+
if (typeof r != "function") continue;
|
|
309
|
+
const h = n.replace("action_", "");
|
|
310
|
+
s.set(r, {
|
|
311
|
+
name: h,
|
|
312
|
+
fn: r,
|
|
313
|
+
moduleId: u,
|
|
314
|
+
url: `/_action/${u}/${h}`
|
|
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" && w) {
|
|
319
|
+
const n = t.get(o);
|
|
320
|
+
n ? n.paths.push(w) : t.set(o, {
|
|
321
|
+
fn: o,
|
|
322
|
+
moduleId: u,
|
|
323
|
+
paths: [w]
|
|
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,360 +339,439 @@ 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 w = c.slice(f + 1);
|
|
386
|
+
w.startsWith(" ") && (w = w.slice(1)), u === "event" ? this.current.event = w : u === "data" ? this.current.data.push(w) : u === "id" && (this.current.id = w);
|
|
386
387
|
}
|
|
387
388
|
return t;
|
|
388
389
|
}
|
|
389
390
|
}
|
|
390
|
-
async function
|
|
391
|
-
const { response:
|
|
392
|
-
let
|
|
393
|
-
const
|
|
394
|
-
let
|
|
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 w = null, o = !1, n = null, r = 0, h = 0;
|
|
394
|
+
const a = [], p = [];
|
|
395
|
+
let i = null, d = Promise.resolve(void 0);
|
|
396
|
+
const v = (y) => {
|
|
397
|
+
for (; a.length > 0; ) {
|
|
398
|
+
const g = a.shift();
|
|
399
|
+
y ? g.reject(y) : g.reject(new Error("[velojs/testing] subscription closed before next event"));
|
|
400
|
+
}
|
|
401
|
+
for (; p.length > 0; ) {
|
|
402
|
+
const g = p.shift();
|
|
403
|
+
y ? g.reject(y) : g.reject(new Error("[velojs/testing] subscription closed before next event"));
|
|
399
404
|
}
|
|
400
405
|
};
|
|
401
|
-
if (
|
|
402
|
-
|
|
403
|
-
const
|
|
404
|
-
|
|
406
|
+
if (c >= 200 && c < 300 && s.body) {
|
|
407
|
+
i = s.body.getReader();
|
|
408
|
+
const y = new TextDecoder(), g = new re();
|
|
409
|
+
d = (async () => {
|
|
405
410
|
try {
|
|
406
411
|
for (; ; ) {
|
|
407
|
-
const { value:
|
|
408
|
-
if (
|
|
409
|
-
|
|
412
|
+
const { value: k, done: E } = await i.read();
|
|
413
|
+
if (E) {
|
|
414
|
+
o || (o = !0), v();
|
|
410
415
|
return;
|
|
411
416
|
}
|
|
412
|
-
const
|
|
413
|
-
for (const
|
|
414
|
-
|
|
417
|
+
const C = y.decode(k, { stream: !0 }), _ = g.push(C);
|
|
418
|
+
for (const b of _) {
|
|
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 || (w = 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 = p.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(), i.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 w;
|
|
457
481
|
},
|
|
458
482
|
get closed() {
|
|
459
|
-
return
|
|
483
|
+
return o;
|
|
460
484
|
},
|
|
461
|
-
async next({ timeoutMs:
|
|
462
|
-
if (
|
|
463
|
-
if (
|
|
464
|
-
const
|
|
465
|
-
return
|
|
485
|
+
async next({ timeoutMs: y }) {
|
|
486
|
+
if (n) throw n;
|
|
487
|
+
if (f.length > r) {
|
|
488
|
+
const g = f[r];
|
|
489
|
+
return r++, g;
|
|
466
490
|
}
|
|
467
|
-
if (
|
|
491
|
+
if (o)
|
|
468
492
|
throw new Error("[velojs/testing] subscription is closed");
|
|
469
|
-
return new Promise((
|
|
470
|
-
const
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
`[velojs/testing] timed out after ${
|
|
493
|
+
return new Promise((g, k) => {
|
|
494
|
+
const E = setTimeout(() => {
|
|
495
|
+
const b = a.findIndex((T) => T.resolve === C);
|
|
496
|
+
b !== -1 && a.splice(b, 1), k(new Error(
|
|
497
|
+
`[velojs/testing] timed out after ${y}ms waiting for next event`
|
|
474
498
|
));
|
|
475
|
-
},
|
|
476
|
-
clearTimeout(
|
|
477
|
-
},
|
|
478
|
-
clearTimeout(
|
|
499
|
+
}, y), C = (b) => {
|
|
500
|
+
clearTimeout(E), r++, g(b);
|
|
501
|
+
}, _ = (b) => {
|
|
502
|
+
clearTimeout(E), k(b);
|
|
479
503
|
};
|
|
480
|
-
|
|
504
|
+
a.push({ resolve: C, reject: _ });
|
|
481
505
|
});
|
|
482
506
|
},
|
|
483
|
-
async
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
const
|
|
487
|
-
|
|
507
|
+
async nextEvent({ timeoutMs: y }) {
|
|
508
|
+
if (n) throw n;
|
|
509
|
+
if (u.length > h) {
|
|
510
|
+
const g = u[h];
|
|
511
|
+
return h++, g;
|
|
512
|
+
}
|
|
513
|
+
if (o)
|
|
514
|
+
throw new Error("[velojs/testing] subscription is closed");
|
|
515
|
+
return new Promise((g, k) => {
|
|
516
|
+
const E = setTimeout(() => {
|
|
517
|
+
const b = p.findIndex((T) => T.resolve === C);
|
|
518
|
+
b !== -1 && p.splice(b, 1), k(new Error(
|
|
519
|
+
`[velojs/testing] timed out after ${y}ms waiting for next event`
|
|
520
|
+
));
|
|
521
|
+
}, y), C = (b) => {
|
|
522
|
+
clearTimeout(E), h++, g(b);
|
|
523
|
+
}, _ = (b) => {
|
|
524
|
+
clearTimeout(E), k(b);
|
|
525
|
+
};
|
|
526
|
+
p.push({ resolve: C, reject: _ });
|
|
527
|
+
});
|
|
528
|
+
},
|
|
529
|
+
async nextN(y, { timeoutMs: g }) {
|
|
530
|
+
const k = Date.now(), E = [];
|
|
531
|
+
for (let C = 0; C < y; C++) {
|
|
532
|
+
const _ = g - (Date.now() - k);
|
|
533
|
+
if (_ <= 0)
|
|
488
534
|
throw new Error(
|
|
489
|
-
`[velojs/testing] timed out after ${
|
|
535
|
+
`[velojs/testing] timed out after ${g}ms waiting for ${y} events (got ${E.length})`
|
|
490
536
|
);
|
|
491
|
-
|
|
537
|
+
E.push(await j.next({ timeoutMs: _ }));
|
|
492
538
|
}
|
|
493
|
-
return
|
|
539
|
+
return E;
|
|
494
540
|
},
|
|
495
541
|
async close() {
|
|
496
|
-
if (
|
|
542
|
+
if (i)
|
|
497
543
|
try {
|
|
498
|
-
await
|
|
544
|
+
await i.cancel();
|
|
499
545
|
} catch {
|
|
500
546
|
}
|
|
501
|
-
|
|
547
|
+
o = !0, v(), await d.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
|
+
}), w = /* @__PURE__ */ new Set();
|
|
574
|
+
u.on("connection", (a) => {
|
|
575
|
+
w.add(a), a.on("close", () => w.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, r = t && t !== "0.0.0.0" && t !== "::" ? t : "localhost";
|
|
578
|
+
let h = !1;
|
|
527
579
|
return {
|
|
528
|
-
port:
|
|
529
|
-
url: `http://${
|
|
580
|
+
port: n,
|
|
581
|
+
url: `http://${r}:${n}`,
|
|
530
582
|
async close() {
|
|
531
|
-
if (
|
|
532
|
-
|
|
533
|
-
const
|
|
534
|
-
|
|
583
|
+
if (h) return;
|
|
584
|
+
h = !0;
|
|
585
|
+
const a = new Promise((p) => {
|
|
586
|
+
u.close(() => p());
|
|
535
587
|
});
|
|
536
|
-
for (const
|
|
537
|
-
|
|
588
|
+
for (const p of w) p.destroy();
|
|
589
|
+
w.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
|
|
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", w), e.off("error", o);
|
|
597
|
+
}, w = () => {
|
|
598
|
+
u(), l();
|
|
599
|
+
}, o = (n) => {
|
|
600
|
+
u();
|
|
601
|
+
const r = n.code ? `${n.code}: ${n.message}` : n.message;
|
|
602
|
+
c(new Error(
|
|
603
|
+
`[velojs/testing] could not bind the test server on ${f} — ${r}`
|
|
552
604
|
));
|
|
553
605
|
};
|
|
554
|
-
e.once("listening",
|
|
606
|
+
e.once("listening", w), 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, r, h = {}) {
|
|
611
|
+
const a = O(r, h.query), p = new Headers(h.headers ?? {}), i = { ...h.cookies ?? {} }, d = M(i);
|
|
612
|
+
d && p.set("cookie", d);
|
|
613
|
+
let v = null;
|
|
614
|
+
if (h.body !== void 0) {
|
|
615
|
+
const k = Z(h.body);
|
|
616
|
+
v = k.body, k.contentType && !p.has("content-type") && p.set("content-type", k.contentType);
|
|
565
617
|
}
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
const
|
|
569
|
-
return await
|
|
618
|
+
const j = { method: n, headers: p };
|
|
619
|
+
v !== null && (j.body = v);
|
|
620
|
+
const y = new Request(a, j), g = await e.fetch(y);
|
|
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 w(n, r, h = {}) {
|
|
624
|
+
const a = O(r, {
|
|
625
|
+
...h.query ?? {},
|
|
626
|
+
...h.channel ? { channel: h.channel } : {}
|
|
627
|
+
}), p = new Headers(h.headers ?? {}), i = { ...h.cookies ?? {} }, d = M(i);
|
|
628
|
+
d && p.set("cookie", d);
|
|
629
|
+
const v = new Request(a, { method: n, headers: p });
|
|
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
|
|
594
|
-
...
|
|
595
|
-
body:
|
|
638
|
+
get: (n, r) => u("GET", n, r ?? {}),
|
|
639
|
+
post: (n, r) => u("POST", n, r ?? {}),
|
|
640
|
+
put: (n, r) => u("PUT", n, r ?? {}),
|
|
641
|
+
patch: (n, r) => u("PATCH", n, r ?? {}),
|
|
642
|
+
delete: (n, r) => u("DELETE", n, r ?? {}),
|
|
643
|
+
async action(n, r = {}) {
|
|
644
|
+
const h = se(t, n);
|
|
645
|
+
return await u("POST", h, {
|
|
646
|
+
...r,
|
|
647
|
+
body: r.body ?? {}
|
|
596
648
|
});
|
|
597
649
|
},
|
|
598
|
-
async loader(
|
|
599
|
-
const
|
|
600
|
-
...
|
|
601
|
-
query: { ...
|
|
650
|
+
async loader(n, r = {}) {
|
|
651
|
+
const h = oe(t, n, r.params), a = await u("GET", h, {
|
|
652
|
+
...r,
|
|
653
|
+
query: { ...r.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 p = typeof n == "function" ? t.loaders.get(n)?.moduleId : void 0, i = await a.json();
|
|
657
|
+
return p && i && typeof i == "object" && p in i ? i[p] : i;
|
|
658
|
+
},
|
|
659
|
+
async subscribe(n, r = {}) {
|
|
660
|
+
const h = typeof n == "string" ? n : n.__path ?? fe(), a = await w("GET", h, r);
|
|
661
|
+
return await J({ response: a });
|
|
606
662
|
},
|
|
607
|
-
async
|
|
608
|
-
const
|
|
609
|
-
|
|
663
|
+
async channel(n, r, h = {}) {
|
|
664
|
+
const a = typeof n == "string" ? n : n?.metadata?.moduleId;
|
|
665
|
+
a || ue(n);
|
|
666
|
+
const p = await w(
|
|
667
|
+
"GET",
|
|
668
|
+
`/_channel/${a}/${r}`,
|
|
669
|
+
h
|
|
670
|
+
);
|
|
671
|
+
return await J({
|
|
672
|
+
response: p,
|
|
673
|
+
snapshotEvents: !0,
|
|
674
|
+
channelEvents: !0
|
|
675
|
+
});
|
|
610
676
|
},
|
|
611
|
-
async socket(
|
|
612
|
-
return await
|
|
677
|
+
async socket(n, r = {}) {
|
|
678
|
+
return await te(e, n, r);
|
|
613
679
|
},
|
|
614
|
-
async sessionCookies({ user:
|
|
615
|
-
if (!
|
|
680
|
+
async sessionCookies({ user: n }) {
|
|
681
|
+
if (!l.getSessionCookie)
|
|
616
682
|
throw new Error(
|
|
617
683
|
"[velojs/testing] sessionCookies/as requires `getSessionCookie` in createTestApp options."
|
|
618
684
|
);
|
|
619
|
-
return await
|
|
685
|
+
return await l.getSessionCookie({ user: n });
|
|
620
686
|
},
|
|
621
|
-
as({ user:
|
|
622
|
-
if (!
|
|
687
|
+
as({ user: n }) {
|
|
688
|
+
if (!l.getSessionCookie)
|
|
623
689
|
throw new Error(
|
|
624
690
|
"[velojs/testing] app.as() requires `getSessionCookie` in createTestApp options."
|
|
625
691
|
);
|
|
626
|
-
let
|
|
627
|
-
const
|
|
628
|
-
const
|
|
629
|
-
...
|
|
630
|
-
cookies: { ...
|
|
692
|
+
let r = null;
|
|
693
|
+
const h = () => (r || (r = Promise.resolve(l.getSessionCookie({ user: n }))), r), a = (d) => (async (...v) => {
|
|
694
|
+
const j = await h(), [y, g] = v, k = {
|
|
695
|
+
...g ?? {},
|
|
696
|
+
cookies: { ...j, ...g?.cookies ?? {} }
|
|
631
697
|
};
|
|
632
|
-
return await
|
|
698
|
+
return await d.call(o, y, k);
|
|
699
|
+
}), p = (d) => (async (v, j, y = {}) => {
|
|
700
|
+
const g = await h();
|
|
701
|
+
return await d.call(o, v, j, {
|
|
702
|
+
...y,
|
|
703
|
+
cookies: { ...g, ...y?.cookies ?? {} }
|
|
704
|
+
});
|
|
633
705
|
});
|
|
634
706
|
return {
|
|
635
707
|
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
|
-
|
|
708
|
+
port: o.port,
|
|
709
|
+
url: o.url,
|
|
710
|
+
get: a(o.get),
|
|
711
|
+
post: a(o.post),
|
|
712
|
+
put: a(o.put),
|
|
713
|
+
patch: a(o.patch),
|
|
714
|
+
delete: a(o.delete),
|
|
715
|
+
action: a(o.action),
|
|
716
|
+
loader: a(o.loader),
|
|
717
|
+
subscribe: a(o.subscribe),
|
|
718
|
+
channel: p(o.channel),
|
|
719
|
+
socket: a(o.socket),
|
|
720
|
+
sessionCookies: o.sessionCookies,
|
|
721
|
+
as: o.as,
|
|
649
722
|
// chaining .as.as works — last wins
|
|
650
|
-
mockContext:
|
|
651
|
-
reset:
|
|
652
|
-
close:
|
|
723
|
+
mockContext: o.mockContext,
|
|
724
|
+
reset: o.reset,
|
|
725
|
+
close: o.close
|
|
653
726
|
};
|
|
654
727
|
},
|
|
655
|
-
mockContext(
|
|
656
|
-
return
|
|
728
|
+
mockContext(n = {}) {
|
|
729
|
+
return D(n);
|
|
657
730
|
},
|
|
658
731
|
async reset() {
|
|
659
|
-
for (const
|
|
732
|
+
for (const n of W())
|
|
660
733
|
try {
|
|
661
|
-
|
|
662
|
-
} catch (
|
|
663
|
-
console.error("[velojs/testing] stream.__reset failed:",
|
|
734
|
+
n.__reset();
|
|
735
|
+
} catch (r) {
|
|
736
|
+
console.error("[velojs/testing] stream.__reset failed:", r);
|
|
664
737
|
}
|
|
738
|
+
z();
|
|
665
739
|
},
|
|
666
740
|
async close() {
|
|
667
|
-
await
|
|
668
|
-
for (const
|
|
741
|
+
await o.reset(), F(e);
|
|
742
|
+
for (const n of s.disposers)
|
|
669
743
|
try {
|
|
670
|
-
|
|
671
|
-
} catch (
|
|
672
|
-
console.error("[velojs/testing] disposer failed:",
|
|
744
|
+
n();
|
|
745
|
+
} catch (r) {
|
|
746
|
+
console.error("[velojs/testing] disposer failed:", r);
|
|
673
747
|
}
|
|
674
|
-
|
|
748
|
+
s.disposers.clear(), await f?.close();
|
|
675
749
|
}
|
|
676
750
|
};
|
|
677
|
-
return
|
|
751
|
+
return o;
|
|
678
752
|
}
|
|
679
|
-
async function
|
|
753
|
+
async function le(e) {
|
|
680
754
|
return {
|
|
681
755
|
status: e.status,
|
|
682
|
-
headers:
|
|
683
|
-
cookies:
|
|
756
|
+
headers: Y(e.headers),
|
|
757
|
+
cookies: X(e.headers),
|
|
684
758
|
json: () => e.clone().json(),
|
|
685
759
|
text: () => e.clone().text(),
|
|
686
760
|
blob: () => e.clone().blob(),
|
|
687
761
|
raw: e
|
|
688
762
|
};
|
|
689
763
|
}
|
|
690
|
-
function
|
|
764
|
+
function ue(e) {
|
|
765
|
+
const s = typeof e == "string" ? e : "(a module without metadata)";
|
|
766
|
+
throw new Error(
|
|
767
|
+
`[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.`
|
|
768
|
+
);
|
|
769
|
+
}
|
|
770
|
+
function fe(e) {
|
|
691
771
|
throw new Error(
|
|
692
772
|
"[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
773
|
);
|
|
694
774
|
}
|
|
695
775
|
export {
|
|
696
|
-
|
|
776
|
+
ge as createTestApp
|
|
697
777
|
};
|