Skip to content

Commit

Permalink
return last result.
Browse files Browse the repository at this point in the history
  • Loading branch information
asafkorem committed Sep 26, 2024
1 parent 8e88746 commit 755019c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ const copilot: CopilotFacade = {
perform: async (...steps: string[]) => {
const copilotInstance = Copilot.getInstance();

const results = new Array<any>();
for (const intent of steps) {
results.push(await copilotInstance.performStep(intent));
let result;
for await (const intent of steps) {
result = await copilotInstance.performStep(intent);
}

return results.length === 1 ? results[0] : results;
return result;
}
};

Expand Down
3 changes: 1 addition & 2 deletions src/integration tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,12 @@ describe('Copilot Integration Tests', () => {
.mockResolvedValueOnce('// Enter username')
.mockResolvedValueOnce('// Enter password');

const results = await copilot.perform(
await copilot.perform(
'Tap on the login button',
'Enter username "testuser"',
'Enter password "password123"'
);

expect(results).toHaveLength(3);
expect(mockPromptHandler.runPrompt).toHaveBeenCalledTimes(3);
expect(mockFrameworkDriver.captureSnapshotImage).toHaveBeenCalledTimes(3);
expect(mockFrameworkDriver.captureViewHierarchyString).toHaveBeenCalledTimes(3);
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export interface CopilotFacade {

/**
* Performs a testing operation or series of testing operations in the app based on the given `steps`.
* @returns The result of the operation(s), which can be a single value or an array of values for each step.
* @returns The result of the last step, if any.
* @example Tap on the login button
* @example Scroll down to the 7th item in the Events list
* @example The welcome message should be visible
* @example The welcome message text should be "Hello, world!"
* @example 'Tap on the login button', 'A login form should be visible'
*/
perform: (...steps: string[]) => Promise<any | any[]>;
perform: (...steps: string[]) => Promise<string>;
}

/**
Expand Down

0 comments on commit 755019c

Please sign in to comment.