mobilePairingDiagnostics.test.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { describe, expect, it } from "vitest";
  2. import { redactMobileDiagnosticText } from "./e2e/helpers/mobile-pairing.js";
  3. describe("手机配对失败证据脱敏", () => {
  4. it("移除完整链接和单独出现的 query/hash 配对材料", () => {
  5. const url = "https://mobile.test/remote/?pairingKey=query-secret#token=hash-secret";
  6. const value = redactMobileDiagnosticText(`goto ${url}; query-secret; hash-secret`, url);
  7. expect(value).toContain("https://mobile.test/remote/");
  8. expect(value).not.toContain("query-secret");
  9. expect(value).not.toContain("hash-secret");
  10. expect(value).not.toContain("pairingKey=");
  11. });
  12. it("保留资源路径以定位加载错误,去掉其他 URL 的查询参数", () => {
  13. const value = redactMobileDiagnosticText(
  14. "failed https://cdn.test/assets/main.js?signature=private: ERR_CONNECTION_RESET",
  15. "https://mobile.test/remote/?key=one-time-key",
  16. );
  17. expect(value).toBe("failed https://cdn.test/assets/main.js ERR_CONNECTION_RESET");
  18. });
  19. });
  20. it("新手机首页以指定项目内容就绪为准,不等待已退役的配对文案", async () => {
  21. const { mkdtemp, rm } = await import("node:fs/promises");
  22. const { join } = await import("node:path");
  23. const { tmpdir } = await import("node:os");
  24. const { vi } = await import("vitest");
  25. const { openMobilePairingPage } = await import("./e2e/helpers/mobile-pairing.js");
  26. const { artifactDir, readySelector } = {
  27. artifactDir: await mkdtemp(join(tmpdir(), "mobile-pairing-")),
  28. readySelector: '[data-testid="task-item-remote-fixture"]',
  29. };
  30. let ready = false;
  31. const content = {
  32. or: () => ({
  33. first: () => ({
  34. waitFor: async () => {
  35. ready = true;
  36. },
  37. }),
  38. }),
  39. waitFor: async () => {
  40. expect(ready).toBe(true);
  41. },
  42. };
  43. const page = {
  44. on: vi.fn(),
  45. off: vi.fn(),
  46. goto: vi.fn(),
  47. locator: (selector: string) => {
  48. expect(selector).toBe(readySelector);
  49. return content;
  50. },
  51. getByTestId: () => ({ isVisible: async () => false }),
  52. getByText: () => {
  53. throw new Error("旧配对文案已删除");
  54. },
  55. };
  56. try {
  57. await openMobilePairingPage(
  58. page as unknown as import("playwright-core").Page,
  59. "https://mobile.test/remote/?key=fixture",
  60. { artifactDir, readySelector, caseMarker: "E2E_MOBILE", phase: "initial" },
  61. );
  62. expect(ready).toBe(true);
  63. } finally {
  64. await rm(artifactDir, { recursive: true, force: true });
  65. }
  66. });