Skip to content

Commit

Permalink
apply lint to all files
Browse files Browse the repository at this point in the history
  • Loading branch information
tzvielwix committed Jan 27, 2025
1 parent 08251e5 commit 6a8c13d
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 78 deletions.
44 changes: 21 additions & 23 deletions src/Copilot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
ScreenCapturerResult,
PromptHandler,
PilotStepReport,
PilotReport,
} from "@/types";
import { mockCache, mockedCacheFile } from "./test-utils/cache";
import { ScreenCapturer } from "@/utils/ScreenCapturer";
Expand Down Expand Up @@ -299,11 +298,12 @@ describe("Copilot", () => {
instance.extendAPICatalog([barCategory1]);
instance.extendAPICatalog([barCategory2], dummyContext);

expect(mockConfig.frameworkDriver.apiCatalog.categories.length).toEqual(1);
expect(mockConfig.frameworkDriver.apiCatalog.categories[0].items).toEqual([
...barCategory1.items,
...barCategory2.items,
]);
expect(mockConfig.frameworkDriver.apiCatalog.categories.length).toEqual(
1,
);
expect(mockConfig.frameworkDriver.apiCatalog.categories[0].items).toEqual(
[...barCategory1.items, ...barCategory2.items],
);
expect(spyCopilotStepPerformer).toHaveBeenCalledWith(dummyContext);
});

Expand Down Expand Up @@ -407,22 +407,20 @@ describe("Copilot", () => {
summary: "All was good",
};

jest
.spyOn(instance["pilotPerformer"], "perform")
.mockResolvedValue({
summary: pilotOutputSuccess.summary,
goal: goal,
steps: [
{
screenDescription: pilotOutputStep1.screenDescription,
plan: pilotOutputStep1.plan,
code: "code executed",
review: pilotOutputStep1.review,
goalAchieved: pilotOutputStep1.goalAchieved,
},
],
review: pilotOutputSuccess.review,
});
jest.spyOn(instance["pilotPerformer"], "perform").mockResolvedValue({
summary: pilotOutputSuccess.summary,
goal: goal,
steps: [
{
screenDescription: pilotOutputStep1.screenDescription,
plan: pilotOutputStep1.plan,
code: "code executed",
review: pilotOutputStep1.review,
goalAchieved: pilotOutputStep1.goalAchieved,
},
],
review: pilotOutputSuccess.review,
});

const result = await instance.pilot(goal);

Expand All @@ -443,4 +441,4 @@ describe("Copilot", () => {
});
});
});
});
});
2 changes: 1 addition & 1 deletion src/actions/PilotPerformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,4 @@ describe("PilotPerformer", () => {
expect(result).toEqual(expectedReport);
});
});
});
});
24 changes: 15 additions & 9 deletions src/actions/PilotPerformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
import { extractOutputs, OUTPUTS_MAPPINGS } from "@/utils/extractOutputs";
import { CopilotStepPerformer } from "@/actions/CopilotStepPerformer";
import { ScreenCapturer } from "@/utils/ScreenCapturer";
import fs from 'fs';
import logger from "@/utils/logger";

export class PilotPerformer {
Expand All @@ -40,7 +39,10 @@ export class PilotPerformer {
};
}

private logReviewSection(review: PilotReviewSection, type: "ux" | "a11y" | "i18n") {
private logReviewSection(
review: PilotReviewSection,
type: "ux" | "a11y" | "i18n",
) {
const config: {
[key: string]: {
emoji: string;
Expand Down Expand Up @@ -102,10 +104,11 @@ export class PilotPerformer {
const generatedPilotTaskDetails: string =
await this.promptHandler.runPrompt(prompt, snapshot);

const { screenDescription, thoughts, action, ux, a11y, i18n } = extractOutputs({
text: generatedPilotTaskDetails,
outputsMapper: OUTPUTS_MAPPINGS.PILOT_STEP,
});
const { screenDescription, thoughts, action, ux, a11y, i18n } =
extractOutputs({
text: generatedPilotTaskDetails,
outputsMapper: OUTPUTS_MAPPINGS.PILOT_STEP,
});

analysisLoggerSpinner.stop("success", `💭 Thoughts:`, {
message: thoughts,
Expand All @@ -123,7 +126,7 @@ export class PilotPerformer {
logger.info({
message: `Conducting review for ${screenDescription}\n`,
isBold: true,
color: 'whiteBright',
color: "whiteBright",
});

review.ux && this.logReviewSection(review.ux, "ux");
Expand Down Expand Up @@ -194,7 +197,10 @@ export class PilotPerformer {
screenCapture,
);
copilotSteps = [...copilotSteps, { step: plan.action, code, result }];
previousSteps = [...previousSteps, { screenDescription, step: plan.action, review }];
previousSteps = [
...previousSteps,
{ screenDescription, step: plan.action, review },
];

const stepReport: PilotStepReport = {
screenDescription,
Expand All @@ -213,4 +219,4 @@ export class PilotPerformer {
logger.writeLogsToFile(`pilot_logs_${Date.now()}`);
return report;
}
}
}
66 changes: 41 additions & 25 deletions src/drivers/playwright/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ export class PlaywrightFrameworkDriver implements TestingFrameworkDriver {
playwright,
expect: playwrightExpect,
},
restrictions:['Never use expect on the page it self for example : await expect(page).toBeVisible()'],
restrictions: [
"Never use expect on the page it self for example : await expect(page).toBeVisible()",
],
categories: [
{
title: "Page Management",
Expand All @@ -91,7 +93,7 @@ export class PlaywrightFrameworkDriver implements TestingFrameworkDriver {
signature: "getCurrentPage(): playwright.Page | undefined",
description: "Gets the current active page instance.",
example: "const page = getCurrentPage();",
guidelines: [
guidelines: [
"Always check if page exists before operations.",
"Returns undefined if no page is set.",
"Use before any page interactions.",
Expand All @@ -102,7 +104,7 @@ export class PlaywrightFrameworkDriver implements TestingFrameworkDriver {
description: "Sets the current active page for interactions.",
example:
"const page = await context.newPage(); setCurrentPage(page);",
guidelines: [
guidelines: [
"Must be called after creating a new page.",
"Required before any page interactions.",
"Only one page can be active at a time.",
Expand All @@ -127,7 +129,7 @@ setCurrentPage(page);
await page.goto('https://www.test.com/');
await page.waitForLoadState('load')
`,
guidelines: [
guidelines: [
"Set longer timeouts (30s or more) to handle slow operations.",
"Can use chromium, firefox, or webkit browsers.",
"Remember to call setCurrentPage after creating a page.",
Expand Down Expand Up @@ -182,7 +184,7 @@ if (page) {
if (page) {
await page.reload();
}`,
guidelines: [
guidelines: [
"Avoid explicit waits - let assertions handle timing.",
"Good for refreshing stale content.",
],
Expand All @@ -199,7 +201,7 @@ if (page) {
if (page) {
await page.getByRole('button', { name: 'Submit' }).click();
}`,
guidelines: [
guidelines: [
"Always check if page exists first.",
"Preferred way to locate interactive elements.",
"Improves test accessibility coverage.",
Expand All @@ -212,7 +214,7 @@ if (page) {
if (page) {
await page.getByText('Welcome').isVisible();
}`,
guidelines: [
guidelines: [
"Always check if page exists first.",
"Good for finding visible text on page.",
"Can use exact or fuzzy matching.",
Expand All @@ -225,7 +227,7 @@ if (page) {
if (page) {
await page.getByLabel('Username').fill('john');
}`,
guidelines: [
guidelines: [
"Always check if page exists first.",
"Best practice for form inputs.",
"More reliable than selectors.",
Expand All @@ -243,7 +245,7 @@ if (page) {
if (page) {
await page.getByRole('button').click();
}`,
guidelines: [
guidelines: [
"Always check if page exists first.",
"Automatically waits for element.",
"Handles scrolling automatically.",
Expand All @@ -256,7 +258,7 @@ if (page) {
if (page) {
await page.getByLabel('Password').fill('secret');
}`,
guidelines: [
guidelines: [
"Always check if page exists first.",
"Preferred over type() for forms.",
"Clears existing value first.",
Expand Down Expand Up @@ -320,7 +322,8 @@ if (page) {
},
{
signature: "await locator.scrollIntoViewIfNeeded()",
description: "Scrolls the element into view if it is not already visible.",
description:
"Scrolls the element into view if it is not already visible.",
example: `const page = getCurrentPage();
if (page) {
await page.getByText('Load More').scrollIntoViewIfNeeded();
Expand Down Expand Up @@ -523,7 +526,8 @@ if (page) {
],
},
{
signature: "const elementHandles = await locator.elementHandles()",
signature:
"const elementHandles = await locator.elementHandles()",
description: "Gets all matching element handles.",
example: `const page = getCurrentPage();
if (page) {
Expand Down Expand Up @@ -570,7 +574,8 @@ if (page) {
},
{
signature: "await expect(locator).toHaveText(expectedText)",
description: "Asserts that the element's text content matches the expected text.",
description:
"Asserts that the element's text content matches the expected text.",
example: `const page = getCurrentPage();
if (page) {
await expect(page.getByTestId('username')).toHaveText('John Doe');
Expand All @@ -583,7 +588,8 @@ if (page) {
},
{
signature: "await expect(page).toHaveURL(expectedURL)",
description: "Asserts that the page's URL matches the expected URL.",
description:
"Asserts that the page's URL matches the expected URL.",
example: `const page = getCurrentPage();
if (page) {
await expect(page).toHaveURL('https://www.example.com/dashboard');
Expand All @@ -596,7 +602,8 @@ if (page) {
},
{
signature: "await expect(locator).toHaveValue(expectedValue)",
description: "Asserts that an input element has the expected value.",
description:
"Asserts that an input element has the expected value.",
example: `const page = getCurrentPage();
if (page) {
await expect(page.getByPlaceholder('Email')).toHaveValue('user@example.com');
Expand Down Expand Up @@ -635,7 +642,8 @@ if (page) {
},
{
signature: "await expect(locator).toBeChecked()",
description: "Asserts that a checkbox or radio button is checked.",
description:
"Asserts that a checkbox or radio button is checked.",
example: `const page = getCurrentPage();
if (page) {
await expect(page.getByLabel('Accept Terms')).toBeChecked();
Expand All @@ -648,7 +656,8 @@ if (page) {
},
{
signature: "await expect(locator).toBeEditable()",
description: "Asserts that an input or textarea element is editable.",
description:
"Asserts that an input or textarea element is editable.",
example: `const page = getCurrentPage();
if (page) {
await expect(page.getByPlaceholder('Enter your name')).toBeEditable();
Expand All @@ -661,7 +670,8 @@ if (page) {
},
{
signature: "await expect(locator).toHaveAttribute(name, value)",
description: "Asserts that the element has the specified attribute value.",
description:
"Asserts that the element has the specified attribute value.",
example: `const page = getCurrentPage();
if (page) {
await expect(page.getByTestId('profile-link')).toHaveAttribute('href', '/profile');
Expand All @@ -674,7 +684,8 @@ if (page) {
},
{
signature: "await expect(locator).toHaveClass(expectedClass)",
description: "Asserts that the element has the specified CSS class.",
description:
"Asserts that the element has the specified CSS class.",
example: `const page = getCurrentPage();
if (page) {
await expect(page.getByRole('button', { name: 'Submit' })).toHaveClass('btn-primary');
Expand All @@ -687,7 +698,8 @@ if (page) {
},
{
signature: "await expect(locator).toContainText(expectedText)",
description: "Asserts that the element's text contains the expected text.",
description:
"Asserts that the element's text contains the expected text.",
example: `const page = getCurrentPage();
if (page) {
await expect(page.getByTestId('notification')).toContainText('Success');
Expand All @@ -700,7 +712,8 @@ if (page) {
},
{
signature: "await expect(locator).toHaveJSProperty(name, value)",
description: "Asserts that the element has the specified JavaScript property.",
description:
"Asserts that the element has the specified JavaScript property.",
example: `const page = getCurrentPage();
if (page) {
await expect(page.getByTestId('toggle')).toHaveJSProperty('checked', true);
Expand All @@ -726,7 +739,8 @@ if (page) {
},
{
signature: "await expect(page).toHaveTitle(expectedTitle)",
description: "Asserts that the page's title matches the expected title.",
description:
"Asserts that the page's title matches the expected title.",
example: `const page = getCurrentPage();
if (page) {
await expect(page).toHaveTitle('Dashboard - MyApp');
Expand All @@ -739,7 +753,8 @@ if (page) {
},
{
signature: "await expect(page).toHaveScreenshot([options])",
description: "Asserts that the page's screenshot matches a stored reference image.",
description:
"Asserts that the page's screenshot matches a stored reference image.",
example: `const page = getCurrentPage();
if (page) {
await expect(page).toHaveScreenshot('dashboard.png');
Expand All @@ -752,7 +767,8 @@ if (page) {
},
{
signature: "await expect(locator).toHaveCount(expectedCount)",
description: "Asserts that the locator resolves to a specific number of elements.",
description:
"Asserts that the locator resolves to a specific number of elements.",
example: `const page = getCurrentPage();
if (page) {
await expect(page.locator('.todo-item')).toHaveCount(3);
Expand All @@ -777,7 +793,7 @@ if (page) {
],
},
],
}
},
],
};
}
Expand Down
1 change: 0 additions & 1 deletion src/integration tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,6 @@ describe("Copilot Integration Tests", () => {
});
});


describe("Cache Modes", () => {
beforeEach(() => {
mockPromptHandler.runPrompt.mockResolvedValue("// No operation");
Expand Down
2 changes: 1 addition & 1 deletion src/types/framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type TestingFrameworkAPICatalog = {
context: any;
/** Available API method categories */
categories: TestingFrameworkAPICatalogCategory[];
/** List of restrictions and guidlines of wrong actions */
/** List of restrictions and guidlines of wrong actions */
restrictions?: string[];
};

Expand Down
Loading

0 comments on commit 6a8c13d

Please sign in to comment.