Skip to content

Commit c65c0df

Browse files
Copilothotlong
andcommitted
Implement JSON path variable substitution in QA TestRunner resolveVariables
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 300c692 commit c65c0df

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

packages/core/src/qa/runner.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,18 @@ export class TestRunner {
131131
return result;
132132
}
133133

134-
private resolveVariables(action: QA.TestAction, _context: Record<string, unknown>): QA.TestAction {
135-
// TODO: Implement JSON path variable substitution stringify/parse
136-
// For now returning as is
137-
return action;
134+
private resolveVariables(action: QA.TestAction, context: Record<string, unknown>): QA.TestAction {
135+
const actionStr = JSON.stringify(action);
136+
const resolved = actionStr.replace(/\{\{([^}]+)\}\}/g, (_match, varPath: string) => {
137+
const value = this.getValueByPath(context, varPath.trim());
138+
if (value === undefined) return _match; // Keep unresolved
139+
return typeof value === 'string' ? value : JSON.stringify(value);
140+
});
141+
try {
142+
return JSON.parse(resolved) as QA.TestAction;
143+
} catch {
144+
return action; // Fallback to original if parse fails
145+
}
138146
}
139147

140148
private getValueByPath(obj: unknown, path: string): unknown {

0 commit comments

Comments
 (0)