дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
Typing npx (or pnpm exec, bunx, yarn) in Run Anything lists the executables installed in node_modules/.bin from the current file's package up to the project root, the current package first and its direct dependencies' bins first within a package. Typing filters, Tab completes, and Enter runs the command as an npm-kind configuration in that package folder. A typed line with arguments runs in the first package that has the executable; an executable that isn't installed or a line with shell syntax still goes to the shell. Yarn 2+ offers only direct dependencies' bins; Bun .bunx shims and dangling links are skipped. Only the disk is read. The provider uses Run Anything's subscribe() to refresh the open popup when its background read finishes; reads are cached and dropped when node_modules or a package.json changes. Co-authored-by: wildcatDownstairs <[email protected]>
116 рядки
4.9 KiB
TypeScript
116 рядки
4.9 KiB
TypeScript
import { expect, test } from "./fixtures";
|
|
|
|
test("Run Anything keeps its command field and shortcuts visible as its results scroll", async ({
|
|
workbench: page,
|
|
}) => {
|
|
await page.setViewportSize({ width: 1080, height: 740 });
|
|
await page.evaluate(async () => {
|
|
const projectModule = "/src/platform/project.ts";
|
|
const contributionsModule = "/src/workbench/contributions.ts";
|
|
const historyModule = "/src/features/run-anything/model.ts";
|
|
const [{ useProject }, { registerRunAnythingProvider }, { pushHistory }] = await Promise.all([
|
|
import(/* @vite-ignore */ projectModule),
|
|
import(/* @vite-ignore */ contributionsModule),
|
|
import(/* @vite-ignore */ historyModule),
|
|
]);
|
|
const root = useProject.getState().project.root;
|
|
for (const command of ["git status", "git diff --stat", "pnpm lint", "pnpm test"]) pushHistory(root, command);
|
|
const tasks = Array.from({ length: 8 }, (_, i) => {
|
|
const command = `npm run verify-${i + 1}`;
|
|
return {
|
|
key: command,
|
|
label: `Verify checkout configuration ${i + 1}`,
|
|
detail: "checkout-service / workspace verification",
|
|
completion: command,
|
|
run: () => {
|
|
document.body.dataset.runAnythingCommand = command;
|
|
},
|
|
};
|
|
});
|
|
registerRunAnythingProvider({
|
|
id: "test-verify",
|
|
order: -100,
|
|
group: "Run Configurations",
|
|
items: (line: string) => tasks.filter((task) => task.completion.includes(line)),
|
|
});
|
|
});
|
|
await page.keyboard.press("Control");
|
|
await page.keyboard.press("Control");
|
|
|
|
const popup = page.getByRole("dialog", { name: "Run Anything", exact: true });
|
|
const field = popup.getByLabel("Command line", { exact: true });
|
|
const fieldSurface = field.locator("..");
|
|
const commandRow = fieldSurface.locator("..");
|
|
const results = popup.getByRole("listbox", { name: "Run Anything entries" });
|
|
const hint = popup.getByText(/Enter to run, Tab to complete|Tab to complete, Enter to run/);
|
|
await expect(field).toBeFocused();
|
|
await expect(fieldSurface).toHaveCSS("box-shadow", "none");
|
|
await expect(commandRow).toHaveCSS("border-bottom-width", "1px");
|
|
await expect(commandRow).toHaveCSS("border-left-width", "0px");
|
|
const focusedDivider = await commandRow.evaluate((el) => getComputedStyle(el).borderBottomColor);
|
|
await page.setViewportSize({ width: 560, height: 340 });
|
|
await expect
|
|
.poll(async () => {
|
|
const [shell, footer] = await Promise.all([popup.boundingBox(), hint.boundingBox()]);
|
|
return (
|
|
!!shell &&
|
|
!!footer &&
|
|
Math.abs(shell.x - (560 - shell.width) / 2) < 2 &&
|
|
shell.x >= 14 &&
|
|
footer.y + footer.height <= shell.y + shell.height + 1
|
|
);
|
|
})
|
|
.toBe(true);
|
|
await expect.poll(() => results.evaluate((el) => el.scrollHeight > el.clientHeight)).toBe(true);
|
|
|
|
await field.fill("verify");
|
|
await field.press("ArrowDown");
|
|
await expect(field).toHaveValue("npm run verify-1");
|
|
const selected = results.getByRole("option", { selected: true });
|
|
await expect(selected).toContainText("Verify checkout configuration 1");
|
|
await expect(field).toHaveAttribute("aria-activedescendant", (await selected.getAttribute("id"))!);
|
|
await field.press("Tab");
|
|
await expect(field).toHaveValue("npm run verify-1");
|
|
await expect(field).toBeFocused();
|
|
await field.press("Shift+Tab");
|
|
const history = popup.getByRole("button", { name: "Clear History" });
|
|
await expect(history).toBeFocused();
|
|
await expect(commandRow).not.toHaveCSS("border-bottom-color", focusedDivider);
|
|
await history.press("Enter");
|
|
await expect(history).toBeHidden();
|
|
await expect(field).toBeFocused();
|
|
await field.press("ArrowDown");
|
|
await field.press("Enter");
|
|
await expect(popup).toBeHidden();
|
|
await expect(page.locator("body")).toHaveAttribute("data-run-anything-command", "npm run verify-1");
|
|
});
|
|
|
|
test("Run Anything shows entries a provider reads in the background without another keystroke", async ({
|
|
workbench: page,
|
|
}) => {
|
|
await page.evaluate(async () => {
|
|
const contributionsModule = "/src/workbench/contributions.ts";
|
|
const { registerRunAnythingProvider } = await import(/* @vite-ignore */ contributionsModule);
|
|
let loaded = false;
|
|
registerRunAnythingProvider({
|
|
id: "test-background",
|
|
order: -100,
|
|
group: "Package Executables",
|
|
items: (line: string) =>
|
|
loaded && line.startsWith("npx") ? [{ key: "vite", label: "npx vite", completion: "npx vite ", run() {} }] : [],
|
|
subscribe(onChange: () => void) {
|
|
const timer = setTimeout(() => {
|
|
loaded = true;
|
|
onChange();
|
|
}, 300);
|
|
return () => clearTimeout(timer);
|
|
},
|
|
});
|
|
});
|
|
await page.keyboard.press("Control");
|
|
await page.keyboard.press("Control");
|
|
const popup = page.getByRole("dialog", { name: "Run Anything", exact: true });
|
|
await popup.getByLabel("Command line", { exact: true }).pressSequentially("npx ");
|
|
await expect(popup.getByRole("option", { name: /npx vite/ })).toBeVisible();
|
|
});
|