Skip to content

Commit 6ce0cb6

Browse files
authored
Fix summary generation (#181)
1 parent 11f3c4c commit 6ce0cb6

17 files changed

Lines changed: 145 additions & 32 deletions

File tree

packages/core/src/report.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import console from "node:console";
1313
import { randomUUID } from "node:crypto";
1414
import { EventEmitter } from "node:events";
1515
import { readFileSync } from "node:fs";
16-
import { opendir, readdir, realpath, rename, rm } from "node:fs/promises";
16+
import { lstat, opendir, readdir, realpath, rename, rm } from "node:fs/promises";
1717
import { dirname, join, resolve } from "node:path";
1818
import type { FullConfig, PluginInstance } from "./api.js";
1919
import { createHistory, writeHistory } from "./history.js";
@@ -213,8 +213,17 @@ export class AllureReport {
213213

214214
const outputDirFiles = await readdir(this.#output);
215215

216-
if (outputDirFiles.length === 1) {
217-
const reportPath = join(this.#output, outputDirFiles[0]);
216+
// just do nothing if there is no reports in the output directory
217+
if (outputDirFiles.length === 0) {
218+
return;
219+
}
220+
221+
const reportPath = join(this.#output, outputDirFiles[0]);
222+
const outputEntriesStats = await Promise.all(outputDirFiles.map((file) => lstat(join(this.#output, file))));
223+
const outputDirectoryEntries = outputEntriesStats.filter((entry) => entry.isDirectory());
224+
225+
// if there is a single report directory in the output directory, move it to the root and prevent summary generation
226+
if (outputDirectoryEntries.length === 1) {
218227
const reportContent = await readdir(reportPath);
219228

220229
for (const entry of reportContent) {
@@ -228,11 +237,9 @@ export class AllureReport {
228237
return;
229238
}
230239

231-
if (summaries.length === 0) {
232-
return;
240+
if (summaries.length > 1) {
241+
await generateSummary(this.#output, summaries);
233242
}
234-
235-
await generateSummary(this.#output, summaries);
236243
};
237244

238245
#eachPlugin = async (

packages/e2e/test/allure-awesome/features/attachments.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Stage, Status, label } from "allure-js-commons";
33
import { readFile } from "node:fs/promises";
44
import { dirname as pathDirname, resolve } from "node:path";
55
import { fileURLToPath } from "node:url";
6-
import { TestResultPage, TreePage } from "../pageObjects/index.js";
6+
import { TestResultPage, TreePage } from "../../pageObjects/index.js";
77
import { type ReportBootstrap, bootstrapReport } from "../utils/index.js";
88

99
const dirname = pathDirname(fileURLToPath(import.meta.url));

packages/e2e/test/allure-awesome/test/environments.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type Page, expect, test } from "@playwright/test";
22
import { Stage, Status, label } from "allure-js-commons";
3-
import { CommonPage, TestResultPage, TreePage } from "../pageObjects/index.js";
3+
import { CommonPage, TestResultPage, TreePage } from "../../pageObjects/index.js";
44
import { type ReportBootstrap, bootstrapReport } from "../utils/index.js";
55

66
let bootstrap: ReportBootstrap;

packages/e2e/test/allure-awesome/test/reportOptions.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import AwesomePlugin from "@allurereport/plugin-awesome";
22
import { expect, test } from "@playwright/test";
33
import { Stage, Status, label } from "allure-js-commons";
4+
import { CommonPage, TreePage } from "../../pageObjects/index.js";
45
import { type ReportBootstrap, bootstrapReport } from "../../utils/index.js";
5-
import { CommonPage, TreePage } from "../pageObjects/index.js";
66

77
let bootstrap: ReportBootstrap;
88
let commonPage: CommonPage;
@@ -86,7 +86,7 @@ test.describe("allure-awesome", () => {
8686
});
8787

8888
await page.goto(bootstrap.url);
89-
await expect(commonPage.singleLayoutLocator).toBeHidden();
89+
await expect(commonPage.baseLayoutLocator).toBeHidden();
9090
await expect(commonPage.splitLayoutLocator).toBeVisible();
9191
});
9292

@@ -111,7 +111,7 @@ test.describe("allure-awesome", () => {
111111
});
112112

113113
await page.goto(bootstrap.url);
114-
await expect(commonPage.singleLayoutLocator).toBeVisible();
114+
await expect(commonPage.baseLayoutLocator).toBeVisible();
115115
await expect(commonPage.splitLayoutLocator).toBeHidden();
116116
});
117117

@@ -138,10 +138,10 @@ test.describe("allure-awesome", () => {
138138
await page.goto(bootstrap.url);
139139
await commonPage.toggleLayout();
140140
await expect(commonPage.splitLayoutLocator).toBeVisible();
141-
await expect(commonPage.singleLayoutLocator).toBeHidden();
141+
await expect(commonPage.baseLayoutLocator).toBeHidden();
142142
await commonPage.toggleLayout();
143143
await expect(commonPage.splitLayoutLocator).toBeHidden();
144-
await expect(commonPage.singleLayoutLocator).toBeVisible();
144+
await expect(commonPage.baseLayoutLocator).toBeVisible();
145145
});
146146
});
147147

packages/e2e/test/allure-awesome/test/testResult.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import AwesomePlugin from "@allurereport/plugin-awesome";
22
import { expect, test } from "@playwright/test";
33
import { Stage, Status, label } from "allure-js-commons";
4+
import { TestResultPage, TreePage } from "../../pageObjects/index.js";
45
import { type ReportBootstrap, bootstrapReport } from "../../utils/index.js";
5-
import { TestResultPage, TreePage } from "../pageObjects/index.js";
66

77
let bootstrap: ReportBootstrap;
88
let treePage: TreePage;

packages/e2e/test/allure-awesome/test/tree.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from "@playwright/test";
22
import { Stage, Status, label } from "allure-js-commons";
3-
import { TestResultPage, TreePage } from "../pageObjects/index.js";
3+
import { TestResultPage, TreePage } from "../../pageObjects/index.js";
44
import { type ReportBootstrap, bootstrapReport } from "../utils/index.js";
55

66
let bootstrap: ReportBootstrap;

packages/e2e/test/allure-awesome/tree/flaky.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect, test } from "@playwright/test";
22
import { Stage, Status, label } from "allure-js-commons";
3+
import { TreePage } from "../../pageObjects/index.js";
34
import { makeHistoryId, makeTestCaseId } from "../../utils/index.js";
4-
import { TreePage } from "../pageObjects/index.js";
55
import { type ReportBootstrap, bootstrapReport } from "../utils/index.js";
66

77
let bootstrap: ReportBootstrap;

packages/e2e/test/allure-awesome/tree/retries.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from "@playwright/test";
22
import { Stage, Status, label } from "allure-js-commons";
3-
import { TreePage } from "../pageObjects/index.js";
3+
import { TreePage } from "../../pageObjects/index.js";
44
import { type ReportBootstrap, bootstrapReport } from "../utils/index.js";
55

66
let bootstrap: ReportBootstrap;

packages/e2e/test/commons/summary.test.ts

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,97 @@
11
import AwesomePlugin from "@allurereport/plugin-awesome";
22
import { expect, test } from "@playwright/test";
33
import { Stage, Status } from "allure-js-commons";
4+
import { CommonPage, SummaryPage } from "../pageObjects/index.js";
45
import { AwesomePluginWithoutSummary, type ReportBootstrap, bootstrapReport } from "../utils/index.js";
56

67
let bootstrap: ReportBootstrap;
8+
let summaryPage: SummaryPage;
9+
let commonPage: CommonPage;
710

811
test.afterAll(async () => {
912
await bootstrap?.shutdown?.();
1013
});
1114

15+
test.beforeEach(async ({ page }) => {
16+
commonPage = new CommonPage(page);
17+
summaryPage = new SummaryPage(page);
18+
});
19+
1220
test.describe("summary", () => {
21+
test("should not generate summary for a single report", async ({ page }) => {
22+
bootstrap = await bootstrapReport({
23+
reportConfig: {
24+
name: "Sample allure report",
25+
appendHistory: false,
26+
history: undefined,
27+
historyPath: undefined,
28+
knownIssuesPath: undefined,
29+
plugins: [
30+
{
31+
id: "awesome1",
32+
enabled: true,
33+
plugin: new AwesomePlugin({}),
34+
options: {},
35+
},
36+
],
37+
},
38+
testResults: [
39+
{
40+
name: "0 sample passed test",
41+
fullName: "sample.js#0 sample passed test",
42+
status: Status.PASSED,
43+
stage: Stage.FINISHED,
44+
start: 1000,
45+
},
46+
],
47+
});
48+
49+
await page.goto(bootstrap.url);
50+
51+
await expect(summaryPage.reportCardLocator).not.toBeVisible();
52+
await expect(commonPage.baseLayoutLocator).toBeVisible();
53+
});
54+
55+
test("should not generate summary on the single report re-generation", async ({ page }) => {
56+
bootstrap = await bootstrapReport({
57+
reportConfig: {
58+
name: "Sample allure report",
59+
appendHistory: false,
60+
history: undefined,
61+
historyPath: undefined,
62+
knownIssuesPath: undefined,
63+
plugins: [
64+
{
65+
id: "awesome1",
66+
enabled: true,
67+
plugin: new AwesomePlugin({}),
68+
options: {},
69+
},
70+
],
71+
},
72+
testResults: [
73+
{
74+
name: "0 sample passed test",
75+
fullName: "sample.js#0 sample passed test",
76+
status: Status.PASSED,
77+
stage: Stage.FINISHED,
78+
start: 1000,
79+
},
80+
],
81+
});
82+
83+
await page.goto(bootstrap.url);
84+
85+
await expect(summaryPage.reportCardLocator).not.toBeVisible();
86+
await expect(commonPage.baseLayoutLocator).toBeVisible();
87+
88+
await bootstrap.regenerate();
89+
await page.reload();
90+
91+
await expect(summaryPage.reportCardLocator).not.toBeVisible();
92+
await expect(commonPage.baseLayoutLocator).toBeVisible();
93+
});
94+
1395
test("should render cards for each generated report with summary", async ({ page, context }) => {
1496
bootstrap = await bootstrapReport({
1597
reportConfig: {
@@ -43,18 +125,17 @@ test.describe("summary", () => {
43125
},
44126
],
45127
});
46-
const summaryCardsLocator = page.getByTestId("summary-report-card");
47128

48129
await page.goto(bootstrap.url);
49130

50-
await expect(summaryCardsLocator).toHaveCount(2);
131+
await expect(summaryPage.reportCardLocator).toHaveCount(2);
51132

52133
const pageUrl = page.url();
53134

54135
expect(context.pages()).toHaveLength(1);
55136
expect(context.pages()[0].url()).toBe(pageUrl);
56137

57-
const [newTab] = await Promise.all([context.waitForEvent("page"), await summaryCardsLocator.nth(0).click()]);
138+
const [newTab] = await Promise.all([context.waitForEvent("page"), await summaryPage.clickReportCard(0)]);
58139

59140
expect(context.pages()[0].url()).toBe(pageUrl);
60141
expect(newTab.url()).not.toBe(`${pageUrl}awesome1/index.html`);
@@ -99,10 +180,9 @@ test.describe("summary", () => {
99180
},
100181
],
101182
});
102-
const summaryCardsLocator = page.getByTestId("summary-report-card");
103183

104184
await page.goto(bootstrap.url);
105185

106-
await expect(summaryCardsLocator).toHaveCount(2);
186+
await expect(summaryPage.reportCardLocator).toHaveCount(2);
107187
});
108188
});

packages/e2e/test/allure-awesome/pageObjects/Common.ts renamed to packages/e2e/test/pageObjects/Common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class CommonPage extends PageObject {
66

77
toggleLayoutButtonLocator: Locator;
88
splitLayoutLocator: Locator;
9-
singleLayoutLocator: Locator;
9+
baseLayoutLocator: Locator;
1010

1111
envPickerLocator: Locator;
1212
envPickerButtonLocator: Locator;
@@ -18,7 +18,7 @@ export class CommonPage extends PageObject {
1818

1919
this.toggleLayoutButtonLocator = page.getByTestId("toggle-layout-button");
2020
this.splitLayoutLocator = page.getByTestId("split-layout");
21-
this.singleLayoutLocator = page.getByTestId("base-layout");
21+
this.baseLayoutLocator = page.getByTestId("base-layout");
2222

2323
this.envPickerLocator = page.getByTestId("environment-picker");
2424
this.envPickerButtonLocator = page.getByTestId("environment-picker-button");

0 commit comments

Comments
 (0)