prunelle 0.0.0-stage → 0.7.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/LICENSE +21 -0
- package/llms.txt +245 -0
- package/package.json +62 -4
- package/src/a11y/declaration.ts +373 -0
- package/src/a11y/index.ts +477 -0
- package/src/a11y/rgaa-map.ts +230 -0
- package/src/ambient.d.ts +6 -0
- package/src/attrs.ts +43 -0
- package/src/build/bundle.ts +661 -0
- package/src/build/byte-size.ts +11 -0
- package/src/build/carry.ts +57 -0
- package/src/build/client-entries.ts +107 -0
- package/src/build/client-plugin.ts +175 -0
- package/src/build/client-prune.ts +168 -0
- package/src/build/compile.ts +130 -0
- package/src/build/ecoindex.ts +238 -0
- package/src/build/files.ts +171 -0
- package/src/build/first-load.ts +235 -0
- package/src/build/graph.ts +237 -0
- package/src/build/index.ts +678 -0
- package/src/build/is-inside.ts +12 -0
- package/src/build/island-promote.ts +311 -0
- package/src/build/islands.ts +452 -0
- package/src/build/manifest.ts +204 -0
- package/src/build/output.ts +81 -0
- package/src/build/plugin-host.ts +294 -0
- package/src/build/precompress.ts +139 -0
- package/src/build/prerender.ts +288 -0
- package/src/build/reach.ts +200 -0
- package/src/build/render-rules.ts +205 -0
- package/src/build/report.ts +290 -0
- package/src/build/resolve.ts +52 -0
- package/src/build/routes.ts +342 -0
- package/src/build/server-entry.ts +38 -0
- package/src/build/static-headers.ts +112 -0
- package/src/build/static.ts +209 -0
- package/src/build/status-pages.ts +127 -0
- package/src/build/style-bundles.ts +526 -0
- package/src/cli/check-forms.ts +636 -0
- package/src/cli/check-imports.ts +31 -0
- package/src/cli/check-links.ts +632 -0
- package/src/cli/check-security.ts +64 -0
- package/src/cli/check.ts +409 -0
- package/src/cli/commands.ts +372 -0
- package/src/cli/docs.ts +403 -0
- package/src/cli/index.ts +70 -0
- package/src/cli/inspect.ts +406 -0
- package/src/cli/mcp-tools.ts +492 -0
- package/src/cli/mcp.ts +205 -0
- package/src/cli/new.ts +52 -0
- package/src/cli/render.ts +416 -0
- package/src/cli/upgrade-names.ts +209 -0
- package/src/cli/upgrade.ts +367 -0
- package/src/compiler/analyze.ts +651 -0
- package/src/compiler/ast.ts +82 -0
- package/src/compiler/browser-globals.ts +250 -0
- package/src/compiler/cacheability-private.ts +566 -0
- package/src/compiler/cacheability.ts +335 -0
- package/src/compiler/compliance-eco.ts +71 -0
- package/src/compiler/compliance-rgaa.ts +614 -0
- package/src/compiler/compliance-urls.ts +148 -0
- package/src/compiler/compliance.ts +653 -0
- package/src/compiler/data-keys.ts +302 -0
- package/src/compiler/dev-source.ts +87 -0
- package/src/compiler/dom-attrs.ts +452 -0
- package/src/compiler/dom.ts +641 -0
- package/src/compiler/emit.ts +131 -0
- package/src/compiler/expr-context.ts +587 -0
- package/src/compiler/foreign-imports.ts +88 -0
- package/src/compiler/index.ts +8 -0
- package/src/compiler/interactivity.ts +366 -0
- package/src/compiler/mistakes.ts +520 -0
- package/src/compiler/node-env.ts +50 -0
- package/src/compiler/patch.ts +97 -0
- package/src/compiler/props-body.ts +60 -0
- package/src/compiler/props.ts +511 -0
- package/src/compiler/scope.ts +635 -0
- package/src/compiler/server-only.ts +365 -0
- package/src/compiler/shared.ts +397 -0
- package/src/compiler/signal-reads.ts +246 -0
- package/src/compiler/slots.ts +227 -0
- package/src/compiler/spread-handlers.ts +295 -0
- package/src/compiler/ssr-helpers.ts +555 -0
- package/src/compiler/ssr-island.ts +90 -0
- package/src/compiler/ssr-prunelle-tags.ts +69 -0
- package/src/compiler/ssr.ts +525 -0
- package/src/context.ts +199 -0
- package/src/dev/child.ts +30 -0
- package/src/dev/error-log.ts +177 -0
- package/src/dev/host-check.ts +32 -0
- package/src/dev/index.ts +268 -0
- package/src/dev/modules.ts +68 -0
- package/src/dev/open-editor.ts +228 -0
- package/src/dev/protocol.ts +24 -0
- package/src/dev/queue.ts +79 -0
- package/src/dev/reload.ts +159 -0
- package/src/dev/supervisor.ts +212 -0
- package/src/dev/watchers.ts +276 -0
- package/src/dom/action.ts +187 -0
- package/src/dom/attrs.ts +84 -0
- package/src/dom/claim.ts +120 -0
- package/src/dom/extras.ts +579 -0
- package/src/dom/index.ts +329 -0
- package/src/dom/island.ts +318 -0
- package/src/dom/loop.ts +484 -0
- package/src/dom/revive.ts +36 -0
- package/src/eco/declaration.ts +328 -0
- package/src/eco/index.ts +69 -0
- package/src/index.ts +22 -0
- package/src/jsx-runtime.ts +566 -0
- package/src/plugins/config.ts +92 -0
- package/src/plugins/context.ts +109 -0
- package/src/plugins/index.ts +14 -0
- package/src/plugins/load.ts +90 -0
- package/src/plugins/order.ts +148 -0
- package/src/plugins/public.ts +15 -0
- package/src/plugins/requires.ts +47 -0
- package/src/plugins/services.ts +119 -0
- package/src/plugins/types.ts +278 -0
- package/src/reactivity/graph.ts +259 -0
- package/src/reactivity/index.ts +541 -0
- package/src/reactivity/selector.ts +78 -0
- package/src/reactivity/store.ts +252 -0
- package/src/server/action-flash.ts +158 -0
- package/src/server/action-protect.ts +199 -0
- package/src/server/action-registry.ts +78 -0
- package/src/server/action.ts +511 -0
- package/src/server/app-entry.ts +23 -0
- package/src/server/app-secret.ts +63 -0
- package/src/server/assets.ts +168 -0
- package/src/server/compress.ts +646 -0
- package/src/server/consent.ts +290 -0
- package/src/server/cookies.ts +153 -0
- package/src/server/document.ts +286 -0
- package/src/server/env.ts +47 -0
- package/src/server/errors.ts +396 -0
- package/src/server/form-schema.ts +337 -0
- package/src/server/health.ts +275 -0
- package/src/server/http.ts +588 -0
- package/src/server/index.ts +615 -0
- package/src/server/lifecycle.ts +75 -0
- package/src/server/loader.ts +131 -0
- package/src/server/page.ts +122 -0
- package/src/server/param-matchers.ts +112 -0
- package/src/server/plugin-host.ts +267 -0
- package/src/server/prerendered.ts +71 -0
- package/src/server/public.ts +20 -0
- package/src/server/rate-limit.ts +199 -0
- package/src/server/region.ts +96 -0
- package/src/server/request-body.ts +27 -0
- package/src/server/request-path.ts +73 -0
- package/src/server/request-scope.ts +22 -0
- package/src/server/route-cache.ts +541 -0
- package/src/server/route-table.ts +424 -0
- package/src/server/router.ts +261 -0
- package/src/server/routing.ts +388 -0
- package/src/server/sanitize-html.ts +309 -0
- package/src/server/security.ts +550 -0
- package/src/server/serve-handlers.ts +93 -0
- package/src/server/served-file.ts +128 -0
- package/src/server/standard-schema.ts +104 -0
- package/src/server/start.ts +143 -0
- package/src/server/static-dir.ts +246 -0
- package/src/server/stream.ts +233 -0
- package/src/ssr/consent-banner.ts +58 -0
- package/src/ssr/context.ts +399 -0
- package/src/ssr/index.ts +624 -0
- package/src/ssr/navigation.ts +96 -0
- package/src/ssr/region.ts +192 -0
- package/src/style.ts +96 -0
- package/src/test/browser.ts +201 -0
- package/src/test/index.ts +262 -0
- package/src/ts-plugin/diagnostics.ts +505 -0
- package/src/ts-plugin/fixes.ts +364 -0
- package/src/ts-plugin/index.ts +194 -0
- package/src/unrenderable.ts +35 -0
- package/templates/_shared/AGENTS.md +10 -0
- package/templates/_shared/CLAUDE.md +1 -0
- package/templates/_shared/gitignore +8 -0
- package/templates/_shared/mcp.json +11 -0
- package/templates/_shared/public/robots.txt +2 -0
- package/templates/_shared/src/routes/legal.tsx +22 -0
- package/templates/_shared/tsconfig.json +25 -0
- package/templates/app/.env.example +8 -0
- package/templates/app/package.json +22 -0
- package/templates/app/prunelle.config.ts +13 -0
- package/templates/app/src/auth.ts +12 -0
- package/templates/app/src/mail.ts +4 -0
- package/templates/app/src/routes/_layout.tsx +40 -0
- package/templates/app/src/routes/dashboard/_middleware.ts +3 -0
- package/templates/app/src/routes/dashboard/index.tsx +47 -0
- package/templates/app/src/routes/index.tsx +15 -0
- package/templates/app/src/routes/login.tsx +53 -0
- package/templates/app/src/routes/privacy.tsx +25 -0
- package/templates/app/src/styles/app.css +14 -0
- package/templates/app/tests/app.test.ts +73 -0
- package/templates/blog/content/posts/welcome.md +9 -0
- package/templates/blog/package.json +22 -0
- package/templates/blog/prunelle.config.ts +23 -0
- package/templates/blog/src/posts.ts +26 -0
- package/templates/blog/src/routes/_layout.tsx +25 -0
- package/templates/blog/src/routes/blog/[slug].tsx +31 -0
- package/templates/blog/src/routes/index.tsx +33 -0
- package/templates/blog/src/styles/app.css +15 -0
- package/templates/fullstack/package.json +19 -0
- package/templates/fullstack/prunelle.config.ts +6 -0
- package/templates/fullstack/src/actions/greet.ts +19 -0
- package/templates/fullstack/src/components/Counter.tsx +10 -0
- package/templates/fullstack/src/components/GreetForm.tsx +28 -0
- package/templates/fullstack/src/routes/_layout.tsx +18 -0
- package/templates/fullstack/src/routes/api/health.ts +5 -0
- package/templates/fullstack/src/routes/index.tsx +13 -0
- package/templates/fullstack/src/styles/app.css +39 -0
- package/templates/fullstack/tests/app.test.ts +37 -0
- package/templates/minimal/package.json +19 -0
- package/templates/minimal/prunelle.config.ts +6 -0
- package/templates/minimal/src/components/Counter.tsx +10 -0
- package/templates/minimal/src/routes/_layout.tsx +18 -0
- package/templates/minimal/src/routes/index.tsx +11 -0
- package/templates/minimal/src/styles/app.css +32 -0
- package/ts-plugin.cjs +4277 -0
- package/README.md +0 -3
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
// prunelle/test: in-process testing for pages, middleware, cookies, and actions — zero port binding.
|
|
2
|
+
|
|
3
|
+
import type { BuildManifest, BuildOptions } from '../build/index'
|
|
4
|
+
import type { PrunelleApp, ServerAction, ServerRuntimeConfig } from '../server/index'
|
|
5
|
+
import { existsSync, readdirSync, rmSync } from 'node:fs'
|
|
6
|
+
import { dirname, join, resolve } from 'node:path'
|
|
7
|
+
import { build } from '../build/index'
|
|
8
|
+
import { relPosix } from '../build/files'
|
|
9
|
+
import { processSuffix, removeDeadProcessDirs } from '../build/output'
|
|
10
|
+
import { ensureCacheGitignore } from '../build/precompress'
|
|
11
|
+
import { resolveServerConfig } from '../server/index'
|
|
12
|
+
import { FORM_TIMESTAMP_FIELD, honeypotFieldName, signFormTimestamp } from '../server/action-protect'
|
|
13
|
+
import { startBuiltApp } from '../server/loader'
|
|
14
|
+
|
|
15
|
+
const TEST_DIR_PREFIX = 'test-'
|
|
16
|
+
const ABSOLUTE_URL_RE = /^https?:\/\//i
|
|
17
|
+
const INTEGER_RE = /^-?\d+$/
|
|
18
|
+
|
|
19
|
+
function safeDecodeCookieValue(val: string): string {
|
|
20
|
+
try {
|
|
21
|
+
return decodeURIComponent(val)
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return val
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isExpiredSetCookie(raw: string): boolean {
|
|
29
|
+
const parts = raw.split(';')
|
|
30
|
+
let hasMaxAge = false
|
|
31
|
+
let maxAgeExpired = false
|
|
32
|
+
let expiresExpired = false
|
|
33
|
+
for (let i = 1; i < parts.length; i++) {
|
|
34
|
+
const seg = parts[i]!.trim()
|
|
35
|
+
const eq = seg.indexOf('=')
|
|
36
|
+
if (eq <= 0)
|
|
37
|
+
continue
|
|
38
|
+
const attrName = seg.slice(0, eq).trim().toLowerCase()
|
|
39
|
+
const attrVal = seg.slice(eq + 1).trim()
|
|
40
|
+
if (attrName === 'max-age' && INTEGER_RE.test(attrVal)) {
|
|
41
|
+
hasMaxAge = true
|
|
42
|
+
maxAgeExpired = Number(attrVal) <= 0
|
|
43
|
+
}
|
|
44
|
+
else if (attrName === 'expires') {
|
|
45
|
+
const ts = Date.parse(attrVal)
|
|
46
|
+
if (Number.isFinite(ts))
|
|
47
|
+
expiresExpired = ts <= Date.now()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return hasMaxAge ? maxAgeExpired : expiresExpired
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function defaultOriginFor(target: string): string {
|
|
54
|
+
if (ABSOLUTE_URL_RE.test(target)) {
|
|
55
|
+
try {
|
|
56
|
+
return new URL(target).origin
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return 'http://localhost'
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return 'http://localhost'
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface TestAppOptions extends Omit<BuildOptions, 'compile' | 'static'>, Partial<ServerRuntimeConfig> {
|
|
66
|
+
prebuilt?: boolean | undefined
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface TestApp {
|
|
70
|
+
readonly app: PrunelleApp
|
|
71
|
+
readonly manifest: BuildManifest | undefined
|
|
72
|
+
readonly cookies: Map<string, string>
|
|
73
|
+
/** The unhandled route, action and plugin errors seen since the app started, as `route GET /path: message`; a response that is a 500 has one here. */
|
|
74
|
+
readonly errors: string[]
|
|
75
|
+
fetch(pathOrReq: string | Request, init?: RequestInit): Promise<Response>
|
|
76
|
+
get(path: string, headers?: HeadersInit): Promise<Response>
|
|
77
|
+
post(path: string, body?: unknown, headers?: HeadersInit): Promise<Response>
|
|
78
|
+
/** The app's own bundled copy of a route, layout, middleware, action file or `prunelle.config.ts`, by path from the root. */
|
|
79
|
+
import(path: string): Promise<Record<string, unknown>>
|
|
80
|
+
/** Posts `fields` as a form to an action, given as one from `import()` or as its URL. */
|
|
81
|
+
submit(action: ServerAction<never, unknown> | string, fields: Record<string, string>, headers?: HeadersInit): Promise<Response>
|
|
82
|
+
clearCookies(): void
|
|
83
|
+
/** Runs plugin shutdown hooks and cleans up app resources (idempotent). */
|
|
84
|
+
dispose(): Promise<void>
|
|
85
|
+
[Symbol.asyncDispose](): Promise<void>
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The folder of the latest testApp() build of each app root in this process, which `prebuilt: true` reuses. */
|
|
89
|
+
const latestOutDirs = new Map<string, string>()
|
|
90
|
+
const ownOutDirs: string[] = []
|
|
91
|
+
|
|
92
|
+
/** A folder under `.prunelle-cache/` for one testApp() build, removed when the process exits, so tests never replace the app's deployable dist/. */
|
|
93
|
+
function ownOutDir(root: string): string {
|
|
94
|
+
const cacheDir = join(root, '.prunelle-cache')
|
|
95
|
+
removeDeadProcessDirs(cacheDir, TEST_DIR_PREFIX)
|
|
96
|
+
ensureCacheGitignore(cacheDir)
|
|
97
|
+
if (ownOutDirs.length === 0) {
|
|
98
|
+
process.once('exit', () => {
|
|
99
|
+
for (const dir of ownOutDirs) {
|
|
100
|
+
rmSync(dir, { recursive: true, force: true })
|
|
101
|
+
const parent = dirname(dir)
|
|
102
|
+
if (!existsSync(parent))
|
|
103
|
+
continue
|
|
104
|
+
const remaining = readdirSync(parent)
|
|
105
|
+
if (remaining.length === 0 || (remaining.length === 1 && remaining[0] === '.gitignore'))
|
|
106
|
+
rmSync(parent, { recursive: true, force: true })
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
const dir = join(cacheDir, `${TEST_DIR_PREFIX}${processSuffix()}`)
|
|
111
|
+
ownOutDirs.push(dir)
|
|
112
|
+
latestOutDirs.set(root, dir)
|
|
113
|
+
return dir
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export async function testApp(options: TestAppOptions): Promise<TestApp> {
|
|
117
|
+
const root = resolve(options.root)
|
|
118
|
+
const outDir = options.outDir ?? (options.prebuilt ? latestOutDirs.get(root) : ownOutDir(root))
|
|
119
|
+
const manifest = options.prebuilt ? undefined : await build({
|
|
120
|
+
root: options.root,
|
|
121
|
+
routesDir: options.routesDir,
|
|
122
|
+
outDir,
|
|
123
|
+
publicDir: options.publicDir,
|
|
124
|
+
minify: options.minify ?? false,
|
|
125
|
+
assetPrefix: options.assetPrefix,
|
|
126
|
+
site: options.site,
|
|
127
|
+
plugins: options.plugins,
|
|
128
|
+
cache: options.cache,
|
|
129
|
+
analyze: options.analyze,
|
|
130
|
+
analyzeJson: options.analyzeJson,
|
|
131
|
+
onAnalyze: options.onAnalyze,
|
|
132
|
+
maxJs: options.maxJs,
|
|
133
|
+
prerender: options.prerender,
|
|
134
|
+
autoPrerender: options.autoPrerender,
|
|
135
|
+
copyPublic: options.copyPublic,
|
|
136
|
+
dev: options.dev,
|
|
137
|
+
nodeEnv: options.nodeEnv,
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
const errors: string[] = []
|
|
141
|
+
const { app, entry } = await startBuiltApp({
|
|
142
|
+
root: options.root,
|
|
143
|
+
outDir,
|
|
144
|
+
dev: options.dev,
|
|
145
|
+
nodeEnv: options.nodeEnv,
|
|
146
|
+
...resolveServerConfig(undefined, options),
|
|
147
|
+
errorSink: ({ error, request, source }) => {
|
|
148
|
+
errors.push(`${source} ${request.method} ${new URL(request.url).pathname}: ${error instanceof Error ? error.message : String(error)}`)
|
|
149
|
+
},
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
const cookies = new Map<string, string>()
|
|
153
|
+
|
|
154
|
+
function cookieHeader(): string | undefined {
|
|
155
|
+
if (cookies.size === 0)
|
|
156
|
+
return undefined
|
|
157
|
+
return [...cookies.entries()].map(([k, v]) => `${k}=${encodeURIComponent(v)}`).join('; ')
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function storeSetCookies(res: Response): void {
|
|
161
|
+
const list = res.headers.getSetCookie?.() ?? []
|
|
162
|
+
for (const raw of list) {
|
|
163
|
+
const first = raw.split(';')[0] ?? ''
|
|
164
|
+
const eq = first.indexOf('=')
|
|
165
|
+
if (eq <= 0)
|
|
166
|
+
continue
|
|
167
|
+
const name = first.slice(0, eq).trim()
|
|
168
|
+
const val = first.slice(eq + 1).trim()
|
|
169
|
+
if (isExpiredSetCookie(raw) || val === '')
|
|
170
|
+
cookies.delete(name)
|
|
171
|
+
else
|
|
172
|
+
cookies.set(name, safeDecodeCookieValue(val))
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function doFetch(pathOrReq: string | Request, init?: RequestInit): Promise<Response> {
|
|
177
|
+
const req = typeof pathOrReq === 'string'
|
|
178
|
+
? new Request(ABSOLUTE_URL_RE.test(pathOrReq) ? pathOrReq : `http://localhost${pathOrReq}`, init)
|
|
179
|
+
: (init !== undefined ? new Request(pathOrReq, init) : pathOrReq)
|
|
180
|
+
|
|
181
|
+
const existing = cookieHeader()
|
|
182
|
+
let withCookies = req
|
|
183
|
+
if (existing !== undefined && !req.headers.has('cookie')) {
|
|
184
|
+
const headers = new Headers(req.headers)
|
|
185
|
+
headers.set('cookie', existing)
|
|
186
|
+
withCookies = new Request(req, { headers })
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const res = await app.handle(withCookies)
|
|
190
|
+
storeSetCookies(res)
|
|
191
|
+
return res
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
let disposed = false
|
|
195
|
+
async function dispose(): Promise<void> {
|
|
196
|
+
if (disposed)
|
|
197
|
+
return
|
|
198
|
+
disposed = true
|
|
199
|
+
await app.dispose?.()
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
app,
|
|
204
|
+
manifest,
|
|
205
|
+
cookies,
|
|
206
|
+
errors,
|
|
207
|
+
fetch: doFetch,
|
|
208
|
+
get(path, headers) {
|
|
209
|
+
return doFetch(path, headers !== undefined ? { method: 'GET', headers } : { method: 'GET' })
|
|
210
|
+
},
|
|
211
|
+
post(path, body, headers) {
|
|
212
|
+
const h = new Headers(headers)
|
|
213
|
+
if (!h.has('origin'))
|
|
214
|
+
h.set('origin', defaultOriginFor(path))
|
|
215
|
+
if (body instanceof FormData)
|
|
216
|
+
return doFetch(path, { method: 'POST', body, headers: h })
|
|
217
|
+
if (!h.has('content-type'))
|
|
218
|
+
h.set('content-type', 'application/json')
|
|
219
|
+
if (!h.has('accept'))
|
|
220
|
+
h.set('accept', 'application/json')
|
|
221
|
+
return doFetch(path, {
|
|
222
|
+
method: 'POST',
|
|
223
|
+
body: body === undefined ? '{}' : JSON.stringify(body),
|
|
224
|
+
headers: h,
|
|
225
|
+
})
|
|
226
|
+
},
|
|
227
|
+
async import(path) {
|
|
228
|
+
const source = relPosix(options.root, resolve(options.root, path))
|
|
229
|
+
const mod = entry?.sources[source]
|
|
230
|
+
if (mod === undefined)
|
|
231
|
+
throw new Error(`prunelle: testApp().import('${path}') found no bundled module. Only routes, layouts, middlewares, action files and prunelle.config.ts are bundled entries; reach ${source} through one of them.`)
|
|
232
|
+
return mod
|
|
233
|
+
},
|
|
234
|
+
submit(action, fields, headers) {
|
|
235
|
+
const actionUrl = typeof action === 'string' ? action : action.url
|
|
236
|
+
if (actionUrl === '')
|
|
237
|
+
throw new Error('prunelle: testApp().submit() got an action with no URL. Pass one from `await app.import(path)`, not one the test file imported itself.')
|
|
238
|
+
const fd = new FormData()
|
|
239
|
+
for (const [k, v] of Object.entries(fields))
|
|
240
|
+
fd.append(k, v)
|
|
241
|
+
if (typeof action !== 'string' && action.protect !== undefined) {
|
|
242
|
+
const hp = honeypotFieldName(action.protect)
|
|
243
|
+
if (hp !== undefined && !Object.hasOwn(fields, hp))
|
|
244
|
+
fd.append(hp, '')
|
|
245
|
+
if (action.protect.minTime !== undefined && !Object.hasOwn(fields, FORM_TIMESTAMP_FIELD))
|
|
246
|
+
fd.append(FORM_TIMESTAMP_FIELD, signFormTimestamp(Date.now() - Math.max(0, action.protect.minTime) - 1000, actionUrl))
|
|
247
|
+
}
|
|
248
|
+
const h = new Headers(headers)
|
|
249
|
+
if (!h.has('origin'))
|
|
250
|
+
h.set('origin', defaultOriginFor(actionUrl))
|
|
251
|
+
return doFetch(actionUrl, { method: 'POST', body: fd, headers: h })
|
|
252
|
+
},
|
|
253
|
+
clearCookies() {
|
|
254
|
+
cookies.clear()
|
|
255
|
+
},
|
|
256
|
+
dispose,
|
|
257
|
+
[Symbol.asyncDispose]: dispose,
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export { testBrowser } from './browser'
|
|
262
|
+
export type { BrowserPage, BrowserTest, BrowserTestOptions } from './browser'
|