testsurfer 0.0.0-stage → 0.1.1
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 +202 -0
- package/README.md +156 -2
- package/dist/aria.d.ts +44 -0
- package/dist/aria.js +198 -0
- package/dist/aria.js.map +1 -0
- package/dist/browser.d.ts +45 -0
- package/dist/browser.js +84 -0
- package/dist/browser.js.map +1 -0
- package/dist/client.d.ts +59 -0
- package/dist/client.js +274 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.js +35 -0
- package/dist/errors.js.map +1 -0
- package/dist/expect.d.ts +55 -0
- package/dist/expect.js +196 -0
- package/dist/expect.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/locator.d.ts +157 -0
- package/dist/locator.js +316 -0
- package/dist/locator.js.map +1 -0
- package/dist/page.d.ts +223 -0
- package/dist/page.js +491 -0
- package/dist/page.js.map +1 -0
- package/dist/roles.d.ts +3 -0
- package/dist/roles.js +33 -0
- package/dist/roles.js.map +1 -0
- package/dist/runner.d.ts +43 -0
- package/dist/runner.js +117 -0
- package/dist/runner.js.map +1 -0
- package/dist/tree.d.ts +46 -0
- package/dist/tree.js +272 -0
- package/dist/tree.js.map +1 -0
- package/dist/wire.d.ts +48 -0
- package/dist/wire.js +78 -0
- package/dist/wire.js.map +1 -0
- package/package.json +49 -4
package/dist/browser.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser: one vibesurfer session. Owns the wire client, opens pages,
|
|
3
|
+
* and closes the session on shutdown.
|
|
4
|
+
*/
|
|
5
|
+
import { WireClient } from "./client.js";
|
|
6
|
+
/** Parse the vs_status daemon line into negotiated capabilities. */
|
|
7
|
+
async function negotiate(client) {
|
|
8
|
+
const caps = { proto: 0, flags: new Set() };
|
|
9
|
+
try {
|
|
10
|
+
const status = await client.call('vs_status');
|
|
11
|
+
const line = status.body.find((l) => l.startsWith('daemon'));
|
|
12
|
+
if (!line)
|
|
13
|
+
return caps;
|
|
14
|
+
for (const field of line.split('\t').slice(1)) {
|
|
15
|
+
const eq = field.indexOf('=');
|
|
16
|
+
if (eq <= 0)
|
|
17
|
+
continue;
|
|
18
|
+
const key = field.slice(0, eq);
|
|
19
|
+
const value = field.slice(eq + 1);
|
|
20
|
+
if (key === 'proto')
|
|
21
|
+
caps.proto = Number(value) || 0;
|
|
22
|
+
if (key === 'flags')
|
|
23
|
+
for (const f of value.split(','))
|
|
24
|
+
caps.flags.add(f.trim());
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Status shape unknown; stay on pinned-contract defaults.
|
|
29
|
+
}
|
|
30
|
+
return caps;
|
|
31
|
+
}
|
|
32
|
+
import { Page, DEFAULT_TIMEOUTS, } from "./page.js";
|
|
33
|
+
export class Browser {
|
|
34
|
+
client;
|
|
35
|
+
sessionId;
|
|
36
|
+
timeouts;
|
|
37
|
+
inputMode;
|
|
38
|
+
clickVia;
|
|
39
|
+
protocol;
|
|
40
|
+
baseURL;
|
|
41
|
+
constructor(client, sessionId, timeouts, inputMode, clickVia, protocol, baseURL) {
|
|
42
|
+
this.baseURL = baseURL;
|
|
43
|
+
this.client = client;
|
|
44
|
+
this.sessionId = sessionId;
|
|
45
|
+
this.timeouts = timeouts;
|
|
46
|
+
this.inputMode = inputMode;
|
|
47
|
+
this.clickVia = clickVia;
|
|
48
|
+
this.protocol = protocol;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Connect to the daemon (spawning it if needed) and open a session.
|
|
52
|
+
* Wire capabilities are negotiated from the vs_status daemon line
|
|
53
|
+
* (`daemon version=... proto=N flags=a,b`): protocol-v1 daemons get
|
|
54
|
+
* inline act deltas, act-mode clicks, and nav-in-place goto
|
|
55
|
+
* automatically. Explicit options always win over negotiation.
|
|
56
|
+
*/
|
|
57
|
+
static async launch(options = {}) {
|
|
58
|
+
const client = await WireClient.connect(options);
|
|
59
|
+
const caps = await negotiate(client);
|
|
60
|
+
const flags = {};
|
|
61
|
+
if (options.policy)
|
|
62
|
+
flags['policy'] = options.policy;
|
|
63
|
+
const resp = await client.call('vs_session_open', [], flags);
|
|
64
|
+
const sessionId = resp.body[0];
|
|
65
|
+
if (!sessionId) {
|
|
66
|
+
client.close();
|
|
67
|
+
throw new Error('vs_session_open returned no session id');
|
|
68
|
+
}
|
|
69
|
+
return new Browser(client, sessionId, { ...DEFAULT_TIMEOUTS, ...options.timeouts }, options.inputMode ?? 'robotic', options.clickVia ?? (caps.flags.has('clickVia') ? 'act' : 'click-at'), {
|
|
70
|
+
actDeltas: options.protocol?.actDeltas ?? caps.flags.has('actDeltas'),
|
|
71
|
+
navInPlace: options.protocol?.navInPlace ?? caps.proto >= 1,
|
|
72
|
+
}, options.baseURL);
|
|
73
|
+
}
|
|
74
|
+
/** A new page in this session. Call page.goto(url) to load a URL. */
|
|
75
|
+
newPage() {
|
|
76
|
+
return new Page(this.client, this.sessionId, this.timeouts, this.inputMode, this.clickVia, this.protocol, this.baseURL);
|
|
77
|
+
}
|
|
78
|
+
/** Close the session and drop the connection. */
|
|
79
|
+
async close() {
|
|
80
|
+
await this.client.call('vs_session_close', [this.sessionId], {}).catch(() => { });
|
|
81
|
+
this.client.close();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAsB,MAAM,aAAa,CAAC;AAE7D,oEAAoE;AACpE,KAAK,UAAU,SAAS,CAAC,MAAkB;IACzC,MAAM,IAAI,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,EAAU,EAAE,CAAC;IACpD,IAAI,CAAC;QACH,M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CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,EACrE;YACE,SAAS,EAAE,OAAO,CAAC,QAAQ,EAAE,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC;YACrE,UAAU,EAAE,OAAO,CAAC,QAAQ,EAAE,UAAU,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC;SAC5D,EACD,OAAO,CAAC,OAAO,CAChB,CAAC;IACJ,CAAC;IAED,qEAAqE;IACrE,OAAO;QACL,OAAO,IAAI,IAAI,CACb,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,OAAO,CACb,CAAC;IACJ,CAAC;IAED,iDAAiD;IACjD,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACjF,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Socket client for the vibesurfer daemon.
|
|
3
|
+
*
|
|
4
|
+
* Speaks the line protocol over the Unix domain socket at
|
|
5
|
+
* `~/.vibesurfer/daemon.sock`. One connection, requests answered in
|
|
6
|
+
* order. Responses are read up to the blank-line terminator, mirroring
|
|
7
|
+
* `crates/vs-cli/src/client.rs` in the vibesurfer repo.
|
|
8
|
+
*
|
|
9
|
+
* If the socket is unreachable the client shells out once to the `vs`
|
|
10
|
+
* binary (which auto-spawns the daemon) and retries. The binary is
|
|
11
|
+
* resolved in this order: `options.vsCommand`, the `TESTSURFER_VS`
|
|
12
|
+
* environment variable, `vs` on PATH, `npx -y vibesurfer@<pinned>`.
|
|
13
|
+
*/
|
|
14
|
+
import { type Flags, type WireResponse } from './wire.ts';
|
|
15
|
+
/** The vibesurfer release testsurfer is built and tested against. */
|
|
16
|
+
export declare const PINNED_VIBESURFER = "0.2.14";
|
|
17
|
+
export interface ClientOptions {
|
|
18
|
+
/** Socket path. Default: `~/.vibesurfer/daemon.sock`. */
|
|
19
|
+
socketPath?: string;
|
|
20
|
+
/** Command used to reach the vs binary, e.g. `['vs']` or `['npx', '-y', 'vibesurfer@0.2.14']`. */
|
|
21
|
+
vsCommand?: string[];
|
|
22
|
+
/** Per-request timeout in ms. Default 70000 (above the daemon's 60s wait cap). */
|
|
23
|
+
requestTimeout?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface CallOptions {
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Number of extra blank-line-terminated body sections the daemon
|
|
29
|
+
* appends on success for this request (composites like
|
|
30
|
+
* `vs_view --layout=...`). Error envelopes never carry sections.
|
|
31
|
+
*/
|
|
32
|
+
extraSections?: number;
|
|
33
|
+
}
|
|
34
|
+
export declare function defaultSocketPath(): string;
|
|
35
|
+
export declare class WireClient {
|
|
36
|
+
private sock;
|
|
37
|
+
private buf;
|
|
38
|
+
private queue;
|
|
39
|
+
private current;
|
|
40
|
+
private closed;
|
|
41
|
+
private readonly opts;
|
|
42
|
+
private constructor();
|
|
43
|
+
static connect(opts?: ClientOptions): Promise<WireClient>;
|
|
44
|
+
private socketPath;
|
|
45
|
+
private ensureConnected;
|
|
46
|
+
private spawnDaemon;
|
|
47
|
+
private socketUp;
|
|
48
|
+
private attach;
|
|
49
|
+
private onData;
|
|
50
|
+
private onLine;
|
|
51
|
+
private finishResponse;
|
|
52
|
+
private failAll;
|
|
53
|
+
/**
|
|
54
|
+
* Send one request and await its response. Rejects with WireError on
|
|
55
|
+
* a `!` envelope, TimeoutError if the daemon does not answer in time.
|
|
56
|
+
*/
|
|
57
|
+
call(primitive: string, args?: string[], flags?: Flags, opts?: CallOptions): Promise<WireResponse>;
|
|
58
|
+
close(): void;
|
|
59
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Socket client for the vibesurfer daemon.
|
|
3
|
+
*
|
|
4
|
+
* Speaks the line protocol over the Unix domain socket at
|
|
5
|
+
* `~/.vibesurfer/daemon.sock`. One connection, requests answered in
|
|
6
|
+
* order. Responses are read up to the blank-line terminator, mirroring
|
|
7
|
+
* `crates/vs-cli/src/client.rs` in the vibesurfer repo.
|
|
8
|
+
*
|
|
9
|
+
* If the socket is unreachable the client shells out once to the `vs`
|
|
10
|
+
* binary (which auto-spawns the daemon) and retries. The binary is
|
|
11
|
+
* resolved in this order: `options.vsCommand`, the `TESTSURFER_VS`
|
|
12
|
+
* environment variable, `vs` on PATH, `npx -y vibesurfer@<pinned>`.
|
|
13
|
+
*/
|
|
14
|
+
import * as net from 'node:net';
|
|
15
|
+
import * as os from 'node:os';
|
|
16
|
+
import * as path from 'node:path';
|
|
17
|
+
import { execFile } from 'node:child_process';
|
|
18
|
+
import { WireError, TimeoutError } from "./errors.js";
|
|
19
|
+
import { encodeRequest, parseEnvelope, parseWarning, } from "./wire.js";
|
|
20
|
+
/** The vibesurfer release testsurfer is built and tested against. */
|
|
21
|
+
export const PINNED_VIBESURFER = '0.2.14';
|
|
22
|
+
export function defaultSocketPath() {
|
|
23
|
+
return path.join(os.homedir(), '.vibesurfer', 'daemon.sock');
|
|
24
|
+
}
|
|
25
|
+
function candidateCommands(opts) {
|
|
26
|
+
const out = [];
|
|
27
|
+
if (opts.vsCommand?.length)
|
|
28
|
+
out.push(opts.vsCommand);
|
|
29
|
+
const env = process.env['TESTSURFER_VS'];
|
|
30
|
+
if (env)
|
|
31
|
+
out.push(env.split(' ').filter(Boolean));
|
|
32
|
+
out.push(['vs']);
|
|
33
|
+
out.push(['npx', '-y', `vibesurfer@${PINNED_VIBESURFER}`]);
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
function runCommand(cmd, args, timeoutMs) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
const [bin, ...pre] = cmd;
|
|
39
|
+
if (!bin) {
|
|
40
|
+
reject(new Error('empty vs command'));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
execFile(bin, [...pre, ...args], { timeout: timeoutMs }, (err) => {
|
|
44
|
+
if (err)
|
|
45
|
+
reject(err);
|
|
46
|
+
else
|
|
47
|
+
resolve();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function connectOnce(socketPath) {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
const sock = net.connect(socketPath);
|
|
54
|
+
sock.once('connect', () => {
|
|
55
|
+
sock.removeAllListeners('error');
|
|
56
|
+
resolve(sock);
|
|
57
|
+
});
|
|
58
|
+
sock.once('error', (e) => reject(e));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
62
|
+
export class WireClient {
|
|
63
|
+
sock = null;
|
|
64
|
+
buf = '';
|
|
65
|
+
queue = [];
|
|
66
|
+
current = null;
|
|
67
|
+
closed = false;
|
|
68
|
+
opts;
|
|
69
|
+
constructor(opts) {
|
|
70
|
+
this.opts = opts;
|
|
71
|
+
}
|
|
72
|
+
static async connect(opts = {}) {
|
|
73
|
+
const client = new WireClient(opts);
|
|
74
|
+
await client.ensureConnected();
|
|
75
|
+
return client;
|
|
76
|
+
}
|
|
77
|
+
socketPath() {
|
|
78
|
+
return this.opts.socketPath ?? defaultSocketPath();
|
|
79
|
+
}
|
|
80
|
+
async ensureConnected() {
|
|
81
|
+
if (this.sock && !this.sock.destroyed)
|
|
82
|
+
return;
|
|
83
|
+
if (this.closed)
|
|
84
|
+
throw new Error('client closed');
|
|
85
|
+
try {
|
|
86
|
+
this.attach(await connectOnce(this.socketPath()));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// Socket missing or daemon down. Ask the CLI to auto-spawn it.
|
|
91
|
+
}
|
|
92
|
+
await this.spawnDaemon();
|
|
93
|
+
const deadline = Date.now() + 15_000;
|
|
94
|
+
let lastErr = new Error('daemon socket missing');
|
|
95
|
+
while (Date.now() < deadline) {
|
|
96
|
+
try {
|
|
97
|
+
this.attach(await connectOnce(this.socketPath()));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
lastErr = e;
|
|
102
|
+
await sleep(100);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
throw new Error(`cannot reach vibesurfer daemon at ${this.socketPath()}: ${String(lastErr)}`);
|
|
106
|
+
}
|
|
107
|
+
async spawnDaemon() {
|
|
108
|
+
let lastErr = null;
|
|
109
|
+
for (const cmd of candidateCommands(this.opts)) {
|
|
110
|
+
try {
|
|
111
|
+
// Any CLI call auto-spawns the daemon. `status` is the cheapest.
|
|
112
|
+
// The generous timeout covers a first-run npx download.
|
|
113
|
+
await runCommand(cmd, ['status'], 180_000);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
lastErr = e;
|
|
118
|
+
// node --test runs test files in parallel, so another process
|
|
119
|
+
// may be spawning the daemon right now and won the race (its
|
|
120
|
+
// npx install or socket bind made ours fail). Use its daemon.
|
|
121
|
+
if (await this.socketUp())
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const deadline = Date.now() + 10_000;
|
|
126
|
+
while (Date.now() < deadline) {
|
|
127
|
+
if (await this.socketUp())
|
|
128
|
+
return;
|
|
129
|
+
await sleep(250);
|
|
130
|
+
}
|
|
131
|
+
throw new Error(`could not start the vibesurfer daemon (tried vs, npx): ${String(lastErr)}`);
|
|
132
|
+
}
|
|
133
|
+
async socketUp() {
|
|
134
|
+
try {
|
|
135
|
+
(await connectOnce(this.socketPath())).destroy();
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
attach(sock) {
|
|
143
|
+
this.sock = sock;
|
|
144
|
+
this.buf = '';
|
|
145
|
+
this.current = null;
|
|
146
|
+
sock.setEncoding('utf8');
|
|
147
|
+
sock.on('data', (chunk) => this.onData(chunk));
|
|
148
|
+
sock.on('error', (e) => this.failAll(new Error(`daemon connection error: ${e.message}`)));
|
|
149
|
+
sock.on('close', () => {
|
|
150
|
+
if (this.queue.length > 0) {
|
|
151
|
+
this.failAll(new Error('daemon closed the connection'));
|
|
152
|
+
}
|
|
153
|
+
this.sock = null;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
onData(chunk) {
|
|
157
|
+
this.buf += chunk;
|
|
158
|
+
let nl;
|
|
159
|
+
while ((nl = this.buf.indexOf('\n')) >= 0) {
|
|
160
|
+
let line = this.buf.slice(0, nl);
|
|
161
|
+
this.buf = this.buf.slice(nl + 1);
|
|
162
|
+
if (line.endsWith('\r'))
|
|
163
|
+
line = line.slice(0, -1);
|
|
164
|
+
this.onLine(line);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
onLine(line) {
|
|
168
|
+
if (!this.current) {
|
|
169
|
+
this.current = {
|
|
170
|
+
warnings: [],
|
|
171
|
+
envelope: null,
|
|
172
|
+
body: [],
|
|
173
|
+
sections: [],
|
|
174
|
+
active: null,
|
|
175
|
+
sectionsWanted: 0,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const cur = this.current;
|
|
179
|
+
if (line === '') {
|
|
180
|
+
// Blank line before the envelope is noise. After the envelope it
|
|
181
|
+
// terminates the main body, then each expected extra section.
|
|
182
|
+
if (!cur.envelope)
|
|
183
|
+
return;
|
|
184
|
+
if (cur.active === null) {
|
|
185
|
+
if (cur.sectionsWanted > 0) {
|
|
186
|
+
cur.active = [];
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
this.finishResponse();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
cur.sections.push(cur.active);
|
|
193
|
+
if (cur.sections.length >= cur.sectionsWanted) {
|
|
194
|
+
cur.active = null;
|
|
195
|
+
this.finishResponse();
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
cur.active = [];
|
|
199
|
+
}
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (!cur.envelope) {
|
|
203
|
+
if (line.startsWith('?')) {
|
|
204
|
+
cur.warnings.push(parseWarning(line));
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
cur.envelope = parseEnvelope(line);
|
|
208
|
+
// Sections only follow success envelopes; the request at the
|
|
209
|
+
// queue head is the one being answered.
|
|
210
|
+
cur.sectionsWanted = cur.envelope.ok ? (this.queue[0]?.extraSections ?? 0) : 0;
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (cur.active !== null)
|
|
214
|
+
cur.active.push(line);
|
|
215
|
+
else
|
|
216
|
+
cur.body.push(line);
|
|
217
|
+
}
|
|
218
|
+
finishResponse() {
|
|
219
|
+
const cur = this.current;
|
|
220
|
+
this.current = null;
|
|
221
|
+
const pending = this.queue.shift();
|
|
222
|
+
if (!cur?.envelope || !pending)
|
|
223
|
+
return;
|
|
224
|
+
clearTimeout(pending.timer);
|
|
225
|
+
if (cur.envelope.ok) {
|
|
226
|
+
pending.resolve({
|
|
227
|
+
warnings: cur.warnings,
|
|
228
|
+
token: cur.envelope.token ?? '',
|
|
229
|
+
body: cur.body,
|
|
230
|
+
sections: cur.sections,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
pending.reject(new WireError(cur.envelope.code ?? 'UNKNOWN', cur.envelope.args ?? []));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
failAll(err) {
|
|
238
|
+
const pending = this.queue;
|
|
239
|
+
this.queue = [];
|
|
240
|
+
this.current = null;
|
|
241
|
+
for (const p of pending) {
|
|
242
|
+
clearTimeout(p.timer);
|
|
243
|
+
p.reject(err);
|
|
244
|
+
}
|
|
245
|
+
this.sock?.destroy();
|
|
246
|
+
this.sock = null;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Send one request and await its response. Rejects with WireError on
|
|
250
|
+
* a `!` envelope, TimeoutError if the daemon does not answer in time.
|
|
251
|
+
*/
|
|
252
|
+
async call(primitive, args = [], flags = {}, opts = {}) {
|
|
253
|
+
await this.ensureConnected();
|
|
254
|
+
const sock = this.sock;
|
|
255
|
+
if (!sock)
|
|
256
|
+
throw new Error('not connected');
|
|
257
|
+
const line = encodeRequest(primitive, args, flags);
|
|
258
|
+
const budget = opts.timeoutMs ?? this.opts.requestTimeout ?? 70_000;
|
|
259
|
+
return new Promise((resolve, reject) => {
|
|
260
|
+
const timer = setTimeout(() => {
|
|
261
|
+
// A timed-out call desyncs the response order; drop the
|
|
262
|
+
// connection so the next call starts clean.
|
|
263
|
+
this.failAll(new TimeoutError(`no response to ${primitive} within ${budget}ms`));
|
|
264
|
+
}, budget);
|
|
265
|
+
this.queue.push({ resolve, reject, timer, line, extraSections: opts.extraSections ?? 0 });
|
|
266
|
+
sock.write(line);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
close() {
|
|
270
|
+
this.closed = true;
|
|
271
|
+
this.failAll(new Error('client closed'));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO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Aa,EAAE,IAAI,CAAC,aAAa,IAAI,CAAC,EAAE,CAAC,CAAC;YAC1F,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK;QACH,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;IAC3C,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Errors thrown by testsurfer. */
|
|
2
|
+
/**
|
|
3
|
+
* A `! CODE args...` error envelope from the vibesurfer daemon.
|
|
4
|
+
* `code` is the wire error code (STALE_TOKEN, NOT_FOUND, BAD_REQUEST, ...);
|
|
5
|
+
* `args` are the space-separated arguments that followed it.
|
|
6
|
+
*/
|
|
7
|
+
export declare class WireError extends Error {
|
|
8
|
+
readonly code: string;
|
|
9
|
+
readonly args: string[];
|
|
10
|
+
constructor(code: string, args: string[]);
|
|
11
|
+
}
|
|
12
|
+
/** An action or assertion did not complete within its timeout. */
|
|
13
|
+
export declare class TimeoutError extends Error {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A locator matched more than one element. Mirrors Playwright's strict
|
|
18
|
+
* mode: an action needs exactly one target. Narrow the locator or pick
|
|
19
|
+
* one with `.first()` / `.nth(i)`.
|
|
20
|
+
*/
|
|
21
|
+
export declare class StrictModeError extends Error {
|
|
22
|
+
constructor(message: string);
|
|
23
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Errors thrown by testsurfer. */
|
|
2
|
+
/**
|
|
3
|
+
* A `! CODE args...` error envelope from the vibesurfer daemon.
|
|
4
|
+
* `code` is the wire error code (STALE_TOKEN, NOT_FOUND, BAD_REQUEST, ...);
|
|
5
|
+
* `args` are the space-separated arguments that followed it.
|
|
6
|
+
*/
|
|
7
|
+
export class WireError extends Error {
|
|
8
|
+
code;
|
|
9
|
+
args;
|
|
10
|
+
constructor(code, args) {
|
|
11
|
+
super(`vibesurfer error: ${code}${args.length ? ' ' + args.join(' ') : ''}`);
|
|
12
|
+
this.name = 'WireError';
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.args = args;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** An action or assertion did not complete within its timeout. */
|
|
18
|
+
export class TimeoutError extends Error {
|
|
19
|
+
constructor(message) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = 'TimeoutError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A locator matched more than one element. Mirrors Playwright's strict
|
|
26
|
+
* mode: an action needs exactly one target. Narrow the locator or pick
|
|
27
|
+
* one with `.first()` / `.nth(i)`.
|
|
28
|
+
*/
|
|
29
|
+
export class StrictModeError extends Error {
|
|
30
|
+
constructor(message) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.name = 'StrictModeError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC;;;;GAIG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IACzB,IAAI,CAAS;IACb,IAAI,CAAW;IAExB,YAAY,IAAY,EAAE,IAAc;QACtC,KAAK,CAAC,qBAAqB,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7E,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,kEAAkE;AAClE,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF"}
|
package/dist/expect.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web-first assertions. Every matcher polls against fresh views until
|
|
3
|
+
* it passes or the expect timeout elapses, so tests never race the
|
|
4
|
+
* page. Negate with `.not`.
|
|
5
|
+
*/
|
|
6
|
+
import { Locator } from './locator.ts';
|
|
7
|
+
import { Page } from './page.ts';
|
|
8
|
+
export interface ExpectOptions {
|
|
9
|
+
timeout?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class LocatorAssertions {
|
|
12
|
+
private readonly locator;
|
|
13
|
+
private readonly negated;
|
|
14
|
+
private readonly defaultTimeout;
|
|
15
|
+
constructor(locator: Locator, negated?: boolean, defaultTimeout?: number);
|
|
16
|
+
get not(): LocatorAssertions;
|
|
17
|
+
private budget;
|
|
18
|
+
private msg;
|
|
19
|
+
/** At least one visible match. */
|
|
20
|
+
toBeVisible(options?: ExpectOptions): Promise<void>;
|
|
21
|
+
/** No visible match. */
|
|
22
|
+
toBeHidden(options?: ExpectOptions): Promise<void>;
|
|
23
|
+
/** The element's full text equals the expected string (or matches the RegExp). */
|
|
24
|
+
toHaveText(expected: string | RegExp, options?: ExpectOptions): Promise<void>;
|
|
25
|
+
/** The element's full text contains the expected substring (or matches the RegExp). */
|
|
26
|
+
toContainText(expected: string | RegExp, options?: ExpectOptions): Promise<void>;
|
|
27
|
+
private textAssertion;
|
|
28
|
+
/** A checked checkbox or radio (vibesurfer 0.2.12+). */
|
|
29
|
+
toBeChecked(options?: ExpectOptions): Promise<void>;
|
|
30
|
+
/** A text field or select whose current value equals the string (or matches the RegExp). */
|
|
31
|
+
toHaveValue(expected: string | RegExp, options?: ExpectOptions): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* The element's accessibility subtree matches a template. See
|
|
34
|
+
* src/aria.ts for the format; `locator.ariaSnapshot()` prints the
|
|
35
|
+
* current tree in it, ready to paste and trim.
|
|
36
|
+
*/
|
|
37
|
+
toMatchAriaSnapshot(template: string, options?: ExpectOptions): Promise<void>;
|
|
38
|
+
/** Exactly `count` matches. */
|
|
39
|
+
toHaveCount(count: number, options?: ExpectOptions): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export declare class PageAssertions {
|
|
42
|
+
private readonly page;
|
|
43
|
+
private readonly negated;
|
|
44
|
+
private readonly defaultTimeout;
|
|
45
|
+
constructor(page: Page, negated?: boolean, defaultTimeout?: number);
|
|
46
|
+
get not(): PageAssertions;
|
|
47
|
+
/** The page URL equals the string (or matches the RegExp). */
|
|
48
|
+
toHaveURL(expected: string | RegExp, options?: ExpectOptions): Promise<void>;
|
|
49
|
+
/** The whole page's accessibility tree matches a template (see LocatorAssertions.toMatchAriaSnapshot). */
|
|
50
|
+
toMatchAriaSnapshot(template: string, options?: ExpectOptions): Promise<void>;
|
|
51
|
+
/** The document title equals the string (or matches the RegExp). */
|
|
52
|
+
toHaveTitle(expected: string | RegExp, options?: ExpectOptions): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
export declare function expect(target: Locator): LocatorAssertions;
|
|
55
|
+
export declare function expect(target: Page): PageAssertions;
|