e2eReportingSummarySkipped.test.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { mkdtempSync, readFileSync, rmSync } from "node:fs";
  2. import { tmpdir } from "node:os";
  3. import { join } from "node:path";
  4. import { afterEach, describe, expect, it } from "vitest";
  5. import { appendJsonLine, writeE2ESummary } from "./e2e/reporting/e2e-reporting-summary.js";
  6. import type { TestResultLine } from "./e2e/reporting/e2e-reporting-types.js";
  7. const tempDirs: string[] = [];
  8. function createTempDir() {
  9. const dir = mkdtempSync(join(tmpdir(), "e2e-summary-skipped-"));
  10. tempDirs.push(dir);
  11. return dir;
  12. }
  13. describe("e2e reporting summary skipped tests", () => {
  14. afterEach(() => {
  15. for (const dir of tempDirs.splice(0)) {
  16. rmSync(dir, { recursive: true, force: true });
  17. }
  18. });
  19. it("does not count WDIO skipped tests as failures", () => {
  20. const artifactDir = createTempDir();
  21. const testsPath = join(artifactDir, "test-results.ndjson");
  22. const summaryJsonPath = join(artifactDir, "summary.json");
  23. const summaryMdPath = join(artifactDir, "summary.md");
  24. appendJsonLine(testsPath, {
  25. capturedAt: "2026-07-09T00:00:00.000Z",
  26. durationMs: 0,
  27. fullTitle: "file tools POSIX executable bit",
  28. passed: false,
  29. status: "skipped",
  30. title: "file tools POSIX executable bit",
  31. } satisfies TestResultLine);
  32. appendJsonLine(testsPath, {
  33. capturedAt: "2026-07-09T00:00:01.000Z",
  34. durationMs: 100,
  35. fullTitle: "actual failing case",
  36. passed: false,
  37. status: "failed",
  38. title: "actual failing case",
  39. errorCategory: "assertion",
  40. } satisfies TestResultLine);
  41. appendJsonLine(testsPath, {
  42. capturedAt: "2026-07-09T00:00:02.000Z",
  43. durationMs: 50,
  44. fullTitle: "passing case",
  45. passed: true,
  46. status: "passed",
  47. title: "passing case",
  48. } satisfies TestResultLine);
  49. writeE2ESummary({
  50. artifactDir,
  51. containerE2E: false,
  52. containerSamplesPath: join(artifactDir, "container-samples.ndjson"),
  53. exitCode: 1,
  54. manifestPath: join(artifactDir, "manifest.json"),
  55. perfDir: join(artifactDir, "perf"),
  56. requestedSpecs: [],
  57. runId: "skipped-summary",
  58. startedAt: new Date("2026-07-09T00:00:00.000Z"),
  59. summaryJsonPath,
  60. summaryMdPath,
  61. testsPath,
  62. });
  63. const summary = JSON.parse(readFileSync(summaryJsonPath, "utf-8"));
  64. const summaryMd = readFileSync(summaryMdPath, "utf-8");
  65. expect(summary.tests.total).toBe(3);
  66. expect(summary.tests.passed).toBe(1);
  67. expect(summary.tests.failed).toBe(1);
  68. expect(summary.tests.skipped).toBe(1);
  69. expect(summary.stability.passRate).toBe(0.5);
  70. expect(summary.failureBreakdown.assertion).toBe(1);
  71. expect(summary.failureBreakdown.unknown).toBe(0);
  72. expect(summary.timing.caseDurationP50Ms).toBe(50);
  73. expect(summaryMd).toContain("- Skipped: `1`");
  74. expect(summaryMd).toContain("| SKIP | 0ms | file tools POSIX executable bit |");
  75. });
  76. it("treats legacy skipped rows without status as skipped", () => {
  77. const artifactDir = createTempDir();
  78. const testsPath = join(artifactDir, "test-results.ndjson");
  79. const summaryJsonPath = join(artifactDir, "summary.json");
  80. const summaryMdPath = join(artifactDir, "summary.md");
  81. appendJsonLine(testsPath, {
  82. capturedAt: "2026-07-09T00:00:00.000Z",
  83. durationMs: 0,
  84. errorCategory: "unknown",
  85. fullTitle: "Write 和 Edit 修改可执行脚本后应保留 POSIX 执行位",
  86. passed: false,
  87. title: "Write 和 Edit 修改可执行脚本后应保留 POSIX 执行位",
  88. });
  89. writeE2ESummary({
  90. artifactDir,
  91. containerE2E: false,
  92. containerSamplesPath: join(artifactDir, "container-samples.ndjson"),
  93. exitCode: 0,
  94. manifestPath: join(artifactDir, "manifest.json"),
  95. perfDir: join(artifactDir, "perf"),
  96. requestedSpecs: [],
  97. runId: "legacy-skipped-summary",
  98. startedAt: new Date("2026-07-09T00:00:00.000Z"),
  99. summaryJsonPath,
  100. summaryMdPath,
  101. testsPath,
  102. });
  103. const summary = JSON.parse(readFileSync(summaryJsonPath, "utf-8"));
  104. expect(summary.tests.total).toBe(1);
  105. expect(summary.tests.failed).toBe(0);
  106. expect(summary.tests.skipped).toBe(1);
  107. expect(summary.failureBreakdown.unknown).toBe(0);
  108. });
  109. });