@akanjs/devkit 3.3.0-rc.72 → 3.3.0-rc.73
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.
|
@@ -32,8 +32,9 @@ the server errors logged meanwhile, console errors and warnings, and layout smel
|
|
|
32
32
|
name, and reads the account from `process.env`. `--as <name>` reaches it as `as`; `--anonymous` skips it.
|
|
33
33
|
With none declared a guarded page shows its redirect: add it, or say "not opened signed in".
|
|
34
34
|
- The viewport is a 390x844 phone; `--desktop` is 1280x800. `--csr` loads each page in the CSR boot the native
|
|
35
|
-
shells load. `--screenshot` saves a PNG per page under `local/apps/<app>/runtime/preview
|
|
36
|
-
|
|
35
|
+
shells load. `--screenshot` saves a PNG per page under `local/apps/<app>/runtime/preview/`. `--format json`
|
|
36
|
+
gives the same report as data. `--wait-for <selector>` holds a page that draws after its first client read
|
|
37
|
+
until the selector matches, and fails it at `--timeout`.
|
|
37
38
|
|
|
38
39
|
### Which platforms that covers
|
|
39
40
|
|
|
@@ -25,7 +25,7 @@ import path at all**, so keep throwing code out of them entirely rather than rea
|
|
|
25
25
|
## Where each error belongs
|
|
26
26
|
|
|
27
27
|
Which file throws which error, and the sentinel best-effort code returns instead, are the `server` rule.
|
|
28
|
-
`try/catch` is rare and always converts an exception into a decision: a guard catches, warns, and returns `false
|
|
28
|
+
`try/catch` is rare and always converts an exception into a decision: a guard catches, warns, and returns `false`, or throws a keyed `Err.Forbidden` the caller must read; an adapter
|
|
29
29
|
catches, logs (`logger.error`), and returns `null`; a UI `try/finally` resets a spinner. A store action never
|
|
30
30
|
catches — let the framework toast the `Err`, or list it in the store's `static silent` when no screen waits on it
|
|
31
31
|
and its caller handles the rejection.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akanjs/devkit",
|
|
3
|
-
"version": "3.3.0-rc.
|
|
3
|
+
"version": "3.3.0-rc.73",
|
|
4
4
|
"sourceType": "module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"./workspace/getRelatedCnsts": "./workspace/getRelatedCnsts.ts"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@akanjs/language": "3.3.0-rc.
|
|
55
|
+
"@akanjs/language": "3.3.0-rc.73",
|
|
56
56
|
"@inquirer/prompts": "^8.7.3",
|
|
57
57
|
"@tailwindcss/node": "^4.3.3",
|
|
58
|
-
"akanjs": "3.3.0-rc.
|
|
58
|
+
"akanjs": "3.3.0-rc.73",
|
|
59
59
|
"chalk": "^6.0.1",
|
|
60
60
|
"commander": "^15.0.0",
|
|
61
61
|
"dayjs": "^1.11.23",
|
package/preview/PreviewView.ts
CHANGED
|
@@ -18,6 +18,7 @@ export interface PreviewProbeOptions {
|
|
|
18
18
|
timeoutMs?: number;
|
|
19
19
|
/** Waited after the load, so the errors effects throw land before the page is read. */
|
|
20
20
|
settleMs?: number;
|
|
21
|
+
waitFor?: string;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export interface PreviewProbeResult {
|
|
@@ -56,6 +57,7 @@ interface PageRead {
|
|
|
56
57
|
export class PreviewView {
|
|
57
58
|
/** A view's first navigation includes the browser's start, which took ~35 s on a cold CI runner. */
|
|
58
59
|
static readonly startTimeoutMs = 120_000;
|
|
60
|
+
static readonly selectorPollMs = 100;
|
|
59
61
|
static readonly #stalled = new Set<PreviewEngine>();
|
|
60
62
|
|
|
61
63
|
static get available() {
|
|
@@ -83,6 +85,7 @@ export class PreviewView {
|
|
|
83
85
|
startTimeoutMs = PreviewView.startTimeoutMs,
|
|
84
86
|
timeoutMs = 30_000,
|
|
85
87
|
settleMs = 0,
|
|
88
|
+
waitFor,
|
|
86
89
|
}: PreviewProbeOptions = {},
|
|
87
90
|
): Promise<PreviewProbeResult> {
|
|
88
91
|
const logs: string[] = [];
|
|
@@ -103,11 +106,11 @@ export class PreviewView {
|
|
|
103
106
|
await within(view.navigate(session.url), "opening the session for");
|
|
104
107
|
await within(view.evaluate(PreviewView.cookieExpression(session.cookies)), "opening the session for");
|
|
105
108
|
}
|
|
106
|
-
let page = await PreviewView.#load(view, url, settleMs, within);
|
|
109
|
+
let page = await PreviewView.#load(view, url, { settleMs, waitFor }, within);
|
|
107
110
|
//? Right after a save the first load can render nothing (`[rscClient] module not loaded`); the next one has it.
|
|
108
111
|
if (page.empty) {
|
|
109
112
|
logs.length = 0;
|
|
110
|
-
page = await PreviewView.#load(view, url, settleMs, within);
|
|
113
|
+
page = await PreviewView.#load(view, url, { settleMs, waitFor }, within);
|
|
111
114
|
}
|
|
112
115
|
const result: PreviewProbeResult = {
|
|
113
116
|
url,
|
|
@@ -157,11 +160,12 @@ export class PreviewView {
|
|
|
157
160
|
static async #load(
|
|
158
161
|
view: WebViewLike,
|
|
159
162
|
url: string,
|
|
160
|
-
settleMs: number,
|
|
163
|
+
{ settleMs, waitFor }: { settleMs: number; waitFor?: string },
|
|
161
164
|
within: <T>(work: Promise<T>, what: string) => Promise<T>,
|
|
162
165
|
): Promise<PageRead> {
|
|
163
166
|
await within(view.navigate(url), "loading");
|
|
164
167
|
if (settleMs > 0) await Bun.sleep(settleMs);
|
|
168
|
+
if (waitFor) await PreviewView.#waitForSelector(view, url, waitFor, within);
|
|
165
169
|
const read = (await within(view.evaluate(readPageExpression), "reading")) as Partial<PageRead> | null;
|
|
166
170
|
return {
|
|
167
171
|
href: typeof read?.href === "string" ? read.href : url,
|
|
@@ -174,6 +178,17 @@ export class PreviewView {
|
|
|
174
178
|
};
|
|
175
179
|
}
|
|
176
180
|
|
|
181
|
+
static async #waitForSelector(
|
|
182
|
+
view: WebViewLike,
|
|
183
|
+
url: string,
|
|
184
|
+
selector: string,
|
|
185
|
+
within: <T>(work: Promise<T>, what: string) => Promise<T>,
|
|
186
|
+
) {
|
|
187
|
+
const expression = `document.querySelector(${JSON.stringify(selector)}) !== null`;
|
|
188
|
+
const what = `waiting for selector ${JSON.stringify(selector)} on`;
|
|
189
|
+
while (!(await within(view.evaluate(expression), what))) await within(Bun.sleep(PreviewView.selectorPollMs), what);
|
|
190
|
+
}
|
|
191
|
+
|
|
177
192
|
//? webkit has no Navigation Timing `responseStatus`, so the status comes from asking the server again, unredirected.
|
|
178
193
|
static async #statusOf(href: string, deadline: number, cookies: string[]) {
|
|
179
194
|
const left = Math.max(1, deadline - Date.now());
|
|
@@ -122,6 +122,37 @@ describe("PreviewView", () => {
|
|
|
122
122
|
browserTestMs,
|
|
123
123
|
);
|
|
124
124
|
|
|
125
|
+
test.skipIf(!PreviewView.available)(
|
|
126
|
+
"waits for a selector that a page draws after its first client-side read",
|
|
127
|
+
async () => {
|
|
128
|
+
const server = serve(
|
|
129
|
+
"<!doctype html><title>Late</title><body><script>setTimeout(() => { document.body.innerHTML = '<p id=\"ready\">drawn</p>'; }, 1500);</script></body>",
|
|
130
|
+
);
|
|
131
|
+
try {
|
|
132
|
+
const probe = await PreviewView.probe(`http://localhost:${server.port}/`, { waitFor: "#ready" });
|
|
133
|
+
expect(probe.text).toBe("drawn");
|
|
134
|
+
} finally {
|
|
135
|
+
server.stop(true);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
browserTestMs,
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
test.skipIf(!PreviewView.available)(
|
|
142
|
+
"fails naming the selector when it never appears before the timeout",
|
|
143
|
+
async () => {
|
|
144
|
+
const server = serve("<!doctype html><title>Blank</title><body>blank</body>");
|
|
145
|
+
try {
|
|
146
|
+
await expect(
|
|
147
|
+
PreviewView.probe(`http://localhost:${server.port}/`, { waitFor: "#never", timeoutMs: 2_000 }),
|
|
148
|
+
).rejects.toThrow('waiting for selector "#never"');
|
|
149
|
+
} finally {
|
|
150
|
+
server.stop(true);
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
browserTestMs,
|
|
154
|
+
);
|
|
155
|
+
|
|
125
156
|
test.skipIf(!PreviewView.available)(
|
|
126
157
|
"gives up on a server that takes the connection and never answers",
|
|
127
158
|
async () => {
|