Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions desktop/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { defineConfig, devices } from "@playwright/test";

import { staticWebServer } from "./tests/helpers/staticWebServer";

export default defineConfig({
testDir: "./tests/e2e",
timeout: 30_000,
Expand Down Expand Up @@ -174,10 +176,5 @@ export default defineConfig({
},
},
],
webServer: {
command: "python3 -m http.server 4173 -d dist",
cwd: ".",
reuseExistingServer: !process.env.CI,
url: "http://127.0.0.1:4173",
},
webServer: staticWebServer({ reuseExistingServer: !process.env.CI }),
});
9 changes: 3 additions & 6 deletions desktop/playwright.perf.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { defineConfig, devices } from "@playwright/test";

import { staticWebServer } from "./tests/helpers/staticWebServer";

export default defineConfig({
testDir: "./tests/e2e",
timeout: 60_000,
Expand All @@ -14,10 +16,5 @@ export default defineConfig({
use: { ...devices["Desktop Chrome"] },
},
],
webServer: {
command: "python3 -m http.server 4173 -d dist",
cwd: ".",
reuseExistingServer: true,
url: "http://127.0.0.1:4173",
},
webServer: staticWebServer({ reuseExistingServer: true }),
});
11 changes: 10 additions & 1 deletion desktop/tests/e2e/messaging.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,17 @@ test("copy a rendered code block and paste it back as code", async ({
await codeBlock.hover();
await expect(copyButton).toHaveCSS("opacity", "1");
await copyButton.click();
// Chromium hands back CRLF when it reads text/plain off the Windows
// clipboard, so compare logical lines rather than the platform separator.
// The app writes LF: `copyCodeBlockToClipboard` puts `code` in the blob
// verbatim.
await expect
.poll(() => page.evaluate(() => navigator.clipboard.readText()))
.poll(async () =>
(await page.evaluate(() => navigator.clipboard.readText())).replace(
/\r\n/g,
"\n",
),
)
.toBe(code);

await input.click();
Expand Down
40 changes: 40 additions & 0 deletions desktop/tests/helpers/staticWebServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { spawnSync } from "node:child_process";

const PORT = 4173;

/**
* `python3` is the right name on Linux and macOS. On Windows it is normally
* the Microsoft Store app-execution alias, which prints an install hint and
* exits 9009 even when a real interpreter is installed as `python`. Playwright
* then reports only `Process from config.webServer was not able to start.
* Exit code: 9009`, so the suite cannot be run at all on a stock Windows box.
*
* Probe the candidates rather than guessing. `-c ""` is a no-op that a real
* interpreter accepts and the alias stub rejects.
*/
function resolvePythonCommand() {
const candidates =
process.platform === "win32"
? ["python", "python3"]
: ["python3", "python"];

for (const candidate of candidates) {
const probe = spawnSync(candidate, ["-c", ""], { stdio: "ignore" });
if (!probe.error && probe.status === 0) {
return candidate;
}
}

// Nothing answered. Keep the historical name so the failure still points at
// the missing interpreter instead of at this helper.
return "python3";
}

export function staticWebServer(options: { reuseExistingServer: boolean }) {
return {
command: `${resolvePythonCommand()} -m http.server ${PORT} -d dist`,
cwd: ".",
reuseExistingServer: options.reuseExistingServer,
url: `http://127.0.0.1:${PORT}`,
};
}