prunelle 0.1.1 → 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 +137 -40
- package/package.json +11 -2
- package/src/a11y/declaration.ts +373 -0
- package/src/a11y/index.ts +477 -0
- package/src/a11y/rgaa-map.ts +230 -0
- package/src/attrs.ts +11 -3
- package/src/build/bundle.ts +89 -41
- package/src/build/byte-size.ts +11 -0
- package/src/build/client-entries.ts +3 -2
- package/src/build/client-plugin.ts +11 -5
- package/src/build/client-prune.ts +56 -6
- package/src/build/compile.ts +13 -10
- package/src/build/ecoindex.ts +238 -0
- package/src/build/files.ts +15 -0
- package/src/build/first-load.ts +85 -14
- package/src/build/graph.ts +29 -39
- package/src/build/index.ts +225 -122
- package/src/build/island-promote.ts +311 -0
- package/src/build/islands.ts +14 -203
- package/src/build/manifest.ts +56 -116
- package/src/build/output.ts +3 -6
- package/src/build/plugin-host.ts +115 -41
- package/src/build/precompress.ts +16 -3
- package/src/build/prerender.ts +177 -39
- package/src/build/reach.ts +200 -0
- package/src/build/render-rules.ts +2 -2
- package/src/build/report.ts +48 -5
- package/src/build/resolve.ts +8 -6
- package/src/build/routes.ts +175 -10
- package/src/build/static-headers.ts +112 -0
- package/src/build/static.ts +139 -39
- 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 +101 -26
- package/src/cli/commands.ts +120 -11
- package/src/cli/docs.ts +403 -0
- package/src/cli/inspect.ts +105 -15
- package/src/cli/mcp-tools.ts +492 -0
- package/src/cli/mcp.ts +205 -0
- package/src/cli/new.ts +16 -5
- package/src/cli/render.ts +416 -0
- package/src/cli/upgrade-names.ts +73 -13
- package/src/cli/upgrade.ts +156 -22
- package/src/compiler/analyze.ts +87 -54
- package/src/compiler/browser-globals.ts +140 -17
- 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 +407 -352
- package/src/compiler/data-keys.ts +199 -192
- package/src/compiler/dev-source.ts +87 -0
- package/src/compiler/dom-attrs.ts +138 -65
- package/src/compiler/dom.ts +517 -442
- package/src/compiler/expr-context.ts +260 -81
- package/src/compiler/foreign-imports.ts +88 -0
- package/src/compiler/mistakes.ts +23 -2
- package/src/compiler/props-body.ts +60 -0
- package/src/compiler/props.ts +87 -36
- package/src/compiler/scope.ts +400 -333
- package/src/compiler/server-only.ts +190 -151
- package/src/compiler/shared.ts +42 -14
- package/src/compiler/signal-reads.ts +6 -2
- package/src/compiler/spread-handlers.ts +295 -0
- package/src/compiler/ssr-prunelle-tags.ts +27 -14
- package/src/compiler/ssr.ts +220 -89
- package/src/context.ts +34 -0
- package/src/dev/error-log.ts +177 -0
- package/src/dev/host-check.ts +32 -0
- package/src/dev/index.ts +94 -34
- package/src/dev/open-editor.ts +228 -0
- package/src/dev/protocol.ts +3 -0
- package/src/dev/reload.ts +5 -3
- package/src/dev/supervisor.ts +50 -25
- package/src/dev/watchers.ts +74 -13
- package/src/dom/action.ts +47 -21
- package/src/dom/attrs.ts +15 -3
- package/src/dom/extras.ts +57 -40
- package/src/dom/index.ts +54 -14
- package/src/dom/island.ts +102 -68
- package/src/dom/loop.ts +66 -32
- package/src/eco/declaration.ts +328 -0
- package/src/eco/index.ts +69 -0
- package/src/index.ts +2 -2
- package/src/jsx-runtime.ts +2 -2
- package/src/plugins/config.ts +18 -12
- package/src/plugins/context.ts +44 -1
- package/src/plugins/index.ts +2 -2
- package/src/plugins/load.ts +30 -10
- package/src/plugins/order.ts +38 -1
- package/src/plugins/public.ts +6 -3
- package/src/plugins/services.ts +84 -0
- package/src/plugins/types.ts +51 -2
- package/src/reactivity/graph.ts +10 -0
- package/src/reactivity/index.ts +24 -16
- package/src/reactivity/selector.ts +31 -4
- package/src/reactivity/store.ts +64 -20
- package/src/server/action-flash.ts +158 -0
- package/src/server/action-protect.ts +199 -0
- package/src/server/action-registry.ts +1 -1
- package/src/server/action.ts +188 -152
- package/src/server/app-secret.ts +63 -0
- package/src/server/assets.ts +34 -2
- package/src/server/compress.ts +96 -10
- package/src/server/consent.ts +59 -22
- package/src/server/cookies.ts +16 -2
- package/src/server/document.ts +25 -10
- package/src/server/env.ts +14 -0
- package/src/server/errors.ts +308 -65
- package/src/server/form-schema.ts +337 -0
- package/src/server/health.ts +275 -0
- package/src/server/http.ts +186 -39
- package/src/server/index.ts +272 -273
- package/src/server/loader.ts +15 -2
- package/src/server/page.ts +15 -0
- package/src/server/param-matchers.ts +112 -0
- package/src/server/plugin-host.ts +125 -88
- package/src/server/public.ts +6 -5
- package/src/server/rate-limit.ts +102 -36
- package/src/server/request-body.ts +1 -1
- package/src/server/route-cache.ts +541 -0
- package/src/server/route-table.ts +356 -11
- package/src/server/router.ts +125 -40
- package/src/server/routing.ts +112 -63
- package/src/server/sanitize-html.ts +309 -0
- package/src/server/security.ts +279 -52
- package/src/server/serve-handlers.ts +31 -7
- package/src/server/standard-schema.ts +17 -0
- package/src/server/start.ts +60 -16
- package/src/server/static-dir.ts +91 -12
- package/src/server/stream.ts +68 -27
- package/src/ssr/consent-banner.ts +58 -0
- package/src/ssr/context.ts +106 -8
- package/src/ssr/index.ts +151 -4
- package/src/ssr/navigation.ts +2 -2
- package/src/ssr/region.ts +40 -19
- package/src/style.ts +64 -1
- package/src/test/browser.ts +28 -13
- package/src/test/index.ts +97 -12
- 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/templates/_shared/AGENTS.md +2 -2
- package/templates/_shared/gitignore +5 -0
- package/templates/_shared/mcp.json +11 -0
- package/templates/_shared/src/routes/legal.tsx +15 -1
- package/templates/_shared/tsconfig.json +5 -0
- package/templates/app/.env.example +4 -0
- package/templates/app/package.json +2 -1
- package/templates/app/prunelle.config.ts +2 -0
- package/templates/app/src/auth.ts +4 -6
- package/templates/app/src/mail.ts +4 -0
- package/templates/app/src/routes/_layout.tsx +9 -1
- package/templates/app/src/routes/dashboard/index.tsx +42 -8
- package/templates/app/src/routes/login.tsx +49 -30
- package/templates/app/src/routes/privacy.tsx +25 -0
- package/templates/app/src/styles/app.css +8 -1
- package/templates/app/tests/app.test.ts +44 -3
- package/templates/blog/package.json +1 -1
- package/templates/blog/prunelle.config.ts +1 -1
- package/templates/blog/src/routes/_layout.tsx +6 -1
- package/templates/blog/src/routes/index.tsx +5 -1
- package/templates/blog/src/styles/app.css +6 -1
- package/templates/fullstack/package.json +1 -1
- package/templates/fullstack/src/components/GreetForm.tsx +2 -1
- package/templates/fullstack/src/routes/_layout.tsx +4 -0
- package/templates/fullstack/src/styles/app.css +11 -1
- package/templates/minimal/package.json +1 -1
- package/templates/minimal/src/routes/_layout.tsx +4 -0
- package/templates/minimal/src/styles/app.css +11 -1
- package/ts-plugin.cjs +4277 -0
package/src/test/browser.ts
CHANGED
|
@@ -23,6 +23,8 @@ export interface BrowserPage {
|
|
|
23
23
|
/** Moves the pointer over the first element matching `selector`, as a visitor hovering a link does. */
|
|
24
24
|
hover(selector: string): Promise<void>
|
|
25
25
|
fill(selector: string, value: string): Promise<void>
|
|
26
|
+
/** Presses a key (`'Escape'`, `'ArrowRight'`, `'Tab'`) through the browser's keyboard input pipeline. */
|
|
27
|
+
press(key: string): Promise<void>
|
|
26
28
|
/** The text content of the first element matching `selector`. */
|
|
27
29
|
text(selector: string): Promise<string>
|
|
28
30
|
close(): Promise<void>
|
|
@@ -43,6 +45,7 @@ const DEFAULT_TIMEOUT_MS = 10_000
|
|
|
43
45
|
|
|
44
46
|
// The few playwright-core types used here, so an app's typecheck never needs playwright-core installed.
|
|
45
47
|
interface Page {
|
|
48
|
+
url(): string
|
|
46
49
|
on(event: 'pageerror', listener: (error: Error) => void): void
|
|
47
50
|
on(event: 'response', listener: (response: { status: () => number, url: () => string }) => void): void
|
|
48
51
|
on(event: 'console', listener: (message: { type: () => string, text: () => string }) => void): void
|
|
@@ -53,6 +56,7 @@ interface Page {
|
|
|
53
56
|
click(selector: string, options: { timeout: number }): Promise<void>
|
|
54
57
|
hover(selector: string, options: { timeout: number }): Promise<void>
|
|
55
58
|
fill(selector: string, value: string, options: { timeout: number }): Promise<void>
|
|
59
|
+
keyboard: { press(key: string): Promise<void> }
|
|
56
60
|
locator(selector: string): { first: () => { innerText: (options: { timeout: number }) => Promise<string> } }
|
|
57
61
|
}
|
|
58
62
|
interface BrowserContext {
|
|
@@ -64,8 +68,8 @@ interface Browser {
|
|
|
64
68
|
close(): Promise<void>
|
|
65
69
|
}
|
|
66
70
|
|
|
67
|
-
// True once every island that hydrates on load has hydrated; the ones waiting to be seen, idle or
|
|
68
|
-
const ISLANDS_HYDRATED = `[...document.querySelectorAll('pru-island')].every(e =>
|
|
71
|
+
// True once every island that hydrates on load has hydrated; the ones waiting to be seen, idle, touched or matching a media query are left to the test.
|
|
72
|
+
const ISLANDS_HYDRATED = `[...document.querySelectorAll('pru-island')].every(e => { const h = e.getAttribute('h'); return h === 'visible' || h === 'idle' || h === 'interaction' || (h !== null && h.startsWith('media(')) || e._d !== undefined })`
|
|
69
73
|
|
|
70
74
|
interface PlaywrightCore {
|
|
71
75
|
chromium: { launch: (options: { headless: boolean, executablePath: string }) => Promise<Browser>, executablePath: () => string }
|
|
@@ -93,7 +97,7 @@ function findBrowser(playwright: PlaywrightCore, given: string | undefined): str
|
|
|
93
97
|
return found
|
|
94
98
|
}
|
|
95
99
|
|
|
96
|
-
function wrapPage(page: Page, context: BrowserContext, timeout: number
|
|
100
|
+
function wrapPage(page: Page, context: BrowserContext, timeout: number): BrowserPage {
|
|
97
101
|
const errors: string[] = []
|
|
98
102
|
page.on('pageerror', error => errors.push(error.message))
|
|
99
103
|
// A failed load logs a console error without its URL, so the response names it instead; the favicon browsers ask for unprompted is no mistake of the app.
|
|
@@ -106,7 +110,9 @@ function wrapPage(page: Page, context: BrowserContext, timeout: number, url: str
|
|
|
106
110
|
errors.push(message.text())
|
|
107
111
|
})
|
|
108
112
|
return {
|
|
109
|
-
url
|
|
113
|
+
get url() {
|
|
114
|
+
return page.url()
|
|
115
|
+
},
|
|
110
116
|
errors,
|
|
111
117
|
async evaluate(fn) {
|
|
112
118
|
return await page.evaluate(fn as () => never)
|
|
@@ -126,6 +132,9 @@ function wrapPage(page: Page, context: BrowserContext, timeout: number, url: str
|
|
|
126
132
|
async fill(selector, value) {
|
|
127
133
|
await page.fill(selector, value, { timeout })
|
|
128
134
|
},
|
|
135
|
+
async press(key) {
|
|
136
|
+
await page.keyboard.press(key)
|
|
137
|
+
},
|
|
129
138
|
async text(selector) {
|
|
130
139
|
return await page.locator(selector).first().innerText({ timeout })
|
|
131
140
|
},
|
|
@@ -160,19 +169,25 @@ export async function testBrowser(options: BrowserTestOptions): Promise<BrowserT
|
|
|
160
169
|
origin,
|
|
161
170
|
async open(path, openOptions) {
|
|
162
171
|
const context = await browser.newContext(openOptions?.reducedMotion === true ? { reducedMotion: 'reduce' } : undefined)
|
|
163
|
-
const page = await context.newPage()
|
|
164
|
-
const url = new URL(path, origin).href
|
|
165
|
-
const wrapped = wrapPage(page, context, timeout, url)
|
|
166
|
-
// Not `networkidle`: a page that polls or streams never goes idle.
|
|
167
|
-
await page.goto(url, { waitUntil: 'load', timeout })
|
|
168
172
|
try {
|
|
169
|
-
|
|
173
|
+
const page = await context.newPage()
|
|
174
|
+
const url = new URL(path, origin).href
|
|
175
|
+
const wrapped = wrapPage(page, context, timeout)
|
|
176
|
+
// Not `networkidle`: a page that polls or streams never goes idle.
|
|
177
|
+
await page.goto(url, { waitUntil: 'load', timeout })
|
|
178
|
+
try {
|
|
179
|
+
await page.waitForFunction(ISLANDS_HYDRATED, undefined, { timeout })
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
const seen = wrapped.errors.length > 0 ? `; the page reported: ${wrapped.errors.join('; ')}` : ''
|
|
183
|
+
throw new Error(`prunelle: the islands of ${url} did not hydrate within ${timeout} ms${seen}.`, { cause: error })
|
|
184
|
+
}
|
|
185
|
+
return wrapped
|
|
170
186
|
}
|
|
171
187
|
catch (error) {
|
|
172
|
-
|
|
173
|
-
throw
|
|
188
|
+
await context.close().catch(() => undefined)
|
|
189
|
+
throw error
|
|
174
190
|
}
|
|
175
|
-
return wrapped
|
|
176
191
|
},
|
|
177
192
|
async close() {
|
|
178
193
|
try {
|
package/src/test/index.ts
CHANGED
|
@@ -2,16 +2,65 @@
|
|
|
2
2
|
|
|
3
3
|
import type { BuildManifest, BuildOptions } from '../build/index'
|
|
4
4
|
import type { PrunelleApp, ServerAction, ServerRuntimeConfig } from '../server/index'
|
|
5
|
-
import { readdirSync, rmSync } from 'node:fs'
|
|
5
|
+
import { existsSync, readdirSync, rmSync } from 'node:fs'
|
|
6
6
|
import { dirname, join, resolve } from 'node:path'
|
|
7
7
|
import { build } from '../build/index'
|
|
8
8
|
import { relPosix } from '../build/files'
|
|
9
9
|
import { processSuffix, removeDeadProcessDirs } from '../build/output'
|
|
10
|
+
import { ensureCacheGitignore } from '../build/precompress'
|
|
10
11
|
import { resolveServerConfig } from '../server/index'
|
|
12
|
+
import { FORM_TIMESTAMP_FIELD, honeypotFieldName, signFormTimestamp } from '../server/action-protect'
|
|
11
13
|
import { startBuiltApp } from '../server/loader'
|
|
12
14
|
|
|
13
15
|
const TEST_DIR_PREFIX = 'test-'
|
|
14
|
-
const ABSOLUTE_URL_RE = /^https?:\/\//
|
|
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
|
+
}
|
|
15
64
|
|
|
16
65
|
export interface TestAppOptions extends Omit<BuildOptions, 'compile' | 'static'>, Partial<ServerRuntimeConfig> {
|
|
17
66
|
prebuilt?: boolean | undefined
|
|
@@ -31,6 +80,9 @@ export interface TestApp {
|
|
|
31
80
|
/** Posts `fields` as a form to an action, given as one from `import()` or as its URL. */
|
|
32
81
|
submit(action: ServerAction<never, unknown> | string, fields: Record<string, string>, headers?: HeadersInit): Promise<Response>
|
|
33
82
|
clearCookies(): void
|
|
83
|
+
/** Runs plugin shutdown hooks and cleans up app resources (idempotent). */
|
|
84
|
+
dispose(): Promise<void>
|
|
85
|
+
[Symbol.asyncDispose](): Promise<void>
|
|
34
86
|
}
|
|
35
87
|
|
|
36
88
|
/** The folder of the latest testApp() build of each app root in this process, which `prebuilt: true` reuses. */
|
|
@@ -41,12 +93,17 @@ const ownOutDirs: string[] = []
|
|
|
41
93
|
function ownOutDir(root: string): string {
|
|
42
94
|
const cacheDir = join(root, '.prunelle-cache')
|
|
43
95
|
removeDeadProcessDirs(cacheDir, TEST_DIR_PREFIX)
|
|
96
|
+
ensureCacheGitignore(cacheDir)
|
|
44
97
|
if (ownOutDirs.length === 0) {
|
|
45
98
|
process.once('exit', () => {
|
|
46
99
|
for (const dir of ownOutDirs) {
|
|
47
100
|
rmSync(dir, { recursive: true, force: true })
|
|
48
|
-
|
|
49
|
-
|
|
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 })
|
|
50
107
|
}
|
|
51
108
|
})
|
|
52
109
|
}
|
|
@@ -63,10 +120,19 @@ export async function testApp(options: TestAppOptions): Promise<TestApp> {
|
|
|
63
120
|
root: options.root,
|
|
64
121
|
routesDir: options.routesDir,
|
|
65
122
|
outDir,
|
|
123
|
+
publicDir: options.publicDir,
|
|
66
124
|
minify: options.minify ?? false,
|
|
67
125
|
assetPrefix: options.assetPrefix,
|
|
68
126
|
site: options.site,
|
|
69
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,
|
|
70
136
|
dev: options.dev,
|
|
71
137
|
nodeEnv: options.nodeEnv,
|
|
72
138
|
})
|
|
@@ -100,29 +166,39 @@ export async function testApp(options: TestAppOptions): Promise<TestApp> {
|
|
|
100
166
|
continue
|
|
101
167
|
const name = first.slice(0, eq).trim()
|
|
102
168
|
const val = first.slice(eq + 1).trim()
|
|
103
|
-
if (
|
|
169
|
+
if (isExpiredSetCookie(raw) || val === '')
|
|
104
170
|
cookies.delete(name)
|
|
105
171
|
else
|
|
106
|
-
cookies.set(name,
|
|
172
|
+
cookies.set(name, safeDecodeCookieValue(val))
|
|
107
173
|
}
|
|
108
174
|
}
|
|
109
175
|
|
|
110
176
|
async function doFetch(pathOrReq: string | Request, init?: RequestInit): Promise<Response> {
|
|
111
177
|
const req = typeof pathOrReq === 'string'
|
|
112
178
|
? new Request(ABSOLUTE_URL_RE.test(pathOrReq) ? pathOrReq : `http://localhost${pathOrReq}`, init)
|
|
113
|
-
: pathOrReq
|
|
179
|
+
: (init !== undefined ? new Request(pathOrReq, init) : pathOrReq)
|
|
114
180
|
|
|
115
|
-
const headers = new Headers(req.headers)
|
|
116
181
|
const existing = cookieHeader()
|
|
117
|
-
|
|
182
|
+
let withCookies = req
|
|
183
|
+
if (existing !== undefined && !req.headers.has('cookie')) {
|
|
184
|
+
const headers = new Headers(req.headers)
|
|
118
185
|
headers.set('cookie', existing)
|
|
186
|
+
withCookies = new Request(req, { headers })
|
|
187
|
+
}
|
|
119
188
|
|
|
120
|
-
const withCookies = new Request(req, { headers })
|
|
121
189
|
const res = await app.handle(withCookies)
|
|
122
190
|
storeSetCookies(res)
|
|
123
191
|
return res
|
|
124
192
|
}
|
|
125
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
|
+
|
|
126
202
|
return {
|
|
127
203
|
app,
|
|
128
204
|
manifest,
|
|
@@ -135,7 +211,7 @@ export async function testApp(options: TestAppOptions): Promise<TestApp> {
|
|
|
135
211
|
post(path, body, headers) {
|
|
136
212
|
const h = new Headers(headers)
|
|
137
213
|
if (!h.has('origin'))
|
|
138
|
-
h.set('origin',
|
|
214
|
+
h.set('origin', defaultOriginFor(path))
|
|
139
215
|
if (body instanceof FormData)
|
|
140
216
|
return doFetch(path, { method: 'POST', body, headers: h })
|
|
141
217
|
if (!h.has('content-type'))
|
|
@@ -162,14 +238,23 @@ export async function testApp(options: TestAppOptions): Promise<TestApp> {
|
|
|
162
238
|
const fd = new FormData()
|
|
163
239
|
for (const [k, v] of Object.entries(fields))
|
|
164
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
|
+
}
|
|
165
248
|
const h = new Headers(headers)
|
|
166
249
|
if (!h.has('origin'))
|
|
167
|
-
h.set('origin',
|
|
250
|
+
h.set('origin', defaultOriginFor(actionUrl))
|
|
168
251
|
return doFetch(actionUrl, { method: 'POST', body: fd, headers: h })
|
|
169
252
|
},
|
|
170
253
|
clearCookies() {
|
|
171
254
|
cookies.clear()
|
|
172
255
|
},
|
|
256
|
+
dispose,
|
|
257
|
+
[Symbol.asyncDispose]: dispose,
|
|
173
258
|
}
|
|
174
259
|
}
|
|
175
260
|
|