Skip to content
Merged
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
21 changes: 14 additions & 7 deletions packages/core/src/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import console from "node:console";
import { randomUUID } from "node:crypto";
import { EventEmitter } from "node:events";
import { readFileSync } from "node:fs";
import { opendir, readdir, realpath, rename, rm } from "node:fs/promises";
import { lstat, opendir, readdir, realpath, rename, rm } from "node:fs/promises";
import { dirname, join, resolve } from "node:path";
import type { FullConfig, PluginInstance } from "./api.js";
import { createHistory, writeHistory } from "./history.js";
Expand Down Expand Up @@ -213,8 +213,17 @@ export class AllureReport {

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

if (outputDirFiles.length === 1) {
const reportPath = join(this.#output, outputDirFiles[0]);
// just do nothing if there is no reports in the output directory
if (outputDirFiles.length === 0) {
return;
}

const reportPath = join(this.#output, outputDirFiles[0]);
const outputEntriesStats = await Promise.all(outputDirFiles.map((file) => lstat(join(this.#output, file))));
const outputDirectoryEntries = outputEntriesStats.filter((entry) => entry.isDirectory());

// if there is a single report directory in the output directory, move it to the root and prevent summary generation
if (outputDirectoryEntries.length === 1) {
const reportContent = await readdir(reportPath);

for (const entry of reportContent) {
Expand All @@ -228,11 +237,9 @@ export class AllureReport {
return;
}

if (summaries.length === 0) {
return;
if (summaries.length > 1) {
await generateSummary(this.#output, summaries);
}

await generateSummary(this.#output, summaries);
};

#eachPlugin = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Stage, Status, label } from "allure-js-commons";
import { readFile } from "node:fs/promises";
import { dirname as pathDirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { TestResultPage, TreePage } from "../pageObjects/index.js";
import { TestResultPage, TreePage } from "../../pageObjects/index.js";
import { type ReportBootstrap, bootstrapReport } from "../utils/index.js";

const dirname = pathDirname(fileURLToPath(import.meta.url));
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/test/allure-awesome/test/environments.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Page, expect, test } from "@playwright/test";
import { Stage, Status, label } from "allure-js-commons";
import { CommonPage, TestResultPage, TreePage } from "../pageObjects/index.js";
import { CommonPage, TestResultPage, TreePage } from "../../pageObjects/index.js";
import { type ReportBootstrap, bootstrapReport } from "../utils/index.js";

let bootstrap: ReportBootstrap;
Expand Down
10 changes: 5 additions & 5 deletions packages/e2e/test/allure-awesome/test/reportOptions.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import AwesomePlugin from "@allurereport/plugin-awesome";
import { expect, test } from "@playwright/test";
import { Stage, Status, label } from "allure-js-commons";
import { CommonPage, TreePage } from "../../pageObjects/index.js";
import { type ReportBootstrap, bootstrapReport } from "../../utils/index.js";
import { CommonPage, TreePage } from "../pageObjects/index.js";

let bootstrap: ReportBootstrap;
let commonPage: CommonPage;
Expand Down Expand Up @@ -86,7 +86,7 @@ test.describe("allure-awesome", () => {
});

await page.goto(bootstrap.url);
await expect(commonPage.singleLayoutLocator).toBeHidden();
await expect(commonPage.baseLayoutLocator).toBeHidden();
await expect(commonPage.splitLayoutLocator).toBeVisible();
});

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

await page.goto(bootstrap.url);
await expect(commonPage.singleLayoutLocator).toBeVisible();
await expect(commonPage.baseLayoutLocator).toBeVisible();
await expect(commonPage.splitLayoutLocator).toBeHidden();
});

Expand All @@ -138,10 +138,10 @@ test.describe("allure-awesome", () => {
await page.goto(bootstrap.url);
await commonPage.toggleLayout();
await expect(commonPage.splitLayoutLocator).toBeVisible();
await expect(commonPage.singleLayoutLocator).toBeHidden();
await expect(commonPage.baseLayoutLocator).toBeHidden();
await commonPage.toggleLayout();
await expect(commonPage.splitLayoutLocator).toBeHidden();
await expect(commonPage.singleLayoutLocator).toBeVisible();
await expect(commonPage.baseLayoutLocator).toBeVisible();
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/test/allure-awesome/test/testResult.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import AwesomePlugin from "@allurereport/plugin-awesome";
import { expect, test } from "@playwright/test";
import { Stage, Status, label } from "allure-js-commons";
import { TestResultPage, TreePage } from "../../pageObjects/index.js";
import { type ReportBootstrap, bootstrapReport } from "../../utils/index.js";
import { TestResultPage, TreePage } from "../pageObjects/index.js";

let bootstrap: ReportBootstrap;
let treePage: TreePage;
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/test/allure-awesome/test/tree.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from "@playwright/test";
import { Stage, Status, label } from "allure-js-commons";
import { TestResultPage, TreePage } from "../pageObjects/index.js";
import { TestResultPage, TreePage } from "../../pageObjects/index.js";
import { type ReportBootstrap, bootstrapReport } from "../utils/index.js";

let bootstrap: ReportBootstrap;
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/test/allure-awesome/tree/flaky.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from "@playwright/test";
import { Stage, Status, label } from "allure-js-commons";
import { TreePage } from "../../pageObjects/index.js";
import { makeHistoryId, makeTestCaseId } from "../../utils/index.js";
import { TreePage } from "../pageObjects/index.js";
import { type ReportBootstrap, bootstrapReport } from "../utils/index.js";

let bootstrap: ReportBootstrap;
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/test/allure-awesome/tree/retries.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from "@playwright/test";
import { Stage, Status, label } from "allure-js-commons";
import { TreePage } from "../pageObjects/index.js";
import { TreePage } from "../../pageObjects/index.js";
import { type ReportBootstrap, bootstrapReport } from "../utils/index.js";

let bootstrap: ReportBootstrap;
Expand Down
90 changes: 85 additions & 5 deletions packages/e2e/test/commons/summary.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,97 @@
import AwesomePlugin from "@allurereport/plugin-awesome";
import { expect, test } from "@playwright/test";
import { Stage, Status } from "allure-js-commons";
import { CommonPage, SummaryPage } from "../pageObjects/index.js";
import { AwesomePluginWithoutSummary, type ReportBootstrap, bootstrapReport } from "../utils/index.js";

let bootstrap: ReportBootstrap;
let summaryPage: SummaryPage;
let commonPage: CommonPage;

test.afterAll(async () => {
await bootstrap?.shutdown?.();
});

test.beforeEach(async ({ page }) => {
commonPage = new CommonPage(page);
summaryPage = new SummaryPage(page);
});

test.describe("summary", () => {
test("should not generate summary for a single report", async ({ page }) => {
bootstrap = await bootstrapReport({
reportConfig: {
name: "Sample allure report",
appendHistory: false,
history: undefined,
historyPath: undefined,
knownIssuesPath: undefined,
plugins: [
{
id: "awesome1",
enabled: true,
plugin: new AwesomePlugin({}),
options: {},
},
],
},
testResults: [
{
name: "0 sample passed test",
fullName: "sample.js#0 sample passed test",
status: Status.PASSED,
stage: Stage.FINISHED,
start: 1000,
},
],
});

await page.goto(bootstrap.url);

await expect(summaryPage.reportCardLocator).not.toBeVisible();
await expect(commonPage.baseLayoutLocator).toBeVisible();
});

test("should not generate summary on the single report re-generation", async ({ page }) => {
bootstrap = await bootstrapReport({
reportConfig: {
name: "Sample allure report",
appendHistory: false,
history: undefined,
historyPath: undefined,
knownIssuesPath: undefined,
plugins: [
{
id: "awesome1",
enabled: true,
plugin: new AwesomePlugin({}),
options: {},
},
],
},
testResults: [
{
name: "0 sample passed test",
fullName: "sample.js#0 sample passed test",
status: Status.PASSED,
stage: Stage.FINISHED,
start: 1000,
},
],
});

await page.goto(bootstrap.url);

await expect(summaryPage.reportCardLocator).not.toBeVisible();
await expect(commonPage.baseLayoutLocator).toBeVisible();

await bootstrap.regenerate();
await page.reload();

await expect(summaryPage.reportCardLocator).not.toBeVisible();
await expect(commonPage.baseLayoutLocator).toBeVisible();
});

test("should render cards for each generated report with summary", async ({ page, context }) => {
bootstrap = await bootstrapReport({
reportConfig: {
Expand Down Expand Up @@ -43,18 +125,17 @@ test.describe("summary", () => {
},
],
});
const summaryCardsLocator = page.getByTestId("summary-report-card");

await page.goto(bootstrap.url);

await expect(summaryCardsLocator).toHaveCount(2);
await expect(summaryPage.reportCardLocator).toHaveCount(2);

const pageUrl = page.url();

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

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

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

await page.goto(bootstrap.url);

await expect(summaryCardsLocator).toHaveCount(2);
await expect(summaryPage.reportCardLocator).toHaveCount(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class CommonPage extends PageObject {

toggleLayoutButtonLocator: Locator;
splitLayoutLocator: Locator;
singleLayoutLocator: Locator;
baseLayoutLocator: Locator;

envPickerLocator: Locator;
envPickerButtonLocator: Locator;
Expand All @@ -18,7 +18,7 @@ export class CommonPage extends PageObject {

this.toggleLayoutButtonLocator = page.getByTestId("toggle-layout-button");
this.splitLayoutLocator = page.getByTestId("split-layout");
this.singleLayoutLocator = page.getByTestId("base-layout");
this.baseLayoutLocator = page.getByTestId("base-layout");

this.envPickerLocator = page.getByTestId("environment-picker");
this.envPickerButtonLocator = page.getByTestId("environment-picker-button");
Expand Down
16 changes: 16 additions & 0 deletions packages/e2e/test/pageObjects/Summary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { type Locator, type Page } from "@playwright/test";
import { PageObject } from "./pageObject.js";

export class SummaryPage extends PageObject {
reportCardLocator: Locator;

constructor(readonly page: Page) {
super(page);

this.reportCardLocator = page.getByTestId("summary-report-card");
}

async clickReportCard(idx: number) {
await this.reportCardLocator.nth(idx).click();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Locator, type Page } from "@playwright/test";
import { randomNumber } from "../../utils/index.js";
import { randomNumber } from "../utils/index.js";
import { PageObject } from "./pageObject.js";

export class TreePage extends PageObject {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./Tree.js";
export * from "./TestResult.js";
export * from "./Common.js";
export * from "./Summary.js";
15 changes: 10 additions & 5 deletions packages/e2e/test/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type GeneratorParams = {
export interface ReportBootstrap {
url: string;
reportDir: string;
regenerate: () => Promise<void>;
shutdown: () => Promise<void>;
}

Expand Down Expand Up @@ -100,18 +101,22 @@ export const bootstrapReport = async (
const temp = tmpdir();
const resultsDir = await mkdtemp(resolve(temp, "allure-results-"));
const reportDir = await mkdtemp(resolve(temp, "allure-report-"));
const reportGenerator = async () => {
await generateReport({
...params,
resultsDir,
reportDir,
});
};

await generateReport({
...params,
resultsDir,
reportDir,
});
await reportGenerator();

const server = await serveReport(reportDir);

return {
...server,
reportDir,
regenerate: reportGenerator,
shutdown: async () => {
await server?.shutdown();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ export const TrAttachment: FunctionComponent<{
</Code>
<Text className={styles["test-result-attachment-text"]}>{link.name || link.originalFileName}</Text>
{missed && (
<Text size={"s"} className={styles["test-result-attachment-missed"]} data-testid={"test-result-attachment-missed"}>
<Text
size={"s"}
className={styles["test-result-attachment-missed"]}
data-testid={"test-result-attachment-missed"}
>
missed
</Text>
)}
Expand Down