Skip to content

Commit

Permalink
stepWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
midleman committed Jan 13, 2025
1 parent af60103 commit 8e3295f
Showing 1 changed file with 32 additions and 27 deletions.
59 changes: 32 additions & 27 deletions test/e2e/pages/quickaccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,27 @@ export class QuickAccess {
}

async openFile(path: string): Promise<void> {
if (!isAbsolute(path)) {
// we require absolute paths to get a single
// result back that is unique and avoid hitting
// the search process to reduce chances of
// search needing longer.
throw new Error('QuickAccess.openFile requires an absolute path');
}
await test.step('Open file', async () => {
if (!isAbsolute(path)) {
// we require absolute paths to get a single
// result back that is unique and avoid hitting
// the search process to reduce chances of
// search needing longer.
throw new Error('QuickAccess.openFile requires an absolute path');
}

const fileName = basename(path);
const fileName = basename(path);

// quick access shows files with the basename of the path
await this.openFileQuickAccessAndWait(path, basename(path));
// quick access shows files with the basename of the path
await this.openFileQuickAccessAndWait(path, basename(path));

// open first element
await this.quickInput.selectQuickInputElement(0);
// open first element
await this.quickInput.selectQuickInputElement(0);

// wait for editor being focused
await this.editors.waitForActiveTab(fileName);
await this.editors.selectTab(fileName);
// wait for editor being focused
await this.editors.waitForActiveTab(fileName);
await this.editors.selectTab(fileName);
});
}

private async openQuickAccessWithRetry(kind: QuickAccessKind, value?: string): Promise<void> {
Expand Down Expand Up @@ -151,39 +153,42 @@ export class QuickAccess {


async runCommand(commandId: string, options?: { keepOpen?: boolean; exactLabelMatch?: boolean }): Promise<void> {
await test.step(`Run command: ${commandId}`, async () => {
const stepWrapper = (label: string, fn: () => Promise<void>) => {
try {
// Check if running in a test context
if (test.info().title) {
return test.step(label, fn); // Use test.step if inside a test
}
} catch (e) {
// Catch errors if not in a test context
}
return fn(); // Run directly if not in a test
};

await stepWrapper(`Run command: ${commandId}`, async () => {
const keepOpen = options?.keepOpen;
const exactLabelMatch = options?.exactLabelMatch;

const openCommandPalletteAndTypeCommand = async (): Promise<boolean> => {
// open commands picker
await this.openQuickAccessWithRetry(QuickAccessKind.Commands, `>${commandId}`);

// wait for quick input element text
const text = await this.quickInput.waitForQuickInputElementText();

if (text === 'No matching commands' || (exactLabelMatch && text !== commandId)) {
return false;
}

return true;
return !(text === 'No matching commands' || (exactLabelMatch && text !== commandId));
};

await expect(async () => {
const hasCommandFound = await openCommandPalletteAndTypeCommand();
if (!hasCommandFound) {
this.code.logger.log(`QuickAccess: No matching commands, retrying...`);
await this.quickInput.closeQuickInput();
throw new Error('Command not found'); // Signal to retry
throw new Error('Command not found');
}
}).toPass({
timeout: 15000,
intervals: [1000],
});

this.code.logger.log('QuickAccess: Command found and successfully executed.');

// wait and click on best choice
await this.quickInput.selectQuickInputElement(0, keepOpen);
});
}
Expand Down

0 comments on commit 8e3295f

Please sign in to comment.