@quiesco/core 0.10.0 → 0.12.0
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/dist/config.d.ts +10 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/device.d.ts +5 -0
- package/dist/device.d.ts.map +1 -1
- package/dist/device.js +48 -2
- package/dist/device.js.map +1 -1
- package/dist/devices/ios-runner.d.ts +10 -1
- package/dist/devices/ios-runner.d.ts.map +1 -1
- package/dist/devices/ios-runner.js +17 -6
- package/dist/devices/ios-runner.js.map +1 -1
- package/dist/devices/ios.d.ts +18 -1
- package/dist/devices/ios.d.ts.map +1 -1
- package/dist/devices/ios.js +98 -28
- package/dist/devices/ios.js.map +1 -1
- package/dist/devices/provider.d.ts +15 -0
- package/dist/devices/provider.d.ts.map +1 -1
- package/dist/driver.d.ts.map +1 -1
- package/dist/driver.js +13 -3
- package/dist/driver.js.map +1 -1
- package/dist/server/ws-server.d.ts +1 -0
- package/dist/server/ws-server.d.ts.map +1 -1
- package/dist/server/ws-server.js +2 -0
- package/dist/server/ws-server.js.map +1 -1
- package/dist/session.d.ts +0 -2
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +13 -2
- package/dist/session.js.map +1 -1
- package/dist/timeline.d.ts +17 -0
- package/dist/timeline.d.ts.map +1 -1
- package/dist/timeline.js +56 -10
- package/dist/timeline.js.map +1 -1
- package/package.json +2 -2
- package/src/config.ts +11 -3
- package/src/device.ts +44 -2
- package/src/devices/ios-runner.ts +19 -6
- package/src/devices/ios.ts +108 -27
- package/src/devices/provider.ts +15 -0
- package/src/driver.ts +11 -3
- package/src/server/ws-server.ts +2 -0
- package/src/session.ts +14 -1
- package/src/timeline.ts +62 -10
package/src/driver.ts
CHANGED
|
@@ -563,8 +563,11 @@ export class Driver {
|
|
|
563
563
|
const covered = e instanceof QuiescoError && (e.errorName === 'ELEMENT_OBSCURED' || (e.errorName === 'ELEMENT_NOT_FOUND' && e.data['reason'] === 'not-in-window'));
|
|
564
564
|
if (!covered || dismiss === undefined) throw e;
|
|
565
565
|
const closed = await dismiss().catch(() => [] as string[]);
|
|
566
|
-
if (closed.length
|
|
567
|
-
|
|
566
|
+
if (closed.length > 0) return this.call('action', params, timeoutMs, steps);
|
|
567
|
+
// One Quiesco leaves up (a permission alert, issue #86) is the likely reason: say so.
|
|
568
|
+
const unanswered = await this.options.provider.unansweredSystemAlert?.().catch(() => undefined);
|
|
569
|
+
if (unanswered === undefined) throw e;
|
|
570
|
+
throw new QuiescoError(e.errorName, `${e.message}\n${unanswered}`, e.data as never);
|
|
568
571
|
}
|
|
569
572
|
}
|
|
570
573
|
|
|
@@ -733,6 +736,10 @@ export class Driver {
|
|
|
733
736
|
this.logErrors.push(l.message);
|
|
734
737
|
if (this.logErrors.length > MAX_APP_LOG_ERRORS) this.logErrors.shift();
|
|
735
738
|
});
|
|
739
|
+
// Steps of the running call, in the timeline before the call returns (issue #84).
|
|
740
|
+
conn.on('step', (s) => {
|
|
741
|
+
if (this.watched === conn) this.options.timeline?.step(s);
|
|
742
|
+
});
|
|
736
743
|
conn.on('appError', (e) => {
|
|
737
744
|
if (this.watched !== conn) return;
|
|
738
745
|
if (this.options.ignoreAppErrors?.some((re) => re.test(e.message)) === true) {
|
|
@@ -749,7 +756,8 @@ export class Driver {
|
|
|
749
756
|
function describeCall(method: string, params: unknown): string {
|
|
750
757
|
const p = (params ?? {}) as Record<string, unknown>;
|
|
751
758
|
const spec = (p['action'] ?? p['assertion']) as Record<string, unknown> | undefined;
|
|
752
|
-
|
|
759
|
+
// scrollTo: the element it looks for.
|
|
760
|
+
const matcher = spec?.['matcher'] ?? spec?.['target'] ?? p['matcher'];
|
|
753
761
|
const what = spec !== undefined ? String(spec['type']) : method === 'backdoor' ? String(p['name']) : '';
|
|
754
762
|
const m = matcher === undefined ? '' : JSON.stringify(matcher);
|
|
755
763
|
return [what, m.length > 120 ? `${m.slice(0, 117)}...` : m].filter((x) => x !== '').join(' ');
|
package/src/server/ws-server.ts
CHANGED
|
@@ -31,6 +31,7 @@ interface Pending {
|
|
|
31
31
|
export class AgentConnection extends EventEmitter<{
|
|
32
32
|
log: [AgentEvents['log']];
|
|
33
33
|
appError: [AgentEvents['error']];
|
|
34
|
+
step: [AgentEvents['step']];
|
|
34
35
|
close: [code: number, reason: string];
|
|
35
36
|
}> {
|
|
36
37
|
private nextId = 1;
|
|
@@ -120,6 +121,7 @@ export class AgentConnection extends EventEmitter<{
|
|
|
120
121
|
}
|
|
121
122
|
if (msg.method === 'log') this.emit('log', msg.params as AgentEvents['log']);
|
|
122
123
|
else if (msg.method === 'error') this.emit('appError', msg.params as AgentEvents['error']);
|
|
124
|
+
else if (msg.method === 'step') this.emit('step', msg.params as AgentEvents['step']);
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
/** @internal */
|
package/src/session.ts
CHANGED
|
@@ -32,12 +32,16 @@ import { consoleLogger } from './logger.js';
|
|
|
32
32
|
import type { AgentConnection } from './server/ws-server.js';
|
|
33
33
|
import { QuiescoServer } from './server/ws-server.js';
|
|
34
34
|
import { tagNames } from './tags.js';
|
|
35
|
+
import { NOT_COUNTED_NOTE } from './timeline.js';
|
|
35
36
|
|
|
36
37
|
/** The session's first launch waits this many times the default connect timeout. */
|
|
37
38
|
export const FIRST_LAUNCH_CONNECT_FACTOR = 3;
|
|
38
39
|
|
|
39
40
|
/** Errors of the per-scenario reset after which the app is started again instead of failing the scenario. */
|
|
40
41
|
/** Issue #74. */
|
|
42
|
+
/** The latest calls whose native calls were not waited for, in idle-state.json (issue #94). */
|
|
43
|
+
const NOT_COUNTED_IN_EVIDENCE = 10;
|
|
44
|
+
|
|
41
45
|
export const NATIVE_MODULES_NOT_WRAPPED =
|
|
42
46
|
"sync.trackers: { 'native-module': true }, but the app's build does not wrap native modules, so the tracker counts nothing. Build it with withQuiesco(config, { nativeModules: true }) in metro.config.js (or EXPO_PUBLIC_QUIESCO_NATIVE_MODULES=1) and restart Metro.";
|
|
43
47
|
|
|
@@ -291,7 +295,16 @@ export class Session {
|
|
|
291
295
|
if (ev.screenshot !== undefined) evidence.push({ data: ev.screenshot, mediaType: 'image/png', fileName: 'failure.png' });
|
|
292
296
|
if (ev.elements !== undefined) evidence.push({ data: JSON.stringify(ev.elements, null, 2), mediaType: 'application/json', fileName: 'elements.json' });
|
|
293
297
|
if (ev.tree !== undefined) evidence.push({ data: JSON.stringify({ elementTree: ev.tree }, null, 2), mediaType: 'application/json', fileName: 'element-tree.json' });
|
|
294
|
-
if (ev.idle !== undefined)
|
|
298
|
+
if (ev.idle !== undefined) {
|
|
299
|
+
// Issue #94: an action that returned while the app awaited a native call races the test; the failure
|
|
300
|
+
// shows up later. The calls of this scenario that did that, for the native-module tracker being off.
|
|
301
|
+
const notCounted = this.artifacts.timeline.all
|
|
302
|
+
.filter((e) => e.nativeCallsNotCounted !== undefined)
|
|
303
|
+
.slice(-NOT_COUNTED_IN_EVIDENCE)
|
|
304
|
+
.map((e) => ({ call: `${e.method} ${e.label}`.trim(), pending: e.nativeCallsNotCounted }));
|
|
305
|
+
const idle = { idleState: ev.idle, ...(notCounted.length > 0 ? { nativeCallsNotCounted: { note: NOT_COUNTED_NOTE, calls: notCounted } } : {}) };
|
|
306
|
+
evidence.push({ data: JSON.stringify(idle, null, 2), mediaType: 'application/json', fileName: 'idle-state.json' });
|
|
307
|
+
}
|
|
295
308
|
if (ev.errors.length > 0) evidence.push({ data: `Quiesco could not collect: ${ev.errors.join('; ')}`, mediaType: 'text/plain', fileName: 'evidence-errors.txt' });
|
|
296
309
|
if (ev.crash !== undefined) {
|
|
297
310
|
evidence.push({ data: `${ev.crash.message}\n`, mediaType: 'text/plain', fileName: 'crash.txt' });
|
package/src/timeline.ts
CHANGED
|
@@ -16,6 +16,10 @@ export interface TimelineEntry {
|
|
|
16
16
|
end: number;
|
|
17
17
|
/** Of which waiting for idle in the agent. */
|
|
18
18
|
syncMs?: number;
|
|
19
|
+
/** What the waits for idle ended on, per tracker (issue #93). */
|
|
20
|
+
syncBusy?: string[];
|
|
21
|
+
/** Native calls pending when the call returned, not counted: the `native-module` tracker is off (issue #94). */
|
|
22
|
+
nativeCallsNotCounted?: string[];
|
|
19
23
|
/** The steps of a multi-step action, `atMs` from `start` (issue #78). */
|
|
20
24
|
steps?: StepTiming[];
|
|
21
25
|
error?: string;
|
|
@@ -24,17 +28,31 @@ export interface TimelineEntry {
|
|
|
24
28
|
/** What a call's result (or error data) says about its timing. */
|
|
25
29
|
export interface CallTiming {
|
|
26
30
|
syncMs?: number;
|
|
31
|
+
syncBusy?: string[];
|
|
32
|
+
nativeCallsNotCounted?: string[];
|
|
27
33
|
steps?: StepTiming[];
|
|
28
34
|
}
|
|
29
35
|
|
|
36
|
+
/** Said with the native calls an action did not wait for (issue #94). */
|
|
37
|
+
export const NOT_COUNTED_NOTE = 'pending when the call returned, not waited for: the native-module tracker is off';
|
|
38
|
+
|
|
39
|
+
/** What a call still running when the timeline is written says (issue #84). */
|
|
40
|
+
export const STILL_RUNNING = 'still running when the scenario ended (the test ended it first: its timeout?)';
|
|
41
|
+
|
|
30
42
|
export class Timeline {
|
|
31
43
|
private entries: TimelineEntry[] = [];
|
|
44
|
+
/** Calls not returned yet, with the steps the agent reported so far (issue #84). */
|
|
45
|
+
private running: TimelineEntry[] = [];
|
|
46
|
+
/** Bumped by reset: a call of an earlier scenario that returns late does not land in this one. */
|
|
47
|
+
private generation = 0;
|
|
32
48
|
private started = Date.now();
|
|
33
49
|
private name = '';
|
|
34
50
|
|
|
35
51
|
/** Start a new scenario's timeline. */
|
|
36
52
|
reset(name: string): void {
|
|
37
53
|
this.entries = [];
|
|
54
|
+
this.running = [];
|
|
55
|
+
this.generation++;
|
|
38
56
|
this.started = Date.now();
|
|
39
57
|
this.name = name;
|
|
40
58
|
}
|
|
@@ -48,29 +66,56 @@ export class Timeline {
|
|
|
48
66
|
/** Measure `fn` as one entry. */
|
|
49
67
|
async measure<T>(method: string, label: string, fn: () => Promise<T>, timing?: (r: T) => CallTiming | undefined): Promise<T> {
|
|
50
68
|
const start = Date.now();
|
|
69
|
+
const running: TimelineEntry = { method, label, start, end: start, steps: [] };
|
|
70
|
+
this.running.push(running);
|
|
71
|
+
const generation = this.generation;
|
|
72
|
+
const add = (entry: TimelineEntry): void => {
|
|
73
|
+
if (generation === this.generation) this.add(entry);
|
|
74
|
+
};
|
|
51
75
|
try {
|
|
52
76
|
const r = await fn();
|
|
53
77
|
const t = timing?.(r);
|
|
54
|
-
|
|
78
|
+
add({
|
|
79
|
+
method,
|
|
80
|
+
label,
|
|
81
|
+
start,
|
|
82
|
+
end: Date.now(),
|
|
83
|
+
...(t?.syncMs !== undefined ? { syncMs: t.syncMs } : {}),
|
|
84
|
+
...(t?.syncBusy !== undefined && t.syncBusy.length > 0 ? { syncBusy: t.syncBusy } : {}),
|
|
85
|
+
...(t?.nativeCallsNotCounted !== undefined && t.nativeCallsNotCounted.length > 0 ? { nativeCallsNotCounted: t.nativeCallsNotCounted } : {}),
|
|
86
|
+
...(t?.steps !== undefined && t.steps.length > 0 ? { steps: t.steps } : {}),
|
|
87
|
+
});
|
|
55
88
|
return r;
|
|
56
89
|
} catch (e) {
|
|
57
90
|
// A multi-step action that failed still reports its steps (issue #78).
|
|
58
91
|
const steps = (e as { data?: { steps?: unknown } } | null)?.data?.steps;
|
|
59
|
-
|
|
92
|
+
add({ method, label, start, end: Date.now(), ...(Array.isArray(steps) && steps.length > 0 ? { steps: steps as StepTiming[] } : {}), error: e instanceof Error ? e.message : String(e) });
|
|
60
93
|
throw e;
|
|
94
|
+
} finally {
|
|
95
|
+
this.running = this.running.filter((r) => r !== running);
|
|
61
96
|
}
|
|
62
97
|
}
|
|
63
98
|
|
|
99
|
+
/** A step of the running call (calls to the agent run one at a time), reported before it returns (issue #84). */
|
|
100
|
+
step(s: StepTiming): void {
|
|
101
|
+
this.running.at(-1)?.steps?.push(s);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The calls, then those still running (ending now, with the steps so far). */
|
|
64
105
|
get all(): readonly TimelineEntry[] {
|
|
65
|
-
return this.entries;
|
|
106
|
+
if (this.running.length === 0) return this.entries;
|
|
107
|
+
const now = Date.now();
|
|
108
|
+
return [...this.entries, ...this.running.map(({ steps, ...r }) => ({ ...r, end: now, ...(steps !== undefined && steps.length > 0 ? { steps: [...steps] } : {}), error: STILL_RUNNING }))];
|
|
66
109
|
}
|
|
67
110
|
|
|
68
111
|
/** Chrome trace event format: complete events ("X"), sync waits nested inside their calls. */
|
|
69
112
|
toTrace(): string {
|
|
70
113
|
const us = (t: number): number => Math.round((t - this.started) * 1000);
|
|
71
114
|
const events: Record<string, unknown>[] = [{ name: 'process_name', ph: 'M', pid: 1, tid: 1, args: { name: `Quiesco: ${this.name}` } }];
|
|
72
|
-
for (const e of this.
|
|
73
|
-
|
|
115
|
+
for (const e of this.all) {
|
|
116
|
+
const args = { ...(e.error !== undefined ? { error: e.error } : {}), ...(e.nativeCallsNotCounted !== undefined ? { nativeCallsNotCounted: e.nativeCallsNotCounted, note: NOT_COUNTED_NOTE } : {}) };
|
|
117
|
+
events.push({ name: `${e.method} ${e.label}`.trim(), cat: e.method, ph: 'X', ts: us(e.start), dur: Math.max(1, us(e.end) - us(e.start)), pid: 1, tid: 1, args });
|
|
118
|
+
const busy = e.syncBusy !== undefined ? { busy: e.syncBusy } : {};
|
|
74
119
|
if (e.steps !== undefined) {
|
|
75
120
|
e.steps.forEach((s, i) => {
|
|
76
121
|
const ts = us(e.start + s.atMs);
|
|
@@ -78,7 +123,7 @@ export class Timeline {
|
|
|
78
123
|
if (s.syncMs > 0) events.push({ name: 'wait for idle', cat: 'sync', ph: 'X', ts: ts + Math.max(0, s.ms - s.syncMs) * 1000, dur: Math.max(1, s.syncMs * 1000), pid: 1, tid: 1 });
|
|
79
124
|
});
|
|
80
125
|
} else if (e.syncMs !== undefined && e.syncMs > 0) {
|
|
81
|
-
events.push({ name: 'wait for idle', cat: 'sync', ph: 'X', ts: us(e.start), dur: Math.max(1, Math.round(e.syncMs * 1000)), pid: 1, tid: 1 });
|
|
126
|
+
events.push({ name: 'wait for idle', cat: 'sync', ph: 'X', ts: us(e.start), dur: Math.max(1, Math.round(e.syncMs * 1000)), pid: 1, tid: 1, args: busy });
|
|
82
127
|
}
|
|
83
128
|
}
|
|
84
129
|
return JSON.stringify({ traceEvents: events, displayTimeUnit: 'ms' });
|
|
@@ -86,14 +131,20 @@ export class Timeline {
|
|
|
86
131
|
|
|
87
132
|
/** One page: a bar per call (sync wait shaded), failed calls in red with their message. */
|
|
88
133
|
toHtml(): string {
|
|
89
|
-
const
|
|
90
|
-
const
|
|
134
|
+
const entries = this.all;
|
|
135
|
+
const total = Math.max(1, ...entries.map((e) => e.end - this.started));
|
|
136
|
+
const rows = entries
|
|
91
137
|
.map((e) => {
|
|
92
138
|
const left = ((e.start - this.started) / total) * 100;
|
|
93
139
|
const width = Math.max(0.3, ((e.end - e.start) / total) * 100);
|
|
94
140
|
const sync = e.syncMs !== undefined ? Math.min(100, (e.syncMs / Math.max(1, e.end - e.start)) * 100) : 0;
|
|
95
141
|
const cls = e.error !== undefined ? 'row failed' : 'row';
|
|
96
142
|
const err = e.error !== undefined ? `<div class="err">${esc(e.error)}</div>` : '';
|
|
143
|
+
const notes = [
|
|
144
|
+
...(e.syncBusy !== undefined ? [`idle wait ended on: ${e.syncBusy.join(' | ')}`] : []),
|
|
145
|
+
...(e.nativeCallsNotCounted !== undefined ? [`native calls ${NOT_COUNTED_NOTE}: ${e.nativeCallsNotCounted.join(', ')}`] : []),
|
|
146
|
+
];
|
|
147
|
+
const why = notes.length > 0 ? `<div class="why">${notes.map(esc).join('<br>')}</div>` : '';
|
|
97
148
|
const steps = (e.steps ?? [])
|
|
98
149
|
.map((s, i) => {
|
|
99
150
|
const sLeft = ((e.start + s.atMs - this.started) / total) * 100;
|
|
@@ -102,7 +153,7 @@ export class Timeline {
|
|
|
102
153
|
return `<div class="row step"><div class="name">step ${i + 1} ${esc(s.label)}</div><div class="ms">${s.ms} ms (idle wait ${s.syncMs} ms)</div><div class="track"><div class="bar" style="left:${sLeft.toFixed(2)}%;width:${sWidth.toFixed(2)}%"><div class="sync" style="width:${sSync.toFixed(1)}%"></div></div></div></div>`;
|
|
103
154
|
})
|
|
104
155
|
.join('');
|
|
105
|
-
return `<div class="${cls}"><div class="name">${esc(`${e.method} ${e.label}`)}</div><div class="ms">${e.end - e.start} ms${e.syncMs !== undefined ? ` (idle wait ${Math.round(e.syncMs)} ms)` : ''}</div><div class="track"><div class="bar" style="left:${left.toFixed(2)}%;width:${width.toFixed(2)}%"><div class="sync" style="width:${sync.toFixed(1)}%"></div></div></div>${err}</div>${steps}`;
|
|
156
|
+
return `<div class="${cls}"><div class="name">${esc(`${e.method} ${e.label}`)}</div><div class="ms">${e.end - e.start} ms${e.syncMs !== undefined ? ` (idle wait ${Math.round(e.syncMs)} ms)` : ''}</div><div class="track"><div class="bar" style="left:${left.toFixed(2)}%;width:${width.toFixed(2)}%"><div class="sync" style="width:${sync.toFixed(1)}%"></div></div></div>${why}${err}</div>${steps}`;
|
|
106
157
|
})
|
|
107
158
|
.join('\n');
|
|
108
159
|
return `<!doctype html><html><head><meta charset="utf-8"><title>${esc(this.name)} — Quiesco timeline</title><style>
|
|
@@ -111,8 +162,9 @@ body{font:13px system-ui,sans-serif;margin:16px;color:#222}h1{font-size:16px}
|
|
|
111
162
|
.name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-family:ui-monospace,monospace}.ms{color:#666;text-align:right}
|
|
112
163
|
.track{position:relative;height:12px;background:#f4f4f4}.bar{position:absolute;top:0;height:12px;background:#6b8de3}.sync{height:12px;background:#b9c9f3}
|
|
113
164
|
.step .name{padding-left:16px;color:#555}.step .bar{background:#9aa9cc}
|
|
165
|
+
.why{grid-column:1/-1;color:#666;white-space:pre-wrap;font-family:ui-monospace,monospace;font-size:12px;padding:0 0 4px 16px}
|
|
114
166
|
.failed .bar{background:#d9534f}.failed .name{color:#c00}.err{grid-column:1/-1;color:#c00;white-space:pre-wrap;font-family:ui-monospace,monospace;font-size:12px;padding:4px 0 6px}
|
|
115
|
-
</style></head><body><h1>${esc(this.name)}</h1><p>${
|
|
167
|
+
</style></head><body><h1>${esc(this.name)}</h1><p>${entries.length} calls, ${total} ms. Light part of a bar: waiting for the app to be idle.</p>
|
|
116
168
|
${rows}
|
|
117
169
|
</body></html>`;
|
|
118
170
|
}
|