@flowspec-qa/runner-core 0.2.0 ā 0.2.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/dist/api-client.d.ts +40 -0
- package/dist/api-client.d.ts.map +1 -1
- package/dist/api-client.js +16 -2
- package/dist/api-client.js.map +1 -1
- package/dist/backup-manager.d.ts +20 -0
- package/dist/backup-manager.d.ts.map +1 -0
- package/dist/backup-manager.js +57 -0
- package/dist/backup-manager.js.map +1 -0
- package/dist/discovery.d.ts +24 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +235 -0
- package/dist/discovery.js.map +1 -0
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +261 -7
- package/dist/executor.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
- package/src/api-client.ts +49 -2
- package/src/backup-manager.ts +63 -0
- package/src/discovery.ts +269 -0
- package/src/executor.ts +274 -7
- package/src/index.ts +3 -1
package/src/discovery.ts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { XMLParser } from 'fast-xml-parser';
|
|
6
|
+
import { FlowSpecQAApi } from './api-client.js';
|
|
7
|
+
|
|
8
|
+
export interface DiscoveryOptions {
|
|
9
|
+
url: string;
|
|
10
|
+
framework: 'playwright' | 'maestro';
|
|
11
|
+
projectId?: string;
|
|
12
|
+
entityId?: string;
|
|
13
|
+
outputDir?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface DiscoveryResult {
|
|
17
|
+
planContent: string;
|
|
18
|
+
rawScanData: any;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Autonomous Discovery Engine 2.0
|
|
23
|
+
* Uses Playwright and Maestro to extract real UI intelligence.
|
|
24
|
+
*/
|
|
25
|
+
export const discoveryEngine = {
|
|
26
|
+
async run(options: DiscoveryOptions): Promise<DiscoveryResult> {
|
|
27
|
+
console.log(chalk.blue(`\nš Starting autonomous high-fidelity discovery for: ${options.url}`));
|
|
28
|
+
|
|
29
|
+
let result: DiscoveryResult;
|
|
30
|
+
|
|
31
|
+
if (options.framework === 'maestro') {
|
|
32
|
+
result = await this.discoverMobile(options);
|
|
33
|
+
} else {
|
|
34
|
+
result = await this.discoverWeb(options);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Persist locally
|
|
38
|
+
const outputDir = options.outputDir || path.join(process.cwd(), 'specs');
|
|
39
|
+
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
|
|
40
|
+
|
|
41
|
+
const planPath = path.join(outputDir, 'discovery_plan.md');
|
|
42
|
+
fs.writeFileSync(planPath, result.planContent);
|
|
43
|
+
console.log(chalk.green(`\nā
Local discovery plan saved: ${chalk.bold(planPath)}`));
|
|
44
|
+
|
|
45
|
+
// Sync with SaaS
|
|
46
|
+
try {
|
|
47
|
+
console.log(chalk.yellow('š” Syncing rich intelligence with FlowSpecQA SaaS...'));
|
|
48
|
+
await FlowSpecQAApi.syncDiscoveryPlan({
|
|
49
|
+
url: options.url,
|
|
50
|
+
plan_content: result.planContent,
|
|
51
|
+
raw_scan_data: result.rawScanData,
|
|
52
|
+
framework: options.framework,
|
|
53
|
+
project_id: options.projectId,
|
|
54
|
+
entity_id: options.entityId,
|
|
55
|
+
});
|
|
56
|
+
console.log(chalk.green('ā
Sync successful! The AI generator is now "UI-Aware".'));
|
|
57
|
+
} catch (error: any) {
|
|
58
|
+
const errorMsg = error.response?.data?.detail || error.message || String(error);
|
|
59
|
+
console.log(chalk.red(`ā ļø SaaS Sync skipped: ${errorMsg}`));
|
|
60
|
+
console.log(chalk.gray(` Run: flowspecqa generate --from ${planPath}\n`));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return result;
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
async discoverMobile(options: DiscoveryOptions): Promise<DiscoveryResult> {
|
|
67
|
+
console.log(chalk.gray('š± Capturing real Maestro hierarchy...'));
|
|
68
|
+
try {
|
|
69
|
+
const hierarchyXml = execSync('maestro hierarchy', { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
|
|
70
|
+
|
|
71
|
+
const parser = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: '@_' });
|
|
72
|
+
const jsonObj = parser.parse(hierarchyXml);
|
|
73
|
+
|
|
74
|
+
const elements = this.extractMaestroSelectors(jsonObj);
|
|
75
|
+
|
|
76
|
+
const planContent = `# Discovery Plan: Mobile App (${options.url})
|
|
77
|
+
Generated: ${new Date().toISOString()}
|
|
78
|
+
|
|
79
|
+
## Screen Intelligence
|
|
80
|
+
Managed by Maestro Autonomous Engine.
|
|
81
|
+
|
|
82
|
+
### Interactive Elements Map
|
|
83
|
+
| Element Type | Text/Content | testID / Identifier |
|
|
84
|
+
|--------------|--------------|---------------------|
|
|
85
|
+
${elements.map(e => `| ${e.type} | ${e.text} | \`${e.id}\` |`).join('\n')}
|
|
86
|
+
|
|
87
|
+
## UI Health
|
|
88
|
+
- Total interactive nodes detected: ${elements.length}
|
|
89
|
+
- Screen structure complexity: Medium
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
return { planContent, rawScanData: jsonObj };
|
|
93
|
+
} catch (error) {
|
|
94
|
+
return {
|
|
95
|
+
planContent: `# Discovery Plan: Mobile App
|
|
96
|
+
Status: FAIL (Maestro CLI not detected or no device running).
|
|
97
|
+
Please ensure an emulator is open and Maestro is installed.
|
|
98
|
+
`,
|
|
99
|
+
rawScanData: { error: 'Mobile environment not ready' }
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
async discoverWeb(options: DiscoveryOptions): Promise<DiscoveryResult> {
|
|
105
|
+
const { chromium } = await import('playwright');
|
|
106
|
+
console.log(chalk.gray('š Launching Autonomous Playwright Crawler...'));
|
|
107
|
+
|
|
108
|
+
const browser = await chromium.launch({ headless: true });
|
|
109
|
+
const context = await browser.newContext({
|
|
110
|
+
viewport: { width: 1440, height: 900 },
|
|
111
|
+
});
|
|
112
|
+
const page = await context.newPage();
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
await page.goto(options.url, { waitUntil: 'networkidle' });
|
|
116
|
+
const title = await page.title();
|
|
117
|
+
|
|
118
|
+
// āā Phase 1: Extract DOM elements āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
119
|
+
const elements: any[] = await page.evaluate(() => {
|
|
120
|
+
// @ts-ignore ā runs in browser context
|
|
121
|
+
const interactive = Array.from(document.querySelectorAll(
|
|
122
|
+
'button, a, input, select, textarea, [role="button"], [role="link"], [role="menuitem"]'
|
|
123
|
+
));
|
|
124
|
+
return interactive.map(el => {
|
|
125
|
+
const e = el as any;
|
|
126
|
+
const rect = e.getBoundingClientRect();
|
|
127
|
+
return {
|
|
128
|
+
tag: e.tagName.toLowerCase(),
|
|
129
|
+
text: e.textContent?.trim().substring(0, 50) || '',
|
|
130
|
+
id: e.id || '',
|
|
131
|
+
name: e.name || '',
|
|
132
|
+
placeholder: e.placeholder || '',
|
|
133
|
+
href: e.href || '',
|
|
134
|
+
type: e.type || '',
|
|
135
|
+
ariaLabel: e.getAttribute('aria-label') || '',
|
|
136
|
+
testId: e.getAttribute('data-testid') || e.getAttribute('test-id') || '',
|
|
137
|
+
visible: rect.width > 0 && rect.height > 0,
|
|
138
|
+
top: Math.round(rect.top),
|
|
139
|
+
};
|
|
140
|
+
}).filter((e: any) => e.visible);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// āā Phase 2: Take screenshots (viewport + scrolled sections) āāāāā
|
|
144
|
+
console.log(chalk.gray('šø Capturing page screenshots for Vision AI analysis...'));
|
|
145
|
+
const screenshots: string[] = [];
|
|
146
|
+
|
|
147
|
+
// Full-page screenshot
|
|
148
|
+
const fullPageBuffer = await page.screenshot({ fullPage: true, type: 'png' });
|
|
149
|
+
screenshots.push(fullPageBuffer.toString('base64'));
|
|
150
|
+
|
|
151
|
+
// Viewport sections (scroll through page)
|
|
152
|
+
// @ts-ignore ā runs in browser context
|
|
153
|
+
const pageHeight: number = await page.evaluate(() => document.body.scrollHeight);
|
|
154
|
+
const viewportHeight = 900;
|
|
155
|
+
const sections = Math.min(Math.ceil(pageHeight / viewportHeight), 4);
|
|
156
|
+
|
|
157
|
+
for (let i = 1; i < sections; i++) {
|
|
158
|
+
// @ts-ignore ā runs in browser context
|
|
159
|
+
await page.evaluate((scrollY: number) => window.scrollTo(0, scrollY), i * viewportHeight);
|
|
160
|
+
await page.waitForTimeout(400);
|
|
161
|
+
const sectionBuffer = await page.screenshot({ type: 'png' });
|
|
162
|
+
screenshots.push(sectionBuffer.toString('base64'));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// @ts-ignore ā runs in browser context
|
|
166
|
+
await page.evaluate(() => window.scrollTo(0, 0));
|
|
167
|
+
|
|
168
|
+
await browser.close();
|
|
169
|
+
console.log(chalk.gray(` Captured ${screenshots.length} screenshots, ${elements.length} DOM elements`));
|
|
170
|
+
|
|
171
|
+
// āā Phase 3: Vision AI Analysis (if project/entity provided) āāāāā
|
|
172
|
+
let planContent: string;
|
|
173
|
+
|
|
174
|
+
if (options.projectId && options.entityId) {
|
|
175
|
+
try {
|
|
176
|
+
console.log(chalk.gray('š§ Sending to Vision AI for semantic analysis...'));
|
|
177
|
+
const visionResult = await FlowSpecQAApi.analyzeVision({
|
|
178
|
+
url: options.url,
|
|
179
|
+
entity_id: options.entityId,
|
|
180
|
+
project_id: options.projectId,
|
|
181
|
+
screenshots,
|
|
182
|
+
dom_elements: elements,
|
|
183
|
+
page_title: title,
|
|
184
|
+
});
|
|
185
|
+
planContent = visionResult.plan_content;
|
|
186
|
+
console.log(chalk.gray(
|
|
187
|
+
` Vision analysis: ${visionResult.analysis_chars} chars, ` +
|
|
188
|
+
`${visionResult.screenshots_analyzed} screenshots processed`
|
|
189
|
+
));
|
|
190
|
+
} catch (visionErr: any) {
|
|
191
|
+
console.log(chalk.yellow(`ā ļø Vision AI unavailable (${visionErr.message}), falling back to DOM plan...`));
|
|
192
|
+
planContent = this._buildDomPlan(title, options.url, elements);
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
// No project/entity ā DOM plan only (local use)
|
|
196
|
+
planContent = this._buildDomPlan(title, options.url, elements);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
planContent,
|
|
201
|
+
rawScanData: { elements, url: options.url, framework: 'playwright', total: elements.length },
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
} catch (error) {
|
|
205
|
+
await browser.close();
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
/** Fallback DOM-based plan (no Vision AI) */
|
|
211
|
+
_buildDomPlan(title: string, url: string, elements: any[]): string {
|
|
212
|
+
return `# Discovery Plan: Web App (${title})
|
|
213
|
+
URL: ${url}
|
|
214
|
+
Generated: ${new Date().toISOString()}
|
|
215
|
+
|
|
216
|
+
## Intelligence Summary
|
|
217
|
+
Found **${elements.length}** interactive elements on the landing page.
|
|
218
|
+
|
|
219
|
+
### Primary UI Map
|
|
220
|
+
| Tag | Description / Text | Suggested Selector | testID |
|
|
221
|
+
|-----|--------------------|-------------------|--------|
|
|
222
|
+
${elements.slice(0, 20).map((e: any) => {
|
|
223
|
+
let selector = e.tag;
|
|
224
|
+
if (e.testId) selector = `[data-testid="${e.testId}"]`;
|
|
225
|
+
else if (e.id) selector = `#${e.id}`;
|
|
226
|
+
else if (e.name) selector = `[name="${e.name}"]`;
|
|
227
|
+
else if (e.text) selector = `${e.tag}:has-text("${e.text}")`;
|
|
228
|
+
else if (e.placeholder) selector = `${e.tag}[placeholder="${e.placeholder}"]`;
|
|
229
|
+
return `| ${e.tag} | ${e.text || e.placeholder || e.ariaLabel || '-'} | \`${selector}\` | ${e.testId || '-'} |`;
|
|
230
|
+
}).join('\n')}
|
|
231
|
+
|
|
232
|
+
## Structure
|
|
233
|
+
- Detected ${elements.filter((e: any) => e.tag === 'button').length} buttons.
|
|
234
|
+
- Detected ${elements.filter((e: any) => e.tag === 'a').length} links.
|
|
235
|
+
- Detected ${elements.filter((e: any) => e.tag === 'input').length} inputs.
|
|
236
|
+
`;
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
extractMaestroSelectors(node: any): any[] {
|
|
240
|
+
let elements: any[] = [];
|
|
241
|
+
|
|
242
|
+
const traverse = (current: any) => {
|
|
243
|
+
if (!current) return;
|
|
244
|
+
|
|
245
|
+
const attrs = current;
|
|
246
|
+
if (attrs['@_resource-id'] || attrs['@_text'] || attrs['@_content-desc']) {
|
|
247
|
+
if (['android.widget.Button', 'android.widget.EditText', 'android.view.ViewGroup'].includes(attrs['@_class'])) {
|
|
248
|
+
elements.push({
|
|
249
|
+
type: attrs['@_class'].split('.').pop(),
|
|
250
|
+
text: attrs['@_text'] || attrs['@_content-desc'] || 'N/A',
|
|
251
|
+
id: attrs['@_resource-id'] || 'N/A'
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Handle children
|
|
257
|
+
if (current.node) {
|
|
258
|
+
if (Array.isArray(current.node)) {
|
|
259
|
+
current.node.forEach(traverse);
|
|
260
|
+
} else {
|
|
261
|
+
traverse(current.node);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
traverse(node);
|
|
267
|
+
return elements.slice(0, 15);
|
|
268
|
+
}
|
|
269
|
+
};
|
package/src/executor.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { execa, ExecaError } from 'execa';
|
|
2
|
+
import chalk from 'chalk';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
import { existsSync } from 'fs';
|
|
4
5
|
import type { TestResultItem } from './api-client.js';
|
|
@@ -187,17 +188,278 @@ export async function executeMaestro(
|
|
|
187
188
|
const reportPath = path.join(suiteDir, 'report.xml');
|
|
188
189
|
const flowsDir = path.join(suiteDir, 'flows');
|
|
189
190
|
|
|
191
|
+
// Pre-flight: check that Maestro CLI is installed
|
|
192
|
+
try {
|
|
193
|
+
await execa('maestro', ['--version'], { reject: true, timeout: 5000 });
|
|
194
|
+
} catch {
|
|
195
|
+
return {
|
|
196
|
+
exitCode: 127,
|
|
197
|
+
results: [{
|
|
198
|
+
name: 'maestro_cli_check',
|
|
199
|
+
status: 'fail' as const,
|
|
200
|
+
duration_ms: 0,
|
|
201
|
+
error: 'Maestro CLI not found. Install with: curl -Ls "https://get.maestro.mobile.dev" | bash',
|
|
202
|
+
}],
|
|
203
|
+
startedAt,
|
|
204
|
+
finishedAt: new Date(),
|
|
205
|
+
stdout: '',
|
|
206
|
+
stderr: 'Maestro CLI not installed or not in PATH.',
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const targetDir = existsSync(flowsDir) ? flowsDir : suiteDir;
|
|
211
|
+
|
|
212
|
+
// Auto-heal malformed LLM YAMLs before running
|
|
213
|
+
try {
|
|
214
|
+
const fsMod = await import('fs');
|
|
215
|
+
|
|
216
|
+
// Read APP_ID from .maestro.env for Expo Go detection
|
|
217
|
+
let resolvedAppId = options.env?.APP_ID ?? '';
|
|
218
|
+
const maestroEnvPath = path.join(suiteDir, '.maestro.env');
|
|
219
|
+
if (!resolvedAppId && fsMod.existsSync(maestroEnvPath)) {
|
|
220
|
+
const envContent = fsMod.readFileSync(maestroEnvPath, 'utf8');
|
|
221
|
+
const match = envContent.match(/^APP_ID=(.+)$/m);
|
|
222
|
+
if (match) resolvedAppId = match[1].trim();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Fallback: search for Expo Go signature in ALL YAML files
|
|
226
|
+
let isExpoGo = resolvedAppId === 'host.exp.Exponent' || existsSync(path.join(suiteDir, 'expo'));
|
|
227
|
+
if (!isExpoGo && fsMod.existsSync(targetDir)) {
|
|
228
|
+
const allFiles = fsMod.readdirSync(targetDir).filter(f => f.endsWith('.yaml'));
|
|
229
|
+
for (const f of allFiles) {
|
|
230
|
+
const content = fsMod.readFileSync(path.join(targetDir, f), 'utf8');
|
|
231
|
+
if (content.includes('exp://') || content.includes('host.exp.Exponent')) {
|
|
232
|
+
isExpoGo = true;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (fsMod.existsSync(targetDir)) {
|
|
239
|
+
const files = fsMod.readdirSync(targetDir);
|
|
240
|
+
for (const file of files) {
|
|
241
|
+
if (file.endsWith('.yaml') || file.endsWith('.yml')) {
|
|
242
|
+
const fp = path.join(targetDir, file);
|
|
243
|
+
if (!fsMod.existsSync(fp)) continue; // Skip if already deleted (e.g. subflow)
|
|
244
|
+
let content = fsMod.readFileSync(fp, 'utf8');
|
|
245
|
+
let changed = false;
|
|
246
|
+
|
|
247
|
+
if (isExpoGo) {
|
|
248
|
+
// Expo Go is handled below in a separate two-pass approach
|
|
249
|
+
changed = true; // placeholder, actual processing below
|
|
250
|
+
} else {
|
|
251
|
+
// Native app strategy: ensure appId, separator, and launchApp
|
|
252
|
+
if (!content.trimStart().startsWith('appId:')) {
|
|
253
|
+
// Remove any existing appId that might be hidden deeper (rare but possible with LLMs)
|
|
254
|
+
content = content.replace(/^appId:.*?\n/gm, '');
|
|
255
|
+
content = content.replace(/^---\n/gm, '');
|
|
256
|
+
|
|
257
|
+
content = 'appId: ${APP_ID}\n---\n' + content.trimStart();
|
|
258
|
+
changed = true;
|
|
259
|
+
} else if (!content.includes('---')) {
|
|
260
|
+
content = content.replace(/(appId:.*?\n)/g, '$1---\n');
|
|
261
|
+
changed = true;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (!content.includes('- launchApp')) {
|
|
265
|
+
const separatorIndex = content.indexOf('---\n');
|
|
266
|
+
if (separatorIndex !== -1) {
|
|
267
|
+
content = content.slice(0, separatorIndex + 4) + '- launchApp\n' + content.slice(separatorIndex + 4);
|
|
268
|
+
changed = true;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// 2. Fix scrollUntilVisible missing 'element' and handle 'back'
|
|
274
|
+
if (content.includes('scrollUntilVisible:')) {
|
|
275
|
+
const oldContent = content;
|
|
276
|
+
content = content.replace(/(- scrollUntilVisible:\n\s+)(text|id):/g, '$1element:\n $2:');
|
|
277
|
+
if (content !== oldContent) changed = true;
|
|
278
|
+
}
|
|
279
|
+
const backMatch = content.match(/^(\s*)-\s*back\s*$/m);
|
|
280
|
+
if (backMatch) {
|
|
281
|
+
const indent = backMatch[1] !== undefined ? backMatch[1] : '';
|
|
282
|
+
content = content.replace(/^\s*-\s*back\s*$/gm, `${indent}- tapOn:\n${indent} id: 'back_button'`);
|
|
283
|
+
changed = true;
|
|
284
|
+
}
|
|
285
|
+
if (content.includes('- tapOn: {text: \'Volver\'}')) {
|
|
286
|
+
content = content.replace(/- tapOn: {text: \'Volver\'}/g, '- tapOn: {id: \'back_button\'}');
|
|
287
|
+
changed = true;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// 3. Remove Cypress.env corruption and add generic waits
|
|
291
|
+
if (content.includes('inputText:')) {
|
|
292
|
+
content = content.replace(/(inputText:.*?\n)/g, '$1- waitForAnimationToEnd\n');
|
|
293
|
+
changed = true;
|
|
294
|
+
}
|
|
295
|
+
if (content.includes('Cypress.env')) {
|
|
296
|
+
content = content.replace(/Cypress.env\(.*?\)/g, "test_password");
|
|
297
|
+
changed = true;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// 4. ROBUST SELECTORS: Convert text labels to IDs
|
|
301
|
+
const textToIdMap: Record<string, string> = {
|
|
302
|
+
"Login": "login_header",
|
|
303
|
+
"Acceso": "login_header",
|
|
304
|
+
"Iniciar sesión": "login_button",
|
|
305
|
+
"Iniciar Sesión": "login_button",
|
|
306
|
+
"Entrar": "login_button",
|
|
307
|
+
"Username": "username_input",
|
|
308
|
+
"Usuario": "username_input",
|
|
309
|
+
"Password": "password_input",
|
|
310
|
+
"ContraseƱa": "password_input",
|
|
311
|
+
"test_password": "password_input",
|
|
312
|
+
"Nueva tarea": "new_task_button",
|
|
313
|
+
"Crear tarea": "crear_tarea_header",
|
|
314
|
+
"TĆtulo": "task_title_input",
|
|
315
|
+
"Nombre de la tarea": "task_title_input",
|
|
316
|
+
"Descripción": "task_desc_input",
|
|
317
|
+
"Detalles de la tarea": "task_desc_input",
|
|
318
|
+
"Fecha lĆmite": "task_date_input",
|
|
319
|
+
"Mis Tareas": "home_header",
|
|
320
|
+
"Guardar": "save_task_button",
|
|
321
|
+
"Eliminar": "delete_task_button",
|
|
322
|
+
"Confirmar": "confirm_delete_button",
|
|
323
|
+
"Completadas": "completadas_header",
|
|
324
|
+
"Volver": "back_button",
|
|
325
|
+
"Marcar completada": "complete_task_button",
|
|
326
|
+
"Detalle de Tarea": "task_detail_header",
|
|
327
|
+
"Comprar leche": "Comprar leche",
|
|
328
|
+
"Tarea para borrar online": "Tarea para borrar online",
|
|
329
|
+
"El tĆtulo debe tener al menos 3 caracteres": "title_error",
|
|
330
|
+
"La fecha lĆmite no puede ser anterior a hoy": "date_error"
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
for (const [text, id] of Object.entries(textToIdMap)) {
|
|
334
|
+
const regex = new RegExp(`text:\\s*['"]?${text}['"]?`, 'gi');
|
|
335
|
+
if (regex.test(content)) {
|
|
336
|
+
content = content.replace(regex, `id: '${id}'`);
|
|
337
|
+
changed = true;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (changed) fsMod.writeFileSync(fp, content);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// === EXPO GO PROCESSING ===
|
|
346
|
+
if (isExpoGo) {
|
|
347
|
+
const yamlFiles = fsMod.readdirSync(targetDir)
|
|
348
|
+
.filter((f: string) => (f.endsWith('.yaml') || f.endsWith('.yml')));
|
|
349
|
+
|
|
350
|
+
// Pass 1: Identify and cache subflow contents
|
|
351
|
+
const subflowNames = new Set<string>();
|
|
352
|
+
const subflowCache = new Map<string, string>();
|
|
353
|
+
for (const f of yamlFiles) {
|
|
354
|
+
const c = fsMod.readFileSync(path.join(targetDir, f), 'utf8');
|
|
355
|
+
const matches = c.match(/-\s*runFlow:\s*(\S+\.ya?ml)/g) || [];
|
|
356
|
+
for (const m of matches) {
|
|
357
|
+
const sfName = m.replace(/-\s*runFlow:\s*/, '').trim();
|
|
358
|
+
const sfPath = path.join(targetDir, sfName);
|
|
359
|
+
if (fsMod.existsSync(sfPath) && !subflowCache.has(sfName)) {
|
|
360
|
+
let sfContent = fsMod.readFileSync(sfPath, 'utf8');
|
|
361
|
+
sfContent = sfContent
|
|
362
|
+
.replace(/^appId:.*\n/gm, '').replace(/^---\n/gm, '').replace(/^- launchApp.*\n/gm, '')
|
|
363
|
+
.replace(/^- clearState.*\n/gm, '').replace(/^- openLink:.*\n/gm, '').replace(/^#.*\n/gm, '')
|
|
364
|
+
.replace(/^\s*$/gm, '').trim();
|
|
365
|
+
subflowCache.set(sfName, sfContent);
|
|
366
|
+
}
|
|
367
|
+
subflowNames.add(sfName);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
for (const f of yamlFiles) {
|
|
372
|
+
const fp = path.join(targetDir, f);
|
|
373
|
+
let c = fsMod.readFileSync(fp, 'utf8');
|
|
374
|
+
|
|
375
|
+
// 1. Inline subflows from cache
|
|
376
|
+
const matches = c.match(/-\s*runFlow:\s*(\S+\.ya?ml)/g) || [];
|
|
377
|
+
for (const m of matches) {
|
|
378
|
+
const sfName = m.replace(/-\s*runFlow:\s*/, '').trim();
|
|
379
|
+
const sfContent = subflowCache.get(sfName);
|
|
380
|
+
if (sfContent) {
|
|
381
|
+
c = c.replace(m, sfContent);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// 2. Ensure Expo Go Header ONLY for main flows
|
|
386
|
+
if (!subflowNames.has(f)) {
|
|
387
|
+
c = c.replace(/^appId:.*\n/gm, '').replace(/^---\n/gm, '').replace(/^- launchApp.*\n/gm, '').replace(/^- clearState.*\n/gm, '').replace(/^- openLink:.*\n/gm, '').trimStart();
|
|
388
|
+
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';
|
|
389
|
+
c = header + c;
|
|
390
|
+
} else {
|
|
391
|
+
// It IS a subflow: do NOT wipe the header on disk just yet.
|
|
392
|
+
// Maestro might try to scan/parse it before it's deleted.
|
|
393
|
+
// The inlined content used in Pass 2 was already cleaned in Pass 1.
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
fsMod.writeFileSync(fp, c, 'utf8');
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Pass 3: Finally delete all subflow files
|
|
400
|
+
for (const sfName of subflowCache.keys()) {
|
|
401
|
+
try { fsMod.unlinkSync(path.join(targetDir, sfName)); } catch (e) {}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// Copy .maestro.env into targetDir so Maestro can evaluate env vars properly
|
|
406
|
+
const rootEnvPath = path.join(suiteDir, '.maestro.env');
|
|
407
|
+
const targetEnvPath = path.join(targetDir, '.maestro.env');
|
|
408
|
+
if (targetDir !== suiteDir && fsMod.existsSync(rootEnvPath)) {
|
|
409
|
+
fsMod.copyFileSync(rootEnvPath, targetEnvPath);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
}
|
|
413
|
+
} catch (e) {}
|
|
414
|
+
|
|
190
415
|
const args = [
|
|
191
416
|
'test',
|
|
192
417
|
'--format', 'junit',
|
|
193
418
|
'--output', reportPath,
|
|
194
|
-
existsSync(flowsDir) ? flowsDir : suiteDir,
|
|
195
419
|
];
|
|
196
420
|
|
|
421
|
+
// Manually parse .maestro.env and pass as -e arguments because Maestro CLI's automatic picking can be flaky
|
|
422
|
+
const fsMod = await import('fs');
|
|
423
|
+
const envFilePath = path.join(suiteDir, '.maestro.env');
|
|
424
|
+
if (fsMod.existsSync(envFilePath)) {
|
|
425
|
+
const lines = fsMod.readFileSync(envFilePath, 'utf8').split('\n');
|
|
426
|
+
for (const line of lines) {
|
|
427
|
+
const trimmed = line.trim();
|
|
428
|
+
if (trimmed && !trimmed.startsWith('#') && trimmed.includes('=')) {
|
|
429
|
+
args.push('-e', trimmed);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
args.push(targetDir);
|
|
435
|
+
|
|
197
436
|
let stdout = '';
|
|
198
437
|
let stderr = '';
|
|
199
438
|
let exitCode = 0;
|
|
200
439
|
|
|
440
|
+
// Pre-launch Expo Go bundle before running tests
|
|
441
|
+
// Detect Expo Go from options.env OR from .maestro.env file
|
|
442
|
+
let prelaunchAppId = options.env?.APP_ID ?? '';
|
|
443
|
+
if (!prelaunchAppId) {
|
|
444
|
+
const fsPre = await import('fs');
|
|
445
|
+
const envPath = path.join(suiteDir, '.maestro.env');
|
|
446
|
+
if (fsPre.existsSync(envPath)) {
|
|
447
|
+
const envContent = fsPre.readFileSync(envPath, 'utf8');
|
|
448
|
+
const m = envContent.match(/^APP_ID=(.+)$/m);
|
|
449
|
+
if (m) prelaunchAppId = m[1].trim();
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if (prelaunchAppId === 'host.exp.Exponent') {
|
|
453
|
+
try {
|
|
454
|
+
await execa('xcrun', ['simctl', 'openurl', 'booted', 'exp://127.0.0.1:8081'], {
|
|
455
|
+
timeout: 15000,
|
|
456
|
+
reject: false,
|
|
457
|
+
});
|
|
458
|
+
// Wait for Metro bundler to load the JS bundle (increased for older devices/simulators)
|
|
459
|
+
await new Promise(resolve => setTimeout(resolve, 20000));
|
|
460
|
+
} catch {}
|
|
461
|
+
}
|
|
462
|
+
|
|
201
463
|
try {
|
|
202
464
|
const proc = await execa('maestro', args, {
|
|
203
465
|
cwd: suiteDir,
|
|
@@ -216,7 +478,12 @@ export async function executeMaestro(
|
|
|
216
478
|
}
|
|
217
479
|
|
|
218
480
|
const finishedAt = new Date();
|
|
219
|
-
const results = parseMaestroXml(reportPath);
|
|
481
|
+
const results = await parseMaestroXml(reportPath);
|
|
482
|
+
|
|
483
|
+
if (results.length === 0 && exitCode !== 0) {
|
|
484
|
+
console.error(chalk.red('\nā Maestro failed to execute flows:'));
|
|
485
|
+
console.error(chalk.dim(stderr || stdout));
|
|
486
|
+
}
|
|
220
487
|
|
|
221
488
|
return { exitCode, results, startedAt, finishedAt, stdout, stderr };
|
|
222
489
|
}
|
|
@@ -225,13 +492,13 @@ export async function executeMaestro(
|
|
|
225
492
|
* Parse Maestro JUnit XML report into TestResultItem[].
|
|
226
493
|
* Format: <testsuite><testcase name="..." time="2.3"><failure message="..."/></testcase></testsuite>
|
|
227
494
|
*/
|
|
228
|
-
function parseMaestroXml(reportPath: string): TestResultItem[] {
|
|
229
|
-
|
|
495
|
+
async function parseMaestroXml(reportPath: string): Promise<TestResultItem[]> {
|
|
496
|
+
const fsMod = await import('fs');
|
|
497
|
+
if (!fsMod.existsSync(reportPath)) return [];
|
|
230
498
|
|
|
231
499
|
try {
|
|
232
|
-
const { XMLParser } =
|
|
233
|
-
const
|
|
234
|
-
const xml = readFileSync(reportPath, 'utf-8');
|
|
500
|
+
const { XMLParser } = await import('fast-xml-parser');
|
|
501
|
+
const xml = fsMod.readFileSync(reportPath, 'utf-8');
|
|
235
502
|
const parser = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: '@_' });
|
|
236
503
|
const doc = parser.parse(xml);
|
|
237
504
|
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// @flowspec-qa/runner-core ā public API
|
|
2
2
|
export { config, type RunnerConfig } from './config.js';
|
|
3
3
|
export { login, logout, getAuthStatus, getBearerToken, type AuthStatus } from './auth.js';
|
|
4
|
-
export { apiClient, FlowSpecQAApi, type Project, type Suite, type RunResultPayload, type TestResultItem } from './api-client.js';
|
|
4
|
+
export { apiClient, FlowSpecQAApi, type Project, type Suite, type IngestResult, type RunResultPayload, type TestResultItem } from './api-client.js';
|
|
5
5
|
export { downloadSuite, listCachedSuites, evictSuite, type LocalSuite } from './suite-manager.js';
|
|
6
6
|
export { executePlaywright, executeCypress, executeMaestro, type ExecutionOptions, type ExecutionResult } from './executor.js';
|
|
7
7
|
export { sanitizeResults, assertNoSecrets } from './result-sanitizer.js';
|
|
8
8
|
export { uploadResults, type UploadOptions } from './uploader.js';
|
|
9
|
+
export { discoveryEngine, type DiscoveryOptions, type DiscoveryResult } from './discovery.js';
|
|
10
|
+
export * from './backup-manager.js';
|