plugin-concurrent-install.test.mjs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import assert from "node:assert/strict";
  2. import { after, before, test } from "node:test";
  3. import { mkdir, writeFile } from "node:fs/promises";
  4. import { join } from "node:path";
  5. import { tmpdir } from "node:os";
  6. import { fileURLToPath } from "node:url";
  7. import { createServer } from "vite";
  8. import react from "@vitejs/plugin-react";
  9. import tailwindcss from "@tailwindcss/vite";
  10. import { chromium } from "playwright-core";
  11. const root = fileURLToPath(new URL("../../../../../../", import.meta.url));
  12. const entry =
  13. "/packages/ui/test/browser/manual-review/pending/plugin-concurrent-install.fixture.tsx";
  14. let server;
  15. let browser;
  16. let origin;
  17. before(async () => {
  18. server = await createServer({
  19. root,
  20. configFile: false,
  21. plugins: [
  22. react(),
  23. tailwindcss(),
  24. {
  25. name: "responsive-fixture",
  26. configureServer(vite) {
  27. vite.middlewares.use(async (req, res, next) => {
  28. if (!req.url?.startsWith("/fixture?")) return next();
  29. res.setHeader("Content-Type", "text/html");
  30. res.end(
  31. await vite.transformIndexHtml(
  32. req.url,
  33. `<html><head><meta name="viewport" content="width=device-width, initial-scale=1" /></head><body><div id="root"></div><script type="module" src="${entry}"></script></body></html>`,
  34. ),
  35. );
  36. });
  37. },
  38. },
  39. ],
  40. resolve: { alias: { "@": `${root}packages/ui/src` } },
  41. optimizeDeps: { entries: [entry.slice(1)] },
  42. server: { host: "127.0.0.1", port: 0 },
  43. });
  44. await server.listen();
  45. origin = server.resolvedUrls.local[0];
  46. browser = await chromium.launch(
  47. process.env.CHROME_EXECUTABLE_PATH
  48. ? { executablePath: process.env.CHROME_EXECUTABLE_PATH }
  49. : { channel: "chrome" },
  50. );
  51. });
  52. after(async () => {
  53. await browser?.close();
  54. await server?.close();
  55. });
  56. const artifacts = join(tmpdir(), "zcode-plugin-concurrent-install");
  57. for (const width of [390, 1200])
  58. for (const locale of ["en-US", "zh-CN"])
  59. for (const theme of ["light", "dark"]) {
  60. test(`PLM-CONCURRENT-INSTALL ${width}/${locale}/${theme}`, async () => {
  61. const page = await browser.newPage({ viewport: { width, height: 700 } });
  62. const logs = [];
  63. page.on("console", (message) => logs.push(message.text()));
  64. try {
  65. await page.goto(`${origin}fixture?locale=${locale}&theme=${theme}`);
  66. const first = page.getByTestId("plugin-store-install").filter({ hasText: /./ }).nth(0);
  67. const second = page.getByTestId("plugin-store-install").nth(1);
  68. await first.click();
  69. await second.click();
  70. assert.equal(await first.isDisabled(), true, "starting B must keep A disabled");
  71. assert.equal(await second.isDisabled(), true);
  72. const busy = locale === "zh-CN" ? "安装中" : "Installing";
  73. assert.ok((await first.textContent()).includes(busy));
  74. assert.ok((await second.textContent()).includes(busy));
  75. await page.getByTestId("finish-second").click();
  76. await page.waitForFunction(
  77. () => !document.querySelectorAll('[data-testid="plugin-store-install"]')[1].disabled,
  78. );
  79. assert.equal(await first.isDisabled(), true, "finishing B must keep A busy");
  80. await page.getByTestId("finish-first").click();
  81. await page.waitForFunction(
  82. () => !document.querySelector('[data-testid="plugin-store-install"]').disabled,
  83. );
  84. await mkdir(artifacts, { recursive: true });
  85. await page.screenshot({ path: join(artifacts, `${width}-${locale}-${theme}.png`) });
  86. await writeFile(join(artifacts, `${width}-${locale}-${theme}.log`), logs.join("\n"));
  87. assert.ok(logs.some((line) => line.includes("install-state")));
  88. } finally {
  89. await page.close();
  90. }
  91. });
  92. }