Skip to content

Commit

Permalink
Merge pull request #46 from wix-incubator/require-testing-framework-info
Browse files Browse the repository at this point in the history
feat(driver): add framework info fields to TestingFrameworkAPICatalog
  • Loading branch information
asafkorem authored Jan 19, 2025
2 parents 0193842 + 926f550 commit 4e2df2f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/test-utils/APICatalogTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export const dummyBarContext2 = {bar: jest.fn()};

export const promptCreatorConstructorMockAPI: TestingFrameworkAPICatalog = {
context: {},
name: 'Test Framework',
description: 'A testing framework for unit testing purposes',
categories: [
{
title: 'Actions',
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ export interface TestingFrameworkDriver {

/**
* Represents the available API of the testing framework that can be used by Copilot.
* @property name Optional name of the testing framework (e.g. "Detox", "Jest", etc.).
* @property description Optional description of the testing framework's purpose and capabilities.
* @property context The available variables of the testing framework (i.e. exposes the matching function, expect, etc.).
* @property categories The available categories of the testing framework API.
*/
export type TestingFrameworkAPICatalog = {
name?: string;
description?: string;
context: any;
categories: TestingFrameworkAPICatalogCategory[];
}
Expand Down
19 changes: 18 additions & 1 deletion src/utils/PromptCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,30 @@ export class PromptCreator {
}

private createBasePrompt(): string[] {
return [
const basePrompt = [
"# Test Code Generation",
"",
"You are an AI assistant tasked with generating test code for an application using the provided UI testing framework API.",
"Please generate the minimal executable code to perform the desired intent based on the given information and context.",
""
];

if (this.apiCatalog.name || this.apiCatalog.description) {
basePrompt.push("## Testing Framework");
basePrompt.push("");

if (this.apiCatalog.name) {
basePrompt.push(`Framework: ${this.apiCatalog.name}`);
basePrompt.push("");
}

if (this.apiCatalog.description) {
basePrompt.push(`Description: ${this.apiCatalog.description}`);
basePrompt.push("");
}
}

return basePrompt;
}

private createContext(
Expand Down
6 changes: 6 additions & 0 deletions src/utils/__snapshots__/PromptCreator.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ exports[`PromptCreator constructor should merge redundant categories 1`] = `
You are an AI assistant tasked with generating test code for an application using the provided UI testing framework API.
Please generate the minimal executable code to perform the desired intent based on the given information and context.
## Testing Framework
Framework: Test Framework
Description: A testing framework for unit testing purposes
## Context
### Intent to perform
Expand Down
12 changes: 8 additions & 4 deletions website/docs/API/framework-driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ By implementing a custom driver, you enable **Copilot** to communicate with your
The `TestingFrameworkDriver` interface defines the essential methods that a driver should implement:

- **`captureSnapshotImage`**: Takes a snapshot of the current screen and returns the path to the saved image. If the driver does not support snapshot functionality, it should return `undefined`.
- **`captureViewHierarchyString`**: Returns the current view hierarchy in a string representation, which helps the AI understand the structure of the app’s UI.
- **`apiCatalog`**: Provides access to the available methods of the testing framework's API, such as matchers and actions.
- **`captureViewHierarchyString`**: Returns the current view hierarchy in a string representation, which helps the AI understand the structure of the app's UI.
- **`apiCatalog`**: Provides access to the available methods of the testing framework's API, such as matchers and actions. The catalog can also include optional framework information:
- `name`: The name of the testing framework (e.g., "Detox", "Jest")
- `description`: A description of the framework's purpose and capabilities

Heres the interface definition for the driver:
Here's the interface definition for the driver:

```typescript
/**
Expand All @@ -42,7 +44,7 @@ export interface TestingFrameworkDriver {
captureViewHierarchyString: () => Promise<string>;

/**
* The available guides methods of the testing framework.
* The available API methods of the testing framework.
*/
apiCatalog: TestingFrameworkAPICatalog;
}
Expand All @@ -58,6 +60,8 @@ const detox = require('../..');
const detoxCopilotFrameworkDriver = {
apiCatalog: {
context: { ...detox, jestExpect },
name: 'Detox',
description: 'End-to-end testing and automation framework for mobile apps',
categories: [
{
title: 'Matchers',
Expand Down

0 comments on commit 4e2df2f

Please sign in to comment.