@flowspec-qa/runner-core 0.2.4 → 0.4.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/api-client.d.ts +87 -10
- package/dist/api-client.d.ts.map +1 -1
- package/dist/api-client.js +108 -7
- package/dist/api-client.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +4 -3
- package/dist/auth.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -1
- package/dist/config.js.map +1 -1
- package/dist/discovery-report.d.ts +13 -0
- package/dist/discovery-report.d.ts.map +1 -0
- package/dist/discovery-report.js +977 -0
- package/dist/discovery-report.js.map +1 -0
- package/dist/discovery.d.ts +213 -3
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +2125 -264
- package/dist/discovery.js.map +1 -1
- package/dist/evidence-corpus.d.ts +338 -0
- package/dist/evidence-corpus.d.ts.map +1 -0
- package/dist/evidence-corpus.js +927 -0
- package/dist/evidence-corpus.js.map +1 -0
- package/dist/evidence-types.d.ts +230 -0
- package/dist/evidence-types.d.ts.map +1 -0
- package/dist/evidence-types.js +24 -0
- package/dist/evidence-types.js.map +1 -0
- package/dist/executor.d.ts +1 -0
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +93 -195
- package/dist/executor.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/suite-manager.d.ts +6 -0
- package/dist/suite-manager.d.ts.map +1 -1
- package/dist/suite-manager.js +55 -2
- package/dist/suite-manager.js.map +1 -1
- package/package.json +4 -1
- package/src/api-client.ts +0 -170
- package/src/auth.ts +0 -45
- package/src/backup-manager.ts +0 -63
- package/src/config.ts +0 -52
- package/src/devices.ts +0 -196
- package/src/discovery.ts +0 -563
- package/src/executor.ts +0 -681
- package/src/index.ts +0 -11
- package/src/result-sanitizer.ts +0 -60
- package/src/suite-manager.ts +0 -73
- package/src/uploader.ts +0 -74
- package/tsconfig.json +0 -8
package/src/executor.ts
DELETED
|
@@ -1,681 +0,0 @@
|
|
|
1
|
-
import { execa, ExecaError } from 'execa';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { existsSync, mkdtempSync, cpSync } from 'fs';
|
|
5
|
-
import { tmpdir } from 'os';
|
|
6
|
-
import type { TestResultItem } from './api-client.js';
|
|
7
|
-
import type { DeviceInfo } from './devices.js';
|
|
8
|
-
|
|
9
|
-
// ─── Multi-device result ─────────────────────────────────────────────────────
|
|
10
|
-
|
|
11
|
-
export interface DeviceResult {
|
|
12
|
-
device: DeviceInfo;
|
|
13
|
-
execution: ExecutionResult;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface ExecutionOptions {
|
|
17
|
-
env?: Record<string, string>; // Environment vars (base URLs, tokens — stay local, never uploaded)
|
|
18
|
-
timeout?: number; // ms, default 10 min
|
|
19
|
-
workers?: number; // Playwright workers
|
|
20
|
-
headed?: boolean; // Run headed (useful for debugging)
|
|
21
|
-
reporter?: string; // Playwright reporter override
|
|
22
|
-
grepPattern?: string; // Run only matching tests
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface ExecutionResult {
|
|
26
|
-
exitCode: number;
|
|
27
|
-
results: TestResultItem[];
|
|
28
|
-
startedAt: Date;
|
|
29
|
-
finishedAt: Date;
|
|
30
|
-
stdout: string;
|
|
31
|
-
stderr: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Execute a Playwright test suite and parse the results.
|
|
36
|
-
*/
|
|
37
|
-
export async function executePlaywright(
|
|
38
|
-
suiteDir: string,
|
|
39
|
-
options: ExecutionOptions = {}
|
|
40
|
-
): Promise<ExecutionResult> {
|
|
41
|
-
const startedAt = new Date();
|
|
42
|
-
|
|
43
|
-
// Install deps if node_modules missing
|
|
44
|
-
if (!isNodeModulesPresent(suiteDir)) {
|
|
45
|
-
await execa('npm', ['install', '--prefer-offline'], {
|
|
46
|
-
cwd: suiteDir,
|
|
47
|
-
env: { ...process.env, ...(options.env ?? {}) },
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const args = ['playwright', 'test',
|
|
52
|
-
'--reporter=json',
|
|
53
|
-
...(options.workers ? [`--workers=${options.workers}`] : []),
|
|
54
|
-
...(options.headed ? ['--headed'] : []),
|
|
55
|
-
...(options.grepPattern ? [`--grep`, options.grepPattern] : []),
|
|
56
|
-
];
|
|
57
|
-
|
|
58
|
-
let stdout = '';
|
|
59
|
-
let stderr = '';
|
|
60
|
-
let exitCode = 0;
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
const result = await execa('npx', args, {
|
|
64
|
-
cwd: suiteDir,
|
|
65
|
-
env: { ...process.env, ...(options.env ?? {}) },
|
|
66
|
-
timeout: options.timeout ?? 600_000,
|
|
67
|
-
reject: false, // don't throw on test failures
|
|
68
|
-
});
|
|
69
|
-
stdout = result.stdout;
|
|
70
|
-
stderr = result.stderr;
|
|
71
|
-
exitCode = result.exitCode ?? 1;
|
|
72
|
-
} catch (err) {
|
|
73
|
-
const e = err as ExecaError;
|
|
74
|
-
stdout = e.stdout ?? '';
|
|
75
|
-
stderr = e.stderr ?? e.message;
|
|
76
|
-
exitCode = e.exitCode ?? 1;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const finishedAt = new Date();
|
|
80
|
-
const results = parsePlaywrightJson(stdout);
|
|
81
|
-
|
|
82
|
-
return { exitCode, results, startedAt, finishedAt, stdout, stderr };
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Execute a Cypress test suite.
|
|
87
|
-
*/
|
|
88
|
-
export async function executeCypress(
|
|
89
|
-
suiteDir: string,
|
|
90
|
-
options: ExecutionOptions = {}
|
|
91
|
-
): Promise<ExecutionResult> {
|
|
92
|
-
const startedAt = new Date();
|
|
93
|
-
|
|
94
|
-
if (!isNodeModulesPresent(suiteDir)) {
|
|
95
|
-
await execa('npm', ['install', '--prefer-offline'], { cwd: suiteDir });
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const args = ['cypress', 'run', '--reporter=json',
|
|
99
|
-
...(options.headed ? ['--headed'] : ['--headless']),
|
|
100
|
-
];
|
|
101
|
-
|
|
102
|
-
let stdout = '';
|
|
103
|
-
let stderr = '';
|
|
104
|
-
let exitCode = 0;
|
|
105
|
-
|
|
106
|
-
try {
|
|
107
|
-
const result = await execa('npx', args, {
|
|
108
|
-
cwd: suiteDir,
|
|
109
|
-
env: { ...process.env, ...(options.env ?? {}) },
|
|
110
|
-
timeout: options.timeout ?? 600_000,
|
|
111
|
-
reject: false,
|
|
112
|
-
});
|
|
113
|
-
stdout = result.stdout;
|
|
114
|
-
stderr = result.stderr;
|
|
115
|
-
exitCode = result.exitCode ?? 1;
|
|
116
|
-
} catch (err) {
|
|
117
|
-
const e = err as ExecaError;
|
|
118
|
-
stdout = e.stdout ?? '';
|
|
119
|
-
stderr = e.stderr ?? e.message;
|
|
120
|
-
exitCode = e.exitCode ?? 1;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const finishedAt = new Date();
|
|
124
|
-
return { exitCode, results: parseCypressJson(stdout), startedAt, finishedAt, stdout, stderr };
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// ─── Parsers ─────────────────────────────────────────────────────────────────
|
|
128
|
-
|
|
129
|
-
function parsePlaywrightJson(stdout: string): TestResultItem[] {
|
|
130
|
-
try {
|
|
131
|
-
// Playwright --reporter=json outputs JSON on stdout
|
|
132
|
-
const json = extractJson(stdout);
|
|
133
|
-
if (!json) return [];
|
|
134
|
-
const suites = json.suites ?? [];
|
|
135
|
-
const items: TestResultItem[] = [];
|
|
136
|
-
collectPlaywrightSpecs(suites, items);
|
|
137
|
-
return items;
|
|
138
|
-
} catch {
|
|
139
|
-
return [];
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function collectPlaywrightSpecs(suites: any[], items: TestResultItem[]): void {
|
|
144
|
-
for (const suite of suites) {
|
|
145
|
-
for (const spec of suite.specs ?? []) {
|
|
146
|
-
for (const test of spec.tests ?? []) {
|
|
147
|
-
const result = test.results?.[0];
|
|
148
|
-
items.push({
|
|
149
|
-
name: spec.title,
|
|
150
|
-
status: result?.status === 'passed' ? 'pass' : result?.status === 'skipped' ? 'skip' : 'fail',
|
|
151
|
-
duration_ms: result?.duration ?? 0,
|
|
152
|
-
error: result?.error?.message ?? null,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
collectPlaywrightSpecs(suite.suites ?? [], items);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function parseCypressJson(stdout: string): TestResultItem[] {
|
|
161
|
-
try {
|
|
162
|
-
const json = extractJson(stdout);
|
|
163
|
-
if (!json) return [];
|
|
164
|
-
return (json.results ?? []).flatMap((r: any) =>
|
|
165
|
-
(r.tests ?? []).map((t: any) => ({
|
|
166
|
-
name: t.fullTitle ?? t.title,
|
|
167
|
-
status: t.state === 'passed' ? 'pass' : t.state === 'pending' ? 'skip' : 'fail',
|
|
168
|
-
duration_ms: t.duration ?? 0,
|
|
169
|
-
error: t.err?.message ?? null,
|
|
170
|
-
}))
|
|
171
|
-
);
|
|
172
|
-
} catch {
|
|
173
|
-
return [];
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function extractJson(text: string): any | null {
|
|
178
|
-
const match = text.match(/\{[\s\S]*\}/);
|
|
179
|
-
if (!match) return null;
|
|
180
|
-
return JSON.parse(match[0]);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function isNodeModulesPresent(dir: string): boolean {
|
|
184
|
-
return existsSync(path.join(dir, 'node_modules'));
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Execute a Maestro test suite (iOS/Android YAML flows) and parse JUnit XML results.
|
|
189
|
-
* Requires: Maestro CLI installed globally (`curl -Ls 'https://get.maestro.mobile.dev' | bash`)
|
|
190
|
-
* No npm install step — Maestro uses its own runtime.
|
|
191
|
-
*/
|
|
192
|
-
export async function executeMaestro(
|
|
193
|
-
suiteDir: string,
|
|
194
|
-
options: ExecutionOptions = {}
|
|
195
|
-
): Promise<ExecutionResult> {
|
|
196
|
-
const startedAt = new Date();
|
|
197
|
-
const reportPath = path.join(suiteDir, 'report.xml');
|
|
198
|
-
const flowsDir = path.join(suiteDir, 'flows');
|
|
199
|
-
|
|
200
|
-
// Pre-flight: check that Maestro CLI is installed
|
|
201
|
-
try {
|
|
202
|
-
await execa('maestro', ['--version'], { reject: true, timeout: 5000 });
|
|
203
|
-
} catch {
|
|
204
|
-
return {
|
|
205
|
-
exitCode: 127,
|
|
206
|
-
results: [{
|
|
207
|
-
name: 'maestro_cli_check',
|
|
208
|
-
status: 'fail' as const,
|
|
209
|
-
duration_ms: 0,
|
|
210
|
-
error: 'Maestro CLI not found. Install with: curl -Ls "https://get.maestro.mobile.dev" | bash',
|
|
211
|
-
}],
|
|
212
|
-
startedAt,
|
|
213
|
-
finishedAt: new Date(),
|
|
214
|
-
stdout: '',
|
|
215
|
-
stderr: 'Maestro CLI not installed or not in PATH.',
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const targetDir = existsSync(flowsDir) ? flowsDir : suiteDir;
|
|
220
|
-
|
|
221
|
-
// Auto-heal malformed LLM YAMLs before running
|
|
222
|
-
try {
|
|
223
|
-
const fsMod = await import('fs');
|
|
224
|
-
|
|
225
|
-
// Read APP_ID from .maestro.env for Expo Go detection
|
|
226
|
-
let resolvedAppId = options.env?.APP_ID ?? '';
|
|
227
|
-
const maestroEnvPath = path.join(suiteDir, '.maestro.env');
|
|
228
|
-
if (!resolvedAppId && fsMod.existsSync(maestroEnvPath)) {
|
|
229
|
-
const envContent = fsMod.readFileSync(maestroEnvPath, 'utf8');
|
|
230
|
-
const match = envContent.match(/^APP_ID=(.+)$/m);
|
|
231
|
-
if (match) resolvedAppId = match[1].trim();
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Fallback: search for Expo Go signature in ALL YAML files
|
|
235
|
-
let isExpoGo = resolvedAppId === 'host.exp.Exponent' || existsSync(path.join(suiteDir, 'expo'));
|
|
236
|
-
if (!isExpoGo && fsMod.existsSync(targetDir)) {
|
|
237
|
-
const allFiles = fsMod.readdirSync(targetDir).filter(f => f.endsWith('.yaml'));
|
|
238
|
-
for (const f of allFiles) {
|
|
239
|
-
const content = fsMod.readFileSync(path.join(targetDir, f), 'utf8');
|
|
240
|
-
if (content.includes('exp://') || content.includes('host.exp.Exponent')) {
|
|
241
|
-
isExpoGo = true;
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (fsMod.existsSync(targetDir)) {
|
|
248
|
-
const files = fsMod.readdirSync(targetDir);
|
|
249
|
-
for (const file of files) {
|
|
250
|
-
if (file.endsWith('.yaml') || file.endsWith('.yml')) {
|
|
251
|
-
const fp = path.join(targetDir, file);
|
|
252
|
-
if (!fsMod.existsSync(fp)) continue; // Skip if already deleted (e.g. subflow)
|
|
253
|
-
let content = fsMod.readFileSync(fp, 'utf8');
|
|
254
|
-
let changed = false;
|
|
255
|
-
|
|
256
|
-
// ── Maestro compatibility shim ──────────────────────────────
|
|
257
|
-
// Fix invalid commands generated by the AI that Maestro does not support
|
|
258
|
-
|
|
259
|
-
// Ensure clearState: true so each test starts from a clean session.
|
|
260
|
-
// Without it, app state persists between tests (SharedPreferences)
|
|
261
|
-
// causing subsequent tests to skip the login screen entirely.
|
|
262
|
-
if (/^- launchApp\s*$/m.test(content)) {
|
|
263
|
-
content = content.replace(/^- launchApp\s*$/gm, '- launchApp:\n clearState: true');
|
|
264
|
-
changed = true;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (content.includes('- typeText:')) {
|
|
268
|
-
// `typeText` → `inputText` (correct Maestro command)
|
|
269
|
-
content = content.replace(/^- typeText:/gm, '- inputText:');
|
|
270
|
-
changed = true;
|
|
271
|
-
}
|
|
272
|
-
if (content.includes('- clearText')) {
|
|
273
|
-
// `clearText` → `eraseText: 50` (erases up to 50 chars from focused field)
|
|
274
|
-
content = content.replace(/^- clearText\s*$/gm, '- eraseText: 50');
|
|
275
|
-
changed = true;
|
|
276
|
-
}
|
|
277
|
-
if (content.includes('- toggleAirplaneMode')) {
|
|
278
|
-
// `toggleAirplaneMode` is not a valid Maestro command — skip gracefully
|
|
279
|
-
content = content.replace(/^- toggleAirplaneMode\s*$/gm, '# toggleAirplaneMode skipped — not supported in this Maestro version');
|
|
280
|
-
changed = true;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (isExpoGo) {
|
|
284
|
-
// Expo Go is handled below in a separate two-pass approach
|
|
285
|
-
changed = true; // placeholder, actual processing below
|
|
286
|
-
} else {
|
|
287
|
-
// Native app strategy: ensure appId, separator, and launchApp
|
|
288
|
-
if (!content.trimStart().startsWith('appId:')) {
|
|
289
|
-
// Remove any existing appId that might be hidden deeper (rare but possible with LLMs)
|
|
290
|
-
content = content.replace(/^appId:.*?\n/gm, '');
|
|
291
|
-
content = content.replace(/^---\n/gm, '');
|
|
292
|
-
|
|
293
|
-
content = 'appId: ${APP_ID}\n---\n' + content.trimStart();
|
|
294
|
-
changed = true;
|
|
295
|
-
} else if (!content.includes('---')) {
|
|
296
|
-
content = content.replace(/(appId:.*?\n)/g, '$1---\n');
|
|
297
|
-
changed = true;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
if (!content.includes('- launchApp')) {
|
|
301
|
-
const separatorIndex = content.indexOf('---\n');
|
|
302
|
-
if (separatorIndex !== -1) {
|
|
303
|
-
content = content.slice(0, separatorIndex + 4) + '- launchApp\n' + content.slice(separatorIndex + 4);
|
|
304
|
-
changed = true;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// 2. Fix scrollUntilVisible missing 'element' and handle 'back'
|
|
310
|
-
if (content.includes('scrollUntilVisible:')) {
|
|
311
|
-
const oldContent = content;
|
|
312
|
-
content = content.replace(/(- scrollUntilVisible:\n\s+)(text|id):/g, '$1element:\n $2:');
|
|
313
|
-
if (content !== oldContent) changed = true;
|
|
314
|
-
}
|
|
315
|
-
const backMatch = content.match(/^(\s*)-\s*back\s*$/m);
|
|
316
|
-
if (backMatch) {
|
|
317
|
-
const indent = backMatch[1] !== undefined ? backMatch[1] : '';
|
|
318
|
-
content = content.replace(/^\s*-\s*back\s*$/gm, `${indent}- tapOn:\n${indent} id: 'back_button'`);
|
|
319
|
-
changed = true;
|
|
320
|
-
}
|
|
321
|
-
if (content.includes('- tapOn: {text: \'Volver\'}')) {
|
|
322
|
-
content = content.replace(/- tapOn: {text: \'Volver\'}/g, '- tapOn: {id: \'back_button\'}');
|
|
323
|
-
changed = true;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// 3. Remove Cypress.env corruption and add generic waits
|
|
327
|
-
if (content.includes('inputText:')) {
|
|
328
|
-
content = content.replace(/(inputText:.*?\n)/g, '$1- waitForAnimationToEnd\n');
|
|
329
|
-
changed = true;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// ── Keyboard dismiss shim ────────────────────────────────────
|
|
333
|
-
// On Android the soft keyboard covers fields below the focused input.
|
|
334
|
-
// After every inputText → waitForAnimationToEnd sequence, inject
|
|
335
|
-
// `- hideKeyboard` so the next tapOn can reach the covered element.
|
|
336
|
-
// hideKeyboard is a no-op when the keyboard is not shown.
|
|
337
|
-
if (content.includes('- inputText:')) {
|
|
338
|
-
const kbLines = content.split('\n');
|
|
339
|
-
const kbPatched: string[] = [];
|
|
340
|
-
let afterInputText = false;
|
|
341
|
-
for (const kbLine of kbLines) {
|
|
342
|
-
const kbTrimmed = kbLine.trim();
|
|
343
|
-
if (kbTrimmed === '- waitForAnimationToEnd' && afterInputText) {
|
|
344
|
-
kbPatched.push(kbLine);
|
|
345
|
-
kbPatched.push('- hideKeyboard');
|
|
346
|
-
afterInputText = false;
|
|
347
|
-
changed = true;
|
|
348
|
-
} else {
|
|
349
|
-
kbPatched.push(kbLine);
|
|
350
|
-
if (kbTrimmed.startsWith('- inputText:')) {
|
|
351
|
-
afterInputText = true;
|
|
352
|
-
} else if (kbTrimmed !== '' && !kbTrimmed.startsWith('#') && !kbTrimmed.startsWith('- waitForAnimationToEnd')) {
|
|
353
|
-
afterInputText = false;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
content = kbPatched.join('\n');
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (content.includes('Cypress.env')) {
|
|
361
|
-
content = content.replace(/Cypress.env\(.*?\)/g, "test_password");
|
|
362
|
-
changed = true;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// 4. ROBUST SELECTORS: Convert text labels to IDs
|
|
366
|
-
const textToIdMap: Record<string, string> = {
|
|
367
|
-
"Login": "login_header",
|
|
368
|
-
"Acceso": "login_header",
|
|
369
|
-
"Iniciar sesión": "login_button",
|
|
370
|
-
"Iniciar Sesión": "login_button",
|
|
371
|
-
"Entrar": "login_button",
|
|
372
|
-
"Username": "username_input",
|
|
373
|
-
"Usuario": "username_input",
|
|
374
|
-
"Password": "password_input",
|
|
375
|
-
"Contraseña": "password_input",
|
|
376
|
-
"test_password": "password_input",
|
|
377
|
-
"Nueva tarea": "new_task_button",
|
|
378
|
-
"Crear tarea": "crear_tarea_header",
|
|
379
|
-
"Título": "task_title_input",
|
|
380
|
-
"Nombre de la tarea": "task_title_input",
|
|
381
|
-
"Descripción": "task_desc_input",
|
|
382
|
-
"Detalles de la tarea": "task_desc_input",
|
|
383
|
-
"Fecha límite": "task_date_input",
|
|
384
|
-
"Mis Tareas": "home_header",
|
|
385
|
-
"Guardar": "save_task_button",
|
|
386
|
-
"Eliminar": "delete_task_button",
|
|
387
|
-
"Confirmar": "confirm_delete_button",
|
|
388
|
-
"Completadas": "completadas_header",
|
|
389
|
-
"Volver": "back_button",
|
|
390
|
-
"Marcar completada": "complete_task_button",
|
|
391
|
-
"Detalle de Tarea": "task_detail_header",
|
|
392
|
-
"Comprar leche": "Comprar leche",
|
|
393
|
-
"Tarea para borrar online": "Tarea para borrar online",
|
|
394
|
-
"El título debe tener al menos 3 caracteres": "title_error",
|
|
395
|
-
"La fecha límite no puede ser anterior a hoy": "date_error"
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
for (const [text, id] of Object.entries(textToIdMap)) {
|
|
399
|
-
const regex = new RegExp(`text:\\s*['"]?${text}['"]?`, 'gi');
|
|
400
|
-
if (regex.test(content)) {
|
|
401
|
-
content = content.replace(regex, `id: '${id}'`);
|
|
402
|
-
changed = true;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
if (changed) fsMod.writeFileSync(fp, content);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// === EXPO GO PROCESSING ===
|
|
411
|
-
if (isExpoGo) {
|
|
412
|
-
const yamlFiles = fsMod.readdirSync(targetDir)
|
|
413
|
-
.filter((f: string) => (f.endsWith('.yaml') || f.endsWith('.yml')));
|
|
414
|
-
|
|
415
|
-
// Pass 1: Identify and cache subflow contents
|
|
416
|
-
const subflowNames = new Set<string>();
|
|
417
|
-
const subflowCache = new Map<string, string>();
|
|
418
|
-
for (const f of yamlFiles) {
|
|
419
|
-
const c = fsMod.readFileSync(path.join(targetDir, f), 'utf8');
|
|
420
|
-
const matches = c.match(/-\s*runFlow:\s*(\S+\.ya?ml)/g) || [];
|
|
421
|
-
for (const m of matches) {
|
|
422
|
-
const sfName = m.replace(/-\s*runFlow:\s*/, '').trim();
|
|
423
|
-
const sfPath = path.join(targetDir, sfName);
|
|
424
|
-
if (fsMod.existsSync(sfPath) && !subflowCache.has(sfName)) {
|
|
425
|
-
let sfContent = fsMod.readFileSync(sfPath, 'utf8');
|
|
426
|
-
sfContent = sfContent
|
|
427
|
-
.replace(/^appId:.*\n/gm, '').replace(/^---\n/gm, '').replace(/^- launchApp.*\n/gm, '')
|
|
428
|
-
.replace(/^- clearState.*\n/gm, '').replace(/^- openLink:.*\n/gm, '').replace(/^#.*\n/gm, '')
|
|
429
|
-
.replace(/^\s*$/gm, '').trim();
|
|
430
|
-
subflowCache.set(sfName, sfContent);
|
|
431
|
-
}
|
|
432
|
-
subflowNames.add(sfName);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
for (const f of yamlFiles) {
|
|
437
|
-
const fp = path.join(targetDir, f);
|
|
438
|
-
let c = fsMod.readFileSync(fp, 'utf8');
|
|
439
|
-
|
|
440
|
-
// 1. Inline subflows from cache
|
|
441
|
-
const matches = c.match(/-\s*runFlow:\s*(\S+\.ya?ml)/g) || [];
|
|
442
|
-
for (const m of matches) {
|
|
443
|
-
const sfName = m.replace(/-\s*runFlow:\s*/, '').trim();
|
|
444
|
-
const sfContent = subflowCache.get(sfName);
|
|
445
|
-
if (sfContent) {
|
|
446
|
-
c = c.replace(m, sfContent);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// 2. Ensure Expo Go Header ONLY for main flows
|
|
451
|
-
if (!subflowNames.has(f)) {
|
|
452
|
-
c = c.replace(/^appId:.*\n/gm, '').replace(/^---\n/gm, '').replace(/^- launchApp.*\n/gm, '').replace(/^- clearState.*\n/gm, '').replace(/^- openLink:.*\n/gm, '').trimStart();
|
|
453
|
-
const header = 'appId: host.exp.Exponent\n---\n- clearState\n- openLink: exp://127.0.0.1:8081\n- extendedWaitUntil:\n visible:\n text: Login\n timeout: 60000\n\n';
|
|
454
|
-
c = header + c;
|
|
455
|
-
} else {
|
|
456
|
-
// It IS a subflow: do NOT wipe the header on disk just yet.
|
|
457
|
-
// Maestro might try to scan/parse it before it's deleted.
|
|
458
|
-
// The inlined content used in Pass 2 was already cleaned in Pass 1.
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
fsMod.writeFileSync(fp, c, 'utf8');
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
// Pass 3: Finally delete all subflow files
|
|
465
|
-
for (const sfName of subflowCache.keys()) {
|
|
466
|
-
try { fsMod.unlinkSync(path.join(targetDir, sfName)); } catch (e) {}
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
// Copy .maestro.env into targetDir so Maestro can evaluate env vars properly
|
|
471
|
-
const rootEnvPath = path.join(suiteDir, '.maestro.env');
|
|
472
|
-
const targetEnvPath = path.join(targetDir, '.maestro.env');
|
|
473
|
-
if (targetDir !== suiteDir && fsMod.existsSync(rootEnvPath)) {
|
|
474
|
-
fsMod.copyFileSync(rootEnvPath, targetEnvPath);
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
}
|
|
478
|
-
} catch (e) {}
|
|
479
|
-
|
|
480
|
-
// Device targeting: --device flag must come BEFORE the 'test' subcommand
|
|
481
|
-
const deviceId = options.env?._FLOWSPECQA_DEVICE_ID;
|
|
482
|
-
const maestroBaseArgs = deviceId ? ['--device', deviceId] : [];
|
|
483
|
-
|
|
484
|
-
const args = [
|
|
485
|
-
...maestroBaseArgs,
|
|
486
|
-
'test',
|
|
487
|
-
'--format', 'junit',
|
|
488
|
-
'--output', reportPath,
|
|
489
|
-
];
|
|
490
|
-
|
|
491
|
-
// Manually parse .maestro.env and pass as -e arguments because Maestro CLI's automatic picking can be flaky
|
|
492
|
-
const fsMod = await import('fs');
|
|
493
|
-
const envFilePath = path.join(suiteDir, '.maestro.env');
|
|
494
|
-
if (fsMod.existsSync(envFilePath)) {
|
|
495
|
-
const lines = fsMod.readFileSync(envFilePath, 'utf8').split('\n');
|
|
496
|
-
for (const line of lines) {
|
|
497
|
-
const trimmed = line.trim();
|
|
498
|
-
if (trimmed && !trimmed.startsWith('#') && trimmed.includes('=')) {
|
|
499
|
-
args.push('-e', trimmed);
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
args.push(targetDir);
|
|
505
|
-
|
|
506
|
-
let stdout = '';
|
|
507
|
-
let stderr = '';
|
|
508
|
-
let exitCode = 0;
|
|
509
|
-
|
|
510
|
-
// Pre-launch Expo Go bundle before running tests
|
|
511
|
-
// Detect Expo Go from options.env OR from .maestro.env file
|
|
512
|
-
let prelaunchAppId = options.env?.APP_ID ?? '';
|
|
513
|
-
if (!prelaunchAppId) {
|
|
514
|
-
const fsPre = await import('fs');
|
|
515
|
-
const envPath = path.join(suiteDir, '.maestro.env');
|
|
516
|
-
if (fsPre.existsSync(envPath)) {
|
|
517
|
-
const envContent = fsPre.readFileSync(envPath, 'utf8');
|
|
518
|
-
const m = envContent.match(/^APP_ID=(.+)$/m);
|
|
519
|
-
if (m) prelaunchAppId = m[1].trim();
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
if (prelaunchAppId === 'host.exp.Exponent') {
|
|
523
|
-
try {
|
|
524
|
-
await execa('xcrun', ['simctl', 'openurl', 'booted', 'exp://127.0.0.1:8081'], {
|
|
525
|
-
timeout: 15000,
|
|
526
|
-
reject: false,
|
|
527
|
-
});
|
|
528
|
-
// Wait for Metro bundler to load the JS bundle (increased for older devices/simulators)
|
|
529
|
-
await new Promise(resolve => setTimeout(resolve, 20000));
|
|
530
|
-
} catch {}
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
try {
|
|
534
|
-
const proc = await execa('maestro', args, {
|
|
535
|
-
cwd: suiteDir,
|
|
536
|
-
env: { ...process.env, ...(options.env ?? {}) },
|
|
537
|
-
reject: false,
|
|
538
|
-
timeout: options.timeout ?? 10 * 60 * 1000,
|
|
539
|
-
});
|
|
540
|
-
stdout = proc.stdout ?? '';
|
|
541
|
-
stderr = proc.stderr ?? '';
|
|
542
|
-
exitCode = proc.exitCode ?? 0;
|
|
543
|
-
} catch (err) {
|
|
544
|
-
const execaErr = err as ExecaError;
|
|
545
|
-
stdout = execaErr.stdout ?? '';
|
|
546
|
-
stderr = execaErr.stderr ?? '';
|
|
547
|
-
exitCode = execaErr.exitCode ?? 1;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
const finishedAt = new Date();
|
|
551
|
-
const results = await parseMaestroXml(reportPath);
|
|
552
|
-
|
|
553
|
-
if (results.length === 0 && exitCode !== 0) {
|
|
554
|
-
console.error(chalk.red('\n✗ Maestro failed to execute flows:'));
|
|
555
|
-
console.error(chalk.dim(stderr || stdout));
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
return { exitCode, results, startedAt, finishedAt, stdout, stderr };
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
/**
|
|
562
|
-
* Run a Maestro suite in parallel across multiple connected devices.
|
|
563
|
-
* Each device gets an isolated copy of the suite directory so reports
|
|
564
|
-
* don't collide. Results are returned per-device, in the same order
|
|
565
|
-
* as the input devices array.
|
|
566
|
-
*/
|
|
567
|
-
export async function executeMaestroMultiDevice(
|
|
568
|
-
suiteDir: string,
|
|
569
|
-
devices: DeviceInfo[],
|
|
570
|
-
options: ExecutionOptions = {}
|
|
571
|
-
): Promise<DeviceResult[]> {
|
|
572
|
-
if (devices.length === 0) return [];
|
|
573
|
-
if (devices.length === 1) {
|
|
574
|
-
const execution = await _executeMaestroOnDevice(suiteDir, devices[0], options);
|
|
575
|
-
return [{ device: devices[0], execution }];
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
// Run all devices in parallel — each gets its own temp dir copy
|
|
579
|
-
const tasks = devices.map(async (device): Promise<DeviceResult> => {
|
|
580
|
-
// Isolated copy so JUnit XML reports don't overwrite each other
|
|
581
|
-
const deviceDir = mkdtempSync(path.join(tmpdir(), `flowspecqa_${device.id}_`));
|
|
582
|
-
try {
|
|
583
|
-
cpSync(suiteDir, deviceDir, { recursive: true });
|
|
584
|
-
const execution = await _executeMaestroOnDevice(deviceDir, device, options);
|
|
585
|
-
return { device, execution };
|
|
586
|
-
} finally {
|
|
587
|
-
// best-effort cleanup
|
|
588
|
-
try { (await import('fs')).rmSync(deviceDir, { recursive: true, force: true }); } catch {}
|
|
589
|
-
}
|
|
590
|
-
});
|
|
591
|
-
|
|
592
|
-
return Promise.all(tasks);
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
/**
|
|
596
|
-
* Run Maestro on a single specific device (Android or iOS).
|
|
597
|
-
* Passes --device flag to Maestro CLI to target the correct device.
|
|
598
|
-
*/
|
|
599
|
-
async function _executeMaestroOnDevice(
|
|
600
|
-
suiteDir: string,
|
|
601
|
-
device: DeviceInfo,
|
|
602
|
-
options: ExecutionOptions
|
|
603
|
-
): Promise<ExecutionResult> {
|
|
604
|
-
// Patch options.env with the correct APP_ID for this platform if available
|
|
605
|
-
const patchedOptions: ExecutionOptions = {
|
|
606
|
-
...options,
|
|
607
|
-
env: {
|
|
608
|
-
...options.env,
|
|
609
|
-
// Allow per-platform APP_ID override: ANDROID_APP_ID / IOS_APP_ID
|
|
610
|
-
...(device.platform === 'android' && options.env?.ANDROID_APP_ID
|
|
611
|
-
? { APP_ID: options.env.ANDROID_APP_ID }
|
|
612
|
-
: {}),
|
|
613
|
-
...(device.platform === 'ios' && options.env?.IOS_APP_ID
|
|
614
|
-
? { APP_ID: options.env.IOS_APP_ID }
|
|
615
|
-
: {}),
|
|
616
|
-
},
|
|
617
|
-
};
|
|
618
|
-
|
|
619
|
-
// Inject --device flag into the Maestro args by temporarily patching
|
|
620
|
-
// the executor. We achieve this by setting the MAESTRO_DEVICE_ID env
|
|
621
|
-
// which executeMaestro reads via the deviceId option field.
|
|
622
|
-
patchedOptions.env = {
|
|
623
|
-
...patchedOptions.env,
|
|
624
|
-
_FLOWSPECQA_DEVICE_ID: device.id,
|
|
625
|
-
};
|
|
626
|
-
|
|
627
|
-
return executeMaestro(suiteDir, patchedOptions);
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
/**
|
|
631
|
-
* Parse Maestro JUnit XML report into TestResultItem[].
|
|
632
|
-
* Format: <testsuite><testcase name="..." time="2.3"><failure message="..."/></testcase></testsuite>
|
|
633
|
-
*/
|
|
634
|
-
async function parseMaestroXml(reportPath: string): Promise<TestResultItem[]> {
|
|
635
|
-
const fsMod = await import('fs');
|
|
636
|
-
if (!fsMod.existsSync(reportPath)) return [];
|
|
637
|
-
|
|
638
|
-
try {
|
|
639
|
-
const { XMLParser } = await import('fast-xml-parser');
|
|
640
|
-
const xml = fsMod.readFileSync(reportPath, 'utf-8');
|
|
641
|
-
const parser = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: '@_' });
|
|
642
|
-
const doc = parser.parse(xml);
|
|
643
|
-
|
|
644
|
-
// Support both <testsuites> (wrapper) and bare <testsuite>
|
|
645
|
-
const suites = doc?.testsuites?.testsuite ?? doc?.testsuite;
|
|
646
|
-
const suiteArray = Array.isArray(suites) ? suites : suites ? [suites] : [];
|
|
647
|
-
|
|
648
|
-
const items: TestResultItem[] = [];
|
|
649
|
-
|
|
650
|
-
for (const suite of suiteArray) {
|
|
651
|
-
const testcases = suite?.testcase;
|
|
652
|
-
const cases = Array.isArray(testcases) ? testcases : testcases ? [testcases] : [];
|
|
653
|
-
|
|
654
|
-
for (const tc of cases) {
|
|
655
|
-
const name: string = tc['@_name'] ?? tc['@_classname'] ?? 'unknown';
|
|
656
|
-
const timeStr: string = tc['@_time'] ?? '0';
|
|
657
|
-
const duration_ms = Math.round(parseFloat(timeStr) * 1000);
|
|
658
|
-
|
|
659
|
-
const hasFailure = tc.failure !== undefined;
|
|
660
|
-
const hasSkipped = tc.skipped !== undefined;
|
|
661
|
-
const failureMsg: string | null =
|
|
662
|
-
typeof tc.failure === 'object'
|
|
663
|
-
? tc.failure['@_message'] ?? null
|
|
664
|
-
: typeof tc.failure === 'string'
|
|
665
|
-
? tc.failure
|
|
666
|
-
: null;
|
|
667
|
-
|
|
668
|
-
items.push({
|
|
669
|
-
name,
|
|
670
|
-
status: hasFailure ? 'fail' : hasSkipped ? 'skip' : 'pass',
|
|
671
|
-
duration_ms,
|
|
672
|
-
error: hasFailure ? failureMsg : null,
|
|
673
|
-
});
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
return items;
|
|
678
|
-
} catch {
|
|
679
|
-
return [];
|
|
680
|
-
}
|
|
681
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// @flowspec-qa/runner-core — public API
|
|
2
|
-
export { config, type RunnerConfig } from './config.js';
|
|
3
|
-
export { login, logout, getAuthStatus, getBearerToken, type AuthStatus } from './auth.js';
|
|
4
|
-
export { apiClient, FlowSpecQAApi, type Project, type Suite, type IngestResult, type RunResultPayload, type TestResultItem } from './api-client.js';
|
|
5
|
-
export { downloadSuite, listCachedSuites, evictSuite, type LocalSuite } from './suite-manager.js';
|
|
6
|
-
export { executePlaywright, executeCypress, executeMaestro, executeMaestroMultiDevice, type ExecutionOptions, type ExecutionResult, type DeviceResult } from './executor.js';
|
|
7
|
-
export { detectAllDevices, detectAndroidDevices, detectIosDevices, readyDevices, type DeviceInfo } from './devices.js';
|
|
8
|
-
export { sanitizeResults, assertNoSecrets } from './result-sanitizer.js';
|
|
9
|
-
export { uploadResults, type UploadOptions } from './uploader.js';
|
|
10
|
-
export { discoveryEngine, type DiscoveryOptions, type DiscoveryResult } from './discovery.js';
|
|
11
|
-
export * from './backup-manager.js';
|