From 386f64b944caf013c79ef54c91344e7ccbfac885 Mon Sep 17 00:00:00 2001 From: epszaw Date: Thu, 12 Dec 2024 16:34:35 +0100 Subject: [PATCH 1/4] add more e2e tests --- packages/e2e/test/allure-awesome/base.test.ts | 192 +++++++++--------- .../e2e/test/allure-awesome/search.test.ts | 89 ++++++++ packages/e2e/test/utils/index.ts | 24 +++ .../src/components/app/ReportHeader/index.tsx | 2 +- .../components/commons/SearchBox/index.tsx | 1 + 5 files changed, 211 insertions(+), 97 deletions(-) create mode 100644 packages/e2e/test/allure-awesome/search.test.ts create mode 100644 packages/e2e/test/utils/index.ts diff --git a/packages/e2e/test/allure-awesome/base.test.ts b/packages/e2e/test/allure-awesome/base.test.ts index 94df0e8..3fac457 100644 --- a/packages/e2e/test/allure-awesome/base.test.ts +++ b/packages/e2e/test/allure-awesome/base.test.ts @@ -5,107 +5,25 @@ import { serve } from "@allurereport/static-server"; import { expect, test } from "@playwright/test"; import { layer } from "allure-js-commons"; import { Stage, Status } from "allure-js-commons"; -import { FileSystemWriter, ReporterRuntime } from "allure-js-commons/sdk/reporter"; import { mkdtemp, rm } from "node:fs/promises"; import { tmpdir } from "node:os"; import { resolve } from "node:path"; +import { generateTestResults, randomNumber } from "../utils/index.js"; let server: AllureStaticServer; let host: string; let allureTestResultsDir: string; let allureReportDir: string; -const generateTestResults = () => { - const runtime = new ReporterRuntime({ - writer: new FileSystemWriter({ - resultsDir: allureTestResultsDir, - }), - }); - const scopeUuid = runtime.startScope(); - const now = Date.now(); - - runtime.writeTest( - runtime.startTest( - { - name: "0 sample passed test", - fullName: "sample.js#0 sample passed test", - status: Status.PASSED, - stage: Stage.FINISHED, - start: now, - stop: now + 1000, - }, - [scopeUuid], - ), - ); - runtime.writeTest( - runtime.startTest( - { - name: "1 sample failed test", - fullName: "sample.js#1 sample failed test", - status: Status.FAILED, - stage: Stage.FINISHED, - start: now + 1000, - stop: now + 2000, - statusDetails: { - message: "Assertion error: Expected 1 to be 2", - trace: "trace", - }, - }, - [scopeUuid], - ), - ); - runtime.writeTest( - runtime.startTest( - { - name: "2 sample broken test", - fullName: "sample.js#2 sample broken test", - status: Status.BROKEN, - stage: Stage.FINISHED, - start: now + 2000, - stop: now + 3000, - statusDetails: { - message: "An unexpected error", - trace: "trace", - }, - }, - [scopeUuid], - ), - ); - runtime.writeTest( - runtime.startTest( - { - name: "3 sample skipped test", - fullName: "sample.js#3 sample skipped test", - start: now + 3000, - stop: now + 3000, - status: Status.SKIPPED, - }, - [scopeUuid], - ), - ); - runtime.writeTest( - runtime.startTest( - { - name: "4 sample unknown test", - fullName: "sample.js#4 sample unknown test", - status: undefined, - start: now + 4000, - stage: Stage.PENDING, - }, - [scopeUuid], - ), - ); - runtime.writeScope(scopeUuid); -}; - test.beforeAll(async () => { + const now = Date.now(); const temp = tmpdir(); allureTestResultsDir = await mkdtemp(resolve(temp, "allure-results-")); allureReportDir = await mkdtemp(resolve(temp, "allure-report-")); const report = new AllureReport({ - name: "sample", + name: "sample allure report", output: allureReportDir, reportFiles: new FileSystemReportFiles(allureReportDir), plugins: [ @@ -118,7 +36,54 @@ test.beforeAll(async () => { ], }); - generateTestResults(); + generateTestResults(allureTestResultsDir, [ + { + name: "0 sample passed test", + fullName: "sample.js#0 sample passed test", + status: Status.PASSED, + stage: Stage.FINISHED, + start: now, + stop: now + 1000, + }, + { + name: "1 sample failed test", + fullName: "sample.js#1 sample failed test", + status: Status.FAILED, + stage: Stage.FINISHED, + start: now + 1000, + stop: now + 2000, + statusDetails: { + message: "Assertion error: Expected 1 to be 2", + trace: "failed test trace", + }, + }, + { + name: "2 sample broken test", + fullName: "sample.js#2 sample broken test", + status: Status.BROKEN, + stage: Stage.FINISHED, + start: now + 2000, + stop: now + 3000, + statusDetails: { + message: "An unexpected error", + trace: "broken test trace", + }, + }, + { + name: "3 sample skipped test", + fullName: "sample.js#3 sample skipped test", + start: now + 3000, + stop: now + 3000, + status: Status.SKIPPED, + }, + { + name: "4 sample unknown test", + fullName: "sample.js#4 sample unknown test", + status: undefined, + start: now + 4000, + stage: Stage.PENDING, + }, + ]); await report.start(); await report.readDirectory(allureTestResultsDir); await report.done(); @@ -143,6 +108,11 @@ test.beforeEach(async ({ page }) => { await page.goto(host); }); +test("report title and page title contain give report name", async ({ page }) => { + await expect(page.getByTestId("report-title")).toHaveText("sample allure report"); + expect(await page.title()).toBe("sample allure report"); +}); + test("all types of tests are displayed", async ({ page }) => { const treeLeaves = page.getByTestId("tree-leaf"); @@ -207,18 +177,32 @@ test("test result page opens after test result click", async ({ page }) => { await expect(page.getByTestId("test-result-fullname")).toHaveText("sample.js#0 sample passed test"); }); -test.skip("it's possible to navigate between test results using navigation arrows", async ({ page }) => { - const passedLeaf = page.getByTestId("tree-leaf").nth(0); +test("it's possible to navigate between tests results using navigation arrows", async ({ page }) => { + const randomLeaf = page.getByTestId("tree-leaf").nth(randomNumber(0, 4)); - await passedLeaf.click(); + await randomLeaf.click(); - await expect(page.getByTestId("test-result-nav-current")).toHaveText("1/5"); - await page.getByTestId("test-result-nav-next").click(); - await expect(page.getByTestId("test-result-nav-current")).toHaveText("2/5"); - await expect(page.getByTestId("test-result-info-title")).not.toHaveText("0 sample passed test"); - await page.getByTestId("test-result-prev-next").click(); - await expect(page.getByTestId("test-result-nav-current")).toHaveText("1/5"); - await expect(page.getByTestId("test-result-info-title")).toHaveText("0 sample passed test"); + const testTitleText = await page.getByTestId("test-result-info-title").textContent(); + const navCounterText = await page.getByTestId("test-result-nav-current").textContent(); + const pressPrevArrow = await page.getByTestId("test-result-nav-next").isDisabled(); + + if (pressPrevArrow) { + await page.getByTestId("test-result-nav-prev").click(); + } else { + await page.getByTestId("test-result-nav-next").click(); + } + + await expect(page.getByTestId("test-result-nav-current")).not.toHaveText(navCounterText); + await expect(page.getByTestId("test-result-info-title")).not.toHaveText(testTitleText); + + if (pressPrevArrow) { + await page.getByTestId("test-result-nav-next").click(); + } else { + await page.getByTestId("test-result-nav-prev").click(); + } + + await expect(page.getByTestId("test-result-nav-current")).toHaveText(navCounterText); + await expect(page.getByTestId("test-result-info-title")).toHaveText(testTitleText); }); test("test result fullname copies to clipboard", async ({ page, context }) => { @@ -233,3 +217,19 @@ test("test result fullname copies to clipboard", async ({ page, context }) => { expect(clipboardContent).toEqual("sample.js#0 sample passed test"); }); + +test("failed test contains error message and stack", async ({ page }) => { + await page.getByTestId("tree-leaf-status-failed").click(); + await expect(page.getByTestId("test-result-error-message")).toHaveText("Assertion error: Expected 1 to be 2"); + await expect(page.getByTestId("test-result-error-trace")).not.toBeVisible(); + await page.getByTestId("test-result-error-message").click(); + await expect(page.getByTestId("test-result-error-trace")).toHaveText("failed test trace"); +}); + +test("broken test contains error message and stack", async ({ page }) => { + await page.getByTestId("tree-leaf-status-broken").click(); + await expect(page.getByTestId("test-result-error-message")).toHaveText("An unexpected error"); + await expect(page.getByTestId("test-result-error-trace")).not.toBeVisible(); + await page.getByTestId("test-result-error-message").click(); + await expect(page.getByTestId("test-result-error-trace")).toHaveText("broken test trace"); +}); diff --git a/packages/e2e/test/allure-awesome/search.test.ts b/packages/e2e/test/allure-awesome/search.test.ts new file mode 100644 index 0000000..39a50d5 --- /dev/null +++ b/packages/e2e/test/allure-awesome/search.test.ts @@ -0,0 +1,89 @@ +import { AllureReport, FileSystemReportFiles } from "@allure/core"; +import AllureAwesomePlugin from "@allure/plugin-awesome"; +import type { AllureStaticServer } from "@allure/static-server"; +import { serve } from "@allure/static-server"; +import { expect, test } from "@playwright/test"; +import { layer } from "allure-js-commons"; +import { Stage, Status } from "allure-js-commons"; +import { mkdtemp, rm } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { resolve } from "node:path"; +import { generateTestResults } from "../utils/index.js"; + +let server: AllureStaticServer; +let host: string; +let allureTestResultsDir: string; +let allureReportDir: string; + +test.beforeAll(async () => { + const now = Date.now(); + const temp = tmpdir(); + + allureTestResultsDir = await mkdtemp(resolve(temp, "allure-results-")); + allureReportDir = await mkdtemp(resolve(temp, "allure-report-")); + + const report = new AllureReport({ + name: "sample", + output: allureReportDir, + reportFiles: new FileSystemReportFiles(allureReportDir), + plugins: [ + { + id: "awesome", + enabled: true, + plugin: new AllureAwesomePlugin({}), + options: {}, + }, + ], + }); + + generateTestResults(allureTestResultsDir, [ + { + name: "0 sample test", + fullName: "sample.js#0 sample passed test", + status: Status.PASSED, + stage: Stage.FINISHED, + start: now, + stop: now + 1000, + }, + { + name: "1 flaky test", + fullName: "sample.js#1 sample failed test", + status: Status.FAILED, + stage: Stage.FINISHED, + start: now + 1000, + stop: now + 2000, + statusDetails: { + message: "Assertion error: Expected 1 to be 2", + trace: "failed test trace", + }, + }, + ]); + await report.start(); + await report.readDirectory(allureTestResultsDir); + await report.done(); + + server = await serve({ + servePath: resolve(allureReportDir, "./awesome"), + }); + host = `http://localhost:${server.port}`; +}); + +test.afterAll(async () => { + try { + await rm(allureTestResultsDir, { recursive: true }); + await rm(allureReportDir, { recursive: true }); + } catch (ignored) {} + + await server?.stop(); +}); + +test.beforeEach(async ({ page }) => { + await layer("e2e"); + await page.goto(host); +}); + +test("search filters tests on typing", async ({ page }) => { + await expect(page.getByTestId("tree-leaf")).toHaveCount(2); + await page.getByTestId("search-input").fill("0 sample"); + await expect(page.getByTestId("tree-leaf")).toHaveCount(1); +}); diff --git a/packages/e2e/test/utils/index.ts b/packages/e2e/test/utils/index.ts new file mode 100644 index 0000000..9ea8d8d --- /dev/null +++ b/packages/e2e/test/utils/index.ts @@ -0,0 +1,24 @@ +import { type TestResult } from "allure-js-commons"; +import { FileSystemWriter, ReporterRuntime } from "allure-js-commons/sdk/reporter"; + +export const randomNumber = (min: number, max: number) => { + if (min > max) { + [min, max] = [max, min]; + } + + return Math.random() * (max - min) + min; +}; + +export const generateTestResults = (resultsDir: string, trs: Partial[]) => { + const runtime = new ReporterRuntime({ + writer: new FileSystemWriter({ + resultsDir, + }), + }); + const scopeUuid = runtime.startScope(); + + trs.forEach((tr) => { + runtime.writeTest(runtime.startTest(tr, [scopeUuid])); + }); + runtime.writeScope(scopeUuid); +}; diff --git a/packages/web-awesome/src/components/app/ReportHeader/index.tsx b/packages/web-awesome/src/components/app/ReportHeader/index.tsx index 1b7c2c1..fb0b4d9 100644 --- a/packages/web-awesome/src/components/app/ReportHeader/index.tsx +++ b/packages/web-awesome/src/components/app/ReportHeader/index.tsx @@ -19,7 +19,7 @@ export const ReportHeader = () => {
- + {reportName} diff --git a/packages/web-awesome/src/components/commons/SearchBox/index.tsx b/packages/web-awesome/src/components/commons/SearchBox/index.tsx index 6d40a49..98a49b3 100644 --- a/packages/web-awesome/src/components/commons/SearchBox/index.tsx +++ b/packages/web-awesome/src/components/commons/SearchBox/index.tsx @@ -50,6 +50,7 @@ export const SearchBox = (props: Props) => { value={localValue} name="search" autocomplete="off" + data-testid="search-input" /> {showClear && (
From 66fc80324b0916a3311b916c950bff7992e00938 Mon Sep 17 00:00:00 2001 From: epszaw Date: Fri, 13 Dec 2024 11:35:31 +0100 Subject: [PATCH 2/4] working on tests --- packages/e2e/test/allure-awesome/base.test.ts | 235 ------------------ .../test/allure-awesome/reportOptions.test.ts | 70 ++++++ .../e2e/test/allure-awesome/search.test.ts | 89 ------- .../test/allure-awesome/testResult.test.ts | 159 ++++++++++++ packages/e2e/test/allure-awesome/tree.test.ts | 172 +++++++++++++ packages/e2e/test/utils/index.ts | 30 ++- 6 files changed, 429 insertions(+), 326 deletions(-) delete mode 100644 packages/e2e/test/allure-awesome/base.test.ts create mode 100644 packages/e2e/test/allure-awesome/reportOptions.test.ts delete mode 100644 packages/e2e/test/allure-awesome/search.test.ts create mode 100644 packages/e2e/test/allure-awesome/testResult.test.ts create mode 100644 packages/e2e/test/allure-awesome/tree.test.ts diff --git a/packages/e2e/test/allure-awesome/base.test.ts b/packages/e2e/test/allure-awesome/base.test.ts deleted file mode 100644 index 3fac457..0000000 --- a/packages/e2e/test/allure-awesome/base.test.ts +++ /dev/null @@ -1,235 +0,0 @@ -import { AllureReport, FileSystemReportFiles } from "@allurereport/core"; -import AllureAwesomePlugin from "@allurereport/plugin-awesome"; -import type { AllureStaticServer } from "@allurereport/static-server"; -import { serve } from "@allurereport/static-server"; -import { expect, test } from "@playwright/test"; -import { layer } from "allure-js-commons"; -import { Stage, Status } from "allure-js-commons"; -import { mkdtemp, rm } from "node:fs/promises"; -import { tmpdir } from "node:os"; -import { resolve } from "node:path"; -import { generateTestResults, randomNumber } from "../utils/index.js"; - -let server: AllureStaticServer; -let host: string; -let allureTestResultsDir: string; -let allureReportDir: string; - -test.beforeAll(async () => { - const now = Date.now(); - const temp = tmpdir(); - - allureTestResultsDir = await mkdtemp(resolve(temp, "allure-results-")); - allureReportDir = await mkdtemp(resolve(temp, "allure-report-")); - - const report = new AllureReport({ - name: "sample allure report", - output: allureReportDir, - reportFiles: new FileSystemReportFiles(allureReportDir), - plugins: [ - { - id: "awesome", - enabled: true, - plugin: new AllureAwesomePlugin({}), - options: {}, - }, - ], - }); - - generateTestResults(allureTestResultsDir, [ - { - name: "0 sample passed test", - fullName: "sample.js#0 sample passed test", - status: Status.PASSED, - stage: Stage.FINISHED, - start: now, - stop: now + 1000, - }, - { - name: "1 sample failed test", - fullName: "sample.js#1 sample failed test", - status: Status.FAILED, - stage: Stage.FINISHED, - start: now + 1000, - stop: now + 2000, - statusDetails: { - message: "Assertion error: Expected 1 to be 2", - trace: "failed test trace", - }, - }, - { - name: "2 sample broken test", - fullName: "sample.js#2 sample broken test", - status: Status.BROKEN, - stage: Stage.FINISHED, - start: now + 2000, - stop: now + 3000, - statusDetails: { - message: "An unexpected error", - trace: "broken test trace", - }, - }, - { - name: "3 sample skipped test", - fullName: "sample.js#3 sample skipped test", - start: now + 3000, - stop: now + 3000, - status: Status.SKIPPED, - }, - { - name: "4 sample unknown test", - fullName: "sample.js#4 sample unknown test", - status: undefined, - start: now + 4000, - stage: Stage.PENDING, - }, - ]); - await report.start(); - await report.readDirectory(allureTestResultsDir); - await report.done(); - - server = await serve({ - servePath: resolve(allureReportDir, "./awesome"), - }); - host = `http://localhost:${server.port}`; -}); - -test.afterAll(async () => { - try { - await rm(allureTestResultsDir, { recursive: true }); - await rm(allureReportDir, { recursive: true }); - } catch (ignored) {} - - await server?.stop(); -}); - -test.beforeEach(async ({ page }) => { - await layer("e2e"); - await page.goto(host); -}); - -test("report title and page title contain give report name", async ({ page }) => { - await expect(page.getByTestId("report-title")).toHaveText("sample allure report"); - expect(await page.title()).toBe("sample allure report"); -}); - -test("all types of tests are displayed", async ({ page }) => { - const treeLeaves = page.getByTestId("tree-leaf"); - - await expect(treeLeaves).toHaveCount(5); - await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("0 sample passed test"); - await expect(treeLeaves.nth(0).getByTestId("tree-leaf-status-passed")).toBeVisible(); - await expect(treeLeaves.nth(1).getByTestId("tree-leaf-title")).toHaveText("1 sample failed test"); - await expect(treeLeaves.nth(1).getByTestId("tree-leaf-status-failed")).toBeVisible(); - await expect(treeLeaves.nth(2).getByTestId("tree-leaf-title")).toHaveText("2 sample broken test"); - await expect(treeLeaves.nth(2).getByTestId("tree-leaf-status-broken")).toBeVisible(); - await expect(treeLeaves.nth(3).getByTestId("tree-leaf-title")).toHaveText("3 sample skipped test"); - await expect(treeLeaves.nth(3).getByTestId("tree-leaf-status-skipped")).toBeVisible(); - await expect(treeLeaves.nth(4).getByTestId("tree-leaf-title")).toHaveText("4 sample unknown test"); - await expect(treeLeaves.nth(4).getByTestId("tree-leaf-status-unknown")).toBeVisible(); -}); - -test("statistics in metadata renders information about the tests", async ({ page }) => { - await expect(page.getByTestId("metadata-item-total").getByTestId("metadata-value")).toHaveText("5"); - await expect(page.getByTestId("metadata-item-passed").getByTestId("metadata-value")).toHaveText("1"); - await expect(page.getByTestId("metadata-item-failed").getByTestId("metadata-value")).toHaveText("1"); - await expect(page.getByTestId("metadata-item-broken").getByTestId("metadata-value")).toHaveText("1"); - await expect(page.getByTestId("metadata-item-skipped").getByTestId("metadata-value")).toHaveText("1"); - await expect(page.getByTestId("metadata-item-unknown").getByTestId("metadata-value")).toHaveText("1"); -}); - -test("tree tabs filter tests by the status", async ({ page }) => { - const treeLeaves = page.getByTestId("tree-leaf"); - - await expect(treeLeaves).toHaveCount(5); - - await page.getByTestId("tab-passed").click(); - await expect(treeLeaves).toHaveCount(1); - await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("0 sample passed test"); - - await page.getByTestId("tab-failed").click(); - await expect(treeLeaves).toHaveCount(1); - await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("1 sample failed test"); - - await page.getByTestId("tab-broken").click(); - await expect(treeLeaves).toHaveCount(1); - await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("2 sample broken test"); - - await page.getByTestId("tab-skipped").click(); - await expect(treeLeaves).toHaveCount(1); - await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("3 sample skipped test"); - - await page.getByTestId("tab-unknown").click(); - await expect(treeLeaves).toHaveCount(1); - await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("4 sample unknown test"); - - await page.getByTestId("tab-all").click(); - await expect(treeLeaves).toHaveCount(5); -}); - -test("test result page opens after test result click", async ({ page }) => { - const passedLeaf = page.getByTestId("tree-leaf").nth(0); - - await passedLeaf.click(); - - await expect(page.getByTestId("test-result-info-title")).toHaveText("0 sample passed test"); - await expect(page.getByTestId("tree-leaf-status-passed")).toBeVisible(); - await expect(page.getByTestId("test-result-fullname")).toHaveText("sample.js#0 sample passed test"); -}); - -test("it's possible to navigate between tests results using navigation arrows", async ({ page }) => { - const randomLeaf = page.getByTestId("tree-leaf").nth(randomNumber(0, 4)); - - await randomLeaf.click(); - - const testTitleText = await page.getByTestId("test-result-info-title").textContent(); - const navCounterText = await page.getByTestId("test-result-nav-current").textContent(); - const pressPrevArrow = await page.getByTestId("test-result-nav-next").isDisabled(); - - if (pressPrevArrow) { - await page.getByTestId("test-result-nav-prev").click(); - } else { - await page.getByTestId("test-result-nav-next").click(); - } - - await expect(page.getByTestId("test-result-nav-current")).not.toHaveText(navCounterText); - await expect(page.getByTestId("test-result-info-title")).not.toHaveText(testTitleText); - - if (pressPrevArrow) { - await page.getByTestId("test-result-nav-next").click(); - } else { - await page.getByTestId("test-result-nav-prev").click(); - } - - await expect(page.getByTestId("test-result-nav-current")).toHaveText(navCounterText); - await expect(page.getByTestId("test-result-info-title")).toHaveText(testTitleText); -}); - -test("test result fullname copies to clipboard", async ({ page, context }) => { - const passedLeaf = page.getByTestId("tree-leaf").nth(0); - - await passedLeaf.click(); - await context.grantPermissions(["clipboard-read", "clipboard-write"]); - await page.getByTestId("test-result-fullname-copy").click(); - - const handle = await page.evaluateHandle(() => globalThis.navigator.clipboard.readText()); - const clipboardContent = await handle.jsonValue(); - - expect(clipboardContent).toEqual("sample.js#0 sample passed test"); -}); - -test("failed test contains error message and stack", async ({ page }) => { - await page.getByTestId("tree-leaf-status-failed").click(); - await expect(page.getByTestId("test-result-error-message")).toHaveText("Assertion error: Expected 1 to be 2"); - await expect(page.getByTestId("test-result-error-trace")).not.toBeVisible(); - await page.getByTestId("test-result-error-message").click(); - await expect(page.getByTestId("test-result-error-trace")).toHaveText("failed test trace"); -}); - -test("broken test contains error message and stack", async ({ page }) => { - await page.getByTestId("tree-leaf-status-broken").click(); - await expect(page.getByTestId("test-result-error-message")).toHaveText("An unexpected error"); - await expect(page.getByTestId("test-result-error-trace")).not.toBeVisible(); - await page.getByTestId("test-result-error-message").click(); - await expect(page.getByTestId("test-result-error-trace")).toHaveText("broken test trace"); -}); diff --git a/packages/e2e/test/allure-awesome/reportOptions.test.ts b/packages/e2e/test/allure-awesome/reportOptions.test.ts new file mode 100644 index 0000000..c642f71 --- /dev/null +++ b/packages/e2e/test/allure-awesome/reportOptions.test.ts @@ -0,0 +1,70 @@ +import type { AllureStaticServer } from "@allure/static-server"; +import { serve } from "@allure/static-server"; +import { expect, test } from "@playwright/test"; +import { layer } from "allure-js-commons"; +import { Stage, Status } from "allure-js-commons"; +import { mkdtemp, rm } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { resolve } from "node:path"; +import { generateTestResults } from "../utils/index.js"; + +let server: AllureStaticServer; +let host: string; +let allureTestResultsDir: string; +let allureReportDir: string; + +test.beforeAll(async () => { + const now = Date.now(); + const temp = tmpdir(); + + allureTestResultsDir = await mkdtemp(resolve(temp, "allure-results-")); + allureReportDir = await mkdtemp(resolve(temp, "allure-report-")); + + await generateTestResults({ + reportConfig: { + name: "Sample allure report" + }, + resultsDir: allureTestResultsDir, + reportDir: allureReportDir, + testResults: [ + { + name: "0 sample passed test", + fullName: "sample.js#0 sample passed test", + status: Status.PASSED, + stage: Stage.FINISHED, + start: now, + stop: now + 1000, + }, + ] + }); + + server = await serve({ + servePath: resolve(allureReportDir, "./awesome"), + }); + host = `http://localhost:${server.port}`; +}); + +test.afterAll(async () => { + try { + await rm(allureTestResultsDir, { recursive: true }); + await rm(allureReportDir, { recursive: true }); + } catch (ignored) {} + + await server?.stop(); +}); + +test.beforeEach(async ({ page }) => { + await layer("e2e"); + await page.goto(host); +}); + +test.describe("allure-awesome", () => { + test.describe("report options", () => { + test("report title and page title contain give report name", async ({ page }) => { + await expect(page.getByTestId("report-title")).toHaveText("Sample allure report"); + expect(await page.title()).toBe("Sample allure report"); + }); + }) +}) + + diff --git a/packages/e2e/test/allure-awesome/search.test.ts b/packages/e2e/test/allure-awesome/search.test.ts deleted file mode 100644 index 39a50d5..0000000 --- a/packages/e2e/test/allure-awesome/search.test.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { AllureReport, FileSystemReportFiles } from "@allure/core"; -import AllureAwesomePlugin from "@allure/plugin-awesome"; -import type { AllureStaticServer } from "@allure/static-server"; -import { serve } from "@allure/static-server"; -import { expect, test } from "@playwright/test"; -import { layer } from "allure-js-commons"; -import { Stage, Status } from "allure-js-commons"; -import { mkdtemp, rm } from "node:fs/promises"; -import { tmpdir } from "node:os"; -import { resolve } from "node:path"; -import { generateTestResults } from "../utils/index.js"; - -let server: AllureStaticServer; -let host: string; -let allureTestResultsDir: string; -let allureReportDir: string; - -test.beforeAll(async () => { - const now = Date.now(); - const temp = tmpdir(); - - allureTestResultsDir = await mkdtemp(resolve(temp, "allure-results-")); - allureReportDir = await mkdtemp(resolve(temp, "allure-report-")); - - const report = new AllureReport({ - name: "sample", - output: allureReportDir, - reportFiles: new FileSystemReportFiles(allureReportDir), - plugins: [ - { - id: "awesome", - enabled: true, - plugin: new AllureAwesomePlugin({}), - options: {}, - }, - ], - }); - - generateTestResults(allureTestResultsDir, [ - { - name: "0 sample test", - fullName: "sample.js#0 sample passed test", - status: Status.PASSED, - stage: Stage.FINISHED, - start: now, - stop: now + 1000, - }, - { - name: "1 flaky test", - fullName: "sample.js#1 sample failed test", - status: Status.FAILED, - stage: Stage.FINISHED, - start: now + 1000, - stop: now + 2000, - statusDetails: { - message: "Assertion error: Expected 1 to be 2", - trace: "failed test trace", - }, - }, - ]); - await report.start(); - await report.readDirectory(allureTestResultsDir); - await report.done(); - - server = await serve({ - servePath: resolve(allureReportDir, "./awesome"), - }); - host = `http://localhost:${server.port}`; -}); - -test.afterAll(async () => { - try { - await rm(allureTestResultsDir, { recursive: true }); - await rm(allureReportDir, { recursive: true }); - } catch (ignored) {} - - await server?.stop(); -}); - -test.beforeEach(async ({ page }) => { - await layer("e2e"); - await page.goto(host); -}); - -test("search filters tests on typing", async ({ page }) => { - await expect(page.getByTestId("tree-leaf")).toHaveCount(2); - await page.getByTestId("search-input").fill("0 sample"); - await expect(page.getByTestId("tree-leaf")).toHaveCount(1); -}); diff --git a/packages/e2e/test/allure-awesome/testResult.test.ts b/packages/e2e/test/allure-awesome/testResult.test.ts new file mode 100644 index 0000000..5be2732 --- /dev/null +++ b/packages/e2e/test/allure-awesome/testResult.test.ts @@ -0,0 +1,159 @@ +import type { AllureStaticServer } from "@allure/static-server"; +import { serve } from "@allure/static-server"; +import { expect, test } from "@playwright/test"; +import { layer } from "allure-js-commons"; +import { Stage, Status } from "allure-js-commons"; +import { mkdtemp, rm } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { resolve } from "node:path"; +import { generateTestResults, randomNumber } from "../utils/index.js"; + +let server: AllureStaticServer; +let host: string; +let allureTestResultsDir: string; +let allureReportDir: string; + +test.beforeAll(async () => { + const now = Date.now(); + const temp = tmpdir(); + + allureTestResultsDir = await mkdtemp(resolve(temp, "allure-results-")); + allureReportDir = await mkdtemp(resolve(temp, "allure-report-")); + + await generateTestResults({ + reportConfig: { + name: "Sample allure report" + }, + resultsDir: allureTestResultsDir, + reportDir: allureReportDir, + testResults: [ + { + name: "0 sample passed test", + fullName: "sample.js#0 sample passed test", + status: Status.PASSED, + stage: Stage.FINISHED, + start: now, + stop: now + 1000, + }, + { + name: "1 sample failed test", + fullName: "sample.js#1 sample failed test", + status: Status.FAILED, + stage: Stage.FINISHED, + start: now + 1000, + stop: now + 2000, + statusDetails: { + message: "Assertion error: Expected 1 to be 2", + trace: "failed test trace", + }, + }, + { + name: "2 sample broken test", + fullName: "sample.js#2 sample broken test", + status: Status.BROKEN, + stage: Stage.FINISHED, + start: now + 2000, + stop: now + 3000, + statusDetails: { + message: "An unexpected error", + trace: "broken test trace", + }, + }, + { + name: "3 sample skipped test", + fullName: "sample.js#3 sample skipped test", + start: now + 3000, + stop: now + 3000, + status: Status.SKIPPED, + }, + { + name: "4 sample unknown test", + fullName: "sample.js#4 sample unknown test", + status: undefined, + start: now + 4000, + stage: Stage.PENDING, + }, + ] + }); + + server = await serve({ + servePath: resolve(allureReportDir, "./awesome"), + }); + host = `http://localhost:${server.port}`; +}); + +test.afterAll(async () => { + try { + await rm(allureTestResultsDir, { recursive: true }); + await rm(allureReportDir, { recursive: true }); + } catch (ignored) {} + + await server?.stop(); +}); + +test.beforeEach(async ({ page }) => { + await layer("e2e"); + await page.goto(host); +}); + +test.describe("allure-awesome", () => { + test.describe("test results", () => { + test("it's possible to navigate between tests results using navigation arrows", async ({ page }) => { + const randomLeaf = page.getByTestId("tree-leaf").nth(randomNumber(0, 4)); + + await randomLeaf.click(); + + const testTitleText = await page.getByTestId("test-result-info-title").textContent(); + const navCounterText = await page.getByTestId("test-result-nav-current").textContent(); + const pressPrevArrow = await page.getByTestId("test-result-nav-next").isDisabled(); + + if (pressPrevArrow) { + await page.getByTestId("test-result-nav-prev").click(); + } else { + await page.getByTestId("test-result-nav-next").click(); + } + + await expect(page.getByTestId("test-result-nav-current")).not.toHaveText(navCounterText); + await expect(page.getByTestId("test-result-info-title")).not.toHaveText(testTitleText); + + if (pressPrevArrow) { + await page.getByTestId("test-result-nav-next").click(); + } else { + await page.getByTestId("test-result-nav-prev").click(); + } + + await expect(page.getByTestId("test-result-nav-current")).toHaveText(navCounterText); + await expect(page.getByTestId("test-result-info-title")).toHaveText(testTitleText); + }); + + test("test result fullname copies to clipboard", async ({ page, context }) => { + const passedLeaf = page.getByTestId("tree-leaf").nth(0); + + await passedLeaf.click(); + await context.grantPermissions(["clipboard-read", "clipboard-write"]); + await page.getByTestId("test-result-fullname-copy").click(); + + const handle = await page.evaluateHandle(() => globalThis.navigator.clipboard.readText()); + const clipboardContent = await handle.jsonValue(); + + expect(clipboardContent).toEqual("sample.js#0 sample passed test"); + }); + + test("failed test contains error message and stack", async ({ page }) => { + await page.getByTestId("tree-leaf-status-failed").click(); + await expect(page.getByTestId("test-result-error-message")).toHaveText("Assertion error: Expected 1 to be 2"); + await expect(page.getByTestId("test-result-error-trace")).not.toBeVisible(); + await page.getByTestId("test-result-error-message").click(); + await expect(page.getByTestId("test-result-error-trace")).toHaveText("failed test trace"); + }); + + test("broken test contains error message and stack", async ({ page }) => { + await page.getByTestId("tree-leaf-status-broken").click(); + await expect(page.getByTestId("test-result-error-message")).toHaveText("An unexpected error"); + await expect(page.getByTestId("test-result-error-trace")).not.toBeVisible(); + await page.getByTestId("test-result-error-message").click(); + await expect(page.getByTestId("test-result-error-trace")).toHaveText("broken test trace"); + }); + }) +}) + diff --git a/packages/e2e/test/allure-awesome/tree.test.ts b/packages/e2e/test/allure-awesome/tree.test.ts new file mode 100644 index 0000000..de63ece --- /dev/null +++ b/packages/e2e/test/allure-awesome/tree.test.ts @@ -0,0 +1,172 @@ +import type { AllureStaticServer } from "@allure/static-server"; +import { serve } from "@allure/static-server"; +import { expect, test } from "@playwright/test"; +import { layer } from "allure-js-commons"; +import { Stage, Status } from "allure-js-commons"; +import { mkdtemp, rm } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { resolve } from "node:path"; +import { generateTestResults } from "../utils/index.js"; + +let server: AllureStaticServer; +let host: string; +let allureTestResultsDir: string; +let allureReportDir: string; + +test.beforeAll(async () => { + const now = Date.now(); + const temp = tmpdir(); + + allureTestResultsDir = await mkdtemp(resolve(temp, "allure-results-")); + allureReportDir = await mkdtemp(resolve(temp, "allure-report-")); + + await generateTestResults({ + reportConfig: { + name: "Sample allure report" + }, + resultsDir: allureTestResultsDir, + reportDir: allureReportDir, + testResults: [ + { + name: "0 sample passed test", + fullName: "sample.js#0 sample passed test", + status: Status.PASSED, + stage: Stage.FINISHED, + start: now, + stop: now + 1000, + }, + { + name: "1 sample failed test", + fullName: "sample.js#1 sample failed test", + status: Status.FAILED, + stage: Stage.FINISHED, + start: now + 1000, + stop: now + 2000, + statusDetails: { + message: "Assertion error: Expected 1 to be 2", + trace: "failed test trace", + }, + }, + { + name: "2 sample broken test", + fullName: "sample.js#2 sample broken test", + status: Status.BROKEN, + stage: Stage.FINISHED, + start: now + 2000, + stop: now + 3000, + statusDetails: { + message: "An unexpected error", + trace: "broken test trace", + }, + }, + { + name: "3 sample skipped test", + fullName: "sample.js#3 sample skipped test", + start: now + 3000, + stop: now + 3000, + status: Status.SKIPPED, + }, + { + name: "4 sample unknown test", + fullName: "sample.js#4 sample unknown test", + status: undefined, + start: now + 4000, + stage: Stage.PENDING, + }, + ] + }); + + server = await serve({ + servePath: resolve(allureReportDir, "./awesome"), + }); + host = `http://localhost:${server.port}`; +}); + +test.afterAll(async () => { + try { + await rm(allureTestResultsDir, { recursive: true }); + await rm(allureReportDir, { recursive: true }); + } catch (ignored) {} + + await server?.stop(); +}); + +test.beforeEach(async ({ page }) => { + await layer("e2e"); + await page.goto(host); +}); + +test.describe("allure-awesome", () => { + test.describe("tree", () => { + test("all types of tests are displayed", async ({ page }) => { + const treeLeaves = page.getByTestId("tree-leaf"); + + await expect(treeLeaves).toHaveCount(5); + await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("0 sample passed test"); + await expect(treeLeaves.nth(0).getByTestId("tree-leaf-status-passed")).toBeVisible(); + await expect(treeLeaves.nth(1).getByTestId("tree-leaf-title")).toHaveText("1 sample failed test"); + await expect(treeLeaves.nth(1).getByTestId("tree-leaf-status-failed")).toBeVisible(); + await expect(treeLeaves.nth(2).getByTestId("tree-leaf-title")).toHaveText("2 sample broken test"); + await expect(treeLeaves.nth(2).getByTestId("tree-leaf-status-broken")).toBeVisible(); + await expect(treeLeaves.nth(3).getByTestId("tree-leaf-title")).toHaveText("3 sample skipped test"); + await expect(treeLeaves.nth(3).getByTestId("tree-leaf-status-skipped")).toBeVisible(); + await expect(treeLeaves.nth(4).getByTestId("tree-leaf-title")).toHaveText("4 sample unknown test"); + await expect(treeLeaves.nth(4).getByTestId("tree-leaf-status-unknown")).toBeVisible(); + }); + + test("statistics in metadata renders information about the tests", async ({ page }) => { + await expect(page.getByTestId("metadata-item-total").getByTestId("metadata-value")).toHaveText("5"); + await expect(page.getByTestId("metadata-item-passed").getByTestId("metadata-value")).toHaveText("1"); + await expect(page.getByTestId("metadata-item-failed").getByTestId("metadata-value")).toHaveText("1"); + await expect(page.getByTestId("metadata-item-broken").getByTestId("metadata-value")).toHaveText("1"); + await expect(page.getByTestId("metadata-item-skipped").getByTestId("metadata-value")).toHaveText("1"); + await expect(page.getByTestId("metadata-item-unknown").getByTestId("metadata-value")).toHaveText("1"); + }); + + test("tree tabs filter tests by the status", async ({ page }) => { + const treeLeaves = page.getByTestId("tree-leaf"); + + await expect(treeLeaves).toHaveCount(5); + + await page.getByTestId("tab-passed").click(); + await expect(treeLeaves).toHaveCount(1); + await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("0 sample passed test"); + + await page.getByTestId("tab-failed").click(); + await expect(treeLeaves).toHaveCount(1); + await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("1 sample failed test"); + + await page.getByTestId("tab-broken").click(); + await expect(treeLeaves).toHaveCount(1); + await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("2 sample broken test"); + + await page.getByTestId("tab-skipped").click(); + await expect(treeLeaves).toHaveCount(1); + await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("3 sample skipped test"); + + await page.getByTestId("tab-unknown").click(); + await expect(treeLeaves).toHaveCount(1); + await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("4 sample unknown test"); + + await page.getByTestId("tab-all").click(); + await expect(treeLeaves).toHaveCount(5); + }); + + test("test result page opens after test result click", async ({ page }) => { + const passedLeaf = page.getByTestId("tree-leaf").nth(0); + + await passedLeaf.click(); + + await expect(page.getByTestId("test-result-info-title")).toHaveText("0 sample passed test"); + await expect(page.getByTestId("tree-leaf-status-passed")).toBeVisible(); + await expect(page.getByTestId("test-result-fullname")).toHaveText("sample.js#0 sample passed test"); + }); + + test("search filters tests on typing", async ({ page }) => { + await expect(page.getByTestId("tree-leaf")).toHaveCount(5); + await page.getByTestId("search-input").fill("0 sample"); + await expect(page.getByTestId("tree-leaf")).toHaveCount(1); + }); + }) +}) + diff --git a/packages/e2e/test/utils/index.ts b/packages/e2e/test/utils/index.ts index 9ea8d8d..eac75ea 100644 --- a/packages/e2e/test/utils/index.ts +++ b/packages/e2e/test/utils/index.ts @@ -1,5 +1,8 @@ +import { AllureReport, FileSystemReportFiles, type FullConfig } from "@allure/core"; +import AllureAwesomePlugin from "@allure/plugin-awesome"; import { type TestResult } from "allure-js-commons"; import { FileSystemWriter, ReporterRuntime } from "allure-js-commons/sdk/reporter"; +import { readdirSync } from "node:fs" export const randomNumber = (min: number, max: number) => { if (min > max) { @@ -9,7 +12,26 @@ export const randomNumber = (min: number, max: number) => { return Math.random() * (max - min) + min; }; -export const generateTestResults = (resultsDir: string, trs: Partial[]) => { +export const generateTestResults = async (payload: { + reportDir: string; + resultsDir: string; + testResults: Partial[]; + reportConfig: Omit; +}) => { + const { reportConfig, reportDir, resultsDir, testResults } = payload; + const report = new AllureReport({ + plugins: [ + { + id: "awesome", + enabled: true, + plugin: new AllureAwesomePlugin({}), + options: {}, + }, + ], + ...reportConfig, + output: reportDir, + reportFiles: new FileSystemReportFiles(reportDir), + }); const runtime = new ReporterRuntime({ writer: new FileSystemWriter({ resultsDir, @@ -17,8 +39,12 @@ export const generateTestResults = (resultsDir: string, trs: Partial }); const scopeUuid = runtime.startScope(); - trs.forEach((tr) => { + testResults.forEach((tr) => { runtime.writeTest(runtime.startTest(tr, [scopeUuid])); }); runtime.writeScope(scopeUuid); + + await report.start(); + await report.readDirectory(resultsDir); + await report.done(); }; From 623d585e2556c4dc2984702a106592521de82ad2 Mon Sep 17 00:00:00 2001 From: epszaw Date: Fri, 13 Dec 2024 11:53:54 +0100 Subject: [PATCH 3/4] fix after rebase --- packages/e2e/test/allure-awesome/reportOptions.test.ts | 4 ++-- packages/e2e/test/allure-awesome/testResult.test.ts | 4 ++-- packages/e2e/test/allure-awesome/tree.test.ts | 4 ++-- packages/e2e/test/utils/index.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/e2e/test/allure-awesome/reportOptions.test.ts b/packages/e2e/test/allure-awesome/reportOptions.test.ts index c642f71..69ac899 100644 --- a/packages/e2e/test/allure-awesome/reportOptions.test.ts +++ b/packages/e2e/test/allure-awesome/reportOptions.test.ts @@ -1,5 +1,5 @@ -import type { AllureStaticServer } from "@allure/static-server"; -import { serve } from "@allure/static-server"; +import type { AllureStaticServer } from "@allurereport/static-server"; +import { serve } from "@allurereport/static-server"; import { expect, test } from "@playwright/test"; import { layer } from "allure-js-commons"; import { Stage, Status } from "allure-js-commons"; diff --git a/packages/e2e/test/allure-awesome/testResult.test.ts b/packages/e2e/test/allure-awesome/testResult.test.ts index 5be2732..49d8949 100644 --- a/packages/e2e/test/allure-awesome/testResult.test.ts +++ b/packages/e2e/test/allure-awesome/testResult.test.ts @@ -1,5 +1,5 @@ -import type { AllureStaticServer } from "@allure/static-server"; -import { serve } from "@allure/static-server"; +import type { AllureStaticServer } from "@allurereport/static-server"; +import { serve } from "@allurereport/static-server"; import { expect, test } from "@playwright/test"; import { layer } from "allure-js-commons"; import { Stage, Status } from "allure-js-commons"; diff --git a/packages/e2e/test/allure-awesome/tree.test.ts b/packages/e2e/test/allure-awesome/tree.test.ts index de63ece..74a4572 100644 --- a/packages/e2e/test/allure-awesome/tree.test.ts +++ b/packages/e2e/test/allure-awesome/tree.test.ts @@ -1,5 +1,5 @@ -import type { AllureStaticServer } from "@allure/static-server"; -import { serve } from "@allure/static-server"; +import type { AllureStaticServer } from "@allurereport/static-server"; +import { serve } from "@allurereport/static-server"; import { expect, test } from "@playwright/test"; import { layer } from "allure-js-commons"; import { Stage, Status } from "allure-js-commons"; diff --git a/packages/e2e/test/utils/index.ts b/packages/e2e/test/utils/index.ts index eac75ea..7994436 100644 --- a/packages/e2e/test/utils/index.ts +++ b/packages/e2e/test/utils/index.ts @@ -1,5 +1,5 @@ -import { AllureReport, FileSystemReportFiles, type FullConfig } from "@allure/core"; -import AllureAwesomePlugin from "@allure/plugin-awesome"; +import { AllureReport, FileSystemReportFiles, type FullConfig } from "@allurereport/core"; +import AllureAwesomePlugin from "@allurereport/plugin-awesome"; import { type TestResult } from "allure-js-commons"; import { FileSystemWriter, ReporterRuntime } from "allure-js-commons/sdk/reporter"; import { readdirSync } from "node:fs" From 00c61a0e707f1a140f38aee8f5e28511d4e003ba Mon Sep 17 00:00:00 2001 From: epszaw Date: Fri, 13 Dec 2024 12:42:28 +0100 Subject: [PATCH 4/4] compress test utils --- .../test/allure-awesome/reportOptions.test.ts | 81 +++++++------------ .../test/allure-awesome/testResult.test.ts | 67 +++++---------- packages/e2e/test/allure-awesome/tree.test.ts | 71 ++++++---------- packages/e2e/test/utils/index.ts | 59 +++++++++++--- 4 files changed, 122 insertions(+), 156 deletions(-) diff --git a/packages/e2e/test/allure-awesome/reportOptions.test.ts b/packages/e2e/test/allure-awesome/reportOptions.test.ts index 69ac899..906692b 100644 --- a/packages/e2e/test/allure-awesome/reportOptions.test.ts +++ b/packages/e2e/test/allure-awesome/reportOptions.test.ts @@ -1,70 +1,45 @@ -import type { AllureStaticServer } from "@allurereport/static-server"; -import { serve } from "@allurereport/static-server"; import { expect, test } from "@playwright/test"; import { layer } from "allure-js-commons"; import { Stage, Status } from "allure-js-commons"; -import { mkdtemp, rm } from "node:fs/promises"; -import { tmpdir } from "node:os"; -import { resolve } from "node:path"; -import { generateTestResults } from "../utils/index.js"; - -let server: AllureStaticServer; -let host: string; -let allureTestResultsDir: string; -let allureReportDir: string; - -test.beforeAll(async () => { - const now = Date.now(); - const temp = tmpdir(); - - allureTestResultsDir = await mkdtemp(resolve(temp, "allure-results-")); - allureReportDir = await mkdtemp(resolve(temp, "allure-report-")); - - await generateTestResults({ - reportConfig: { - name: "Sample allure report" +import { type ReportBootstrap, boostrapReport } from "../utils/index.js"; + +let bootstrap: ReportBootstrap; + +const now = Date.now(); +const fixtures = { + testResults: [ + { + name: "0 sample passed test", + fullName: "sample.js#0 sample passed test", + status: Status.PASSED, + stage: Stage.FINISHED, + start: now, + stop: now + 1000, }, - resultsDir: allureTestResultsDir, - reportDir: allureReportDir, - testResults: [ - { - name: "0 sample passed test", - fullName: "sample.js#0 sample passed test", - status: Status.PASSED, - stage: Stage.FINISHED, - start: now, - stop: now + 1000, - }, - ] - }); - - server = await serve({ - servePath: resolve(allureReportDir, "./awesome"), - }); - host = `http://localhost:${server.port}`; -}); + ], +}; test.afterAll(async () => { - try { - await rm(allureTestResultsDir, { recursive: true }); - await rm(allureReportDir, { recursive: true }); - } catch (ignored) {} - - await server?.stop(); + await bootstrap?.shutdown?.(); }); -test.beforeEach(async ({ page }) => { +test.beforeEach(async () => { await layer("e2e"); - await page.goto(host); }); test.describe("allure-awesome", () => { test.describe("report options", () => { test("report title and page title contain give report name", async ({ page }) => { + bootstrap = await boostrapReport({ + reportConfig: { + name: "Sample allure report", + }, + testResults: fixtures.testResults, + }); + await page.goto(bootstrap.url); + await expect(page.getByTestId("report-title")).toHaveText("Sample allure report"); expect(await page.title()).toBe("Sample allure report"); }); - }) -}) - - + }); +}); diff --git a/packages/e2e/test/allure-awesome/testResult.test.ts b/packages/e2e/test/allure-awesome/testResult.test.ts index 49d8949..8e81239 100644 --- a/packages/e2e/test/allure-awesome/testResult.test.ts +++ b/packages/e2e/test/allure-awesome/testResult.test.ts @@ -1,31 +1,17 @@ -import type { AllureStaticServer } from "@allurereport/static-server"; -import { serve } from "@allurereport/static-server"; import { expect, test } from "@playwright/test"; import { layer } from "allure-js-commons"; import { Stage, Status } from "allure-js-commons"; -import { mkdtemp, rm } from "node:fs/promises"; -import { tmpdir } from "node:os"; -import { resolve } from "node:path"; -import { generateTestResults, randomNumber } from "../utils/index.js"; +import { type ReportBootstrap, boostrapReport, randomNumber } from "../utils/index.js"; -let server: AllureStaticServer; -let host: string; -let allureTestResultsDir: string; -let allureReportDir: string; +let bootstrap: ReportBootstrap; test.beforeAll(async () => { const now = Date.now(); - const temp = tmpdir(); - allureTestResultsDir = await mkdtemp(resolve(temp, "allure-results-")); - allureReportDir = await mkdtemp(resolve(temp, "allure-report-")); - - await generateTestResults({ + bootstrap = await boostrapReport({ reportConfig: { - name: "Sample allure report" + name: "Sample allure report", }, - resultsDir: allureTestResultsDir, - reportDir: allureReportDir, testResults: [ { name: "0 sample passed test", @@ -73,72 +59,62 @@ test.beforeAll(async () => { start: now + 4000, stage: Stage.PENDING, }, - ] - }); - - server = await serve({ - servePath: resolve(allureReportDir, "./awesome"), + ], }); - host = `http://localhost:${server.port}`; }); test.afterAll(async () => { - try { - await rm(allureTestResultsDir, { recursive: true }); - await rm(allureReportDir, { recursive: true }); - } catch (ignored) {} - - await server?.stop(); + await bootstrap.shutdown(); }); test.beforeEach(async ({ page }) => { await layer("e2e"); - await page.goto(host); + await page.goto(bootstrap.url); }); test.describe("allure-awesome", () => { test.describe("test results", () => { test("it's possible to navigate between tests results using navigation arrows", async ({ page }) => { const randomLeaf = page.getByTestId("tree-leaf").nth(randomNumber(0, 4)); - + await randomLeaf.click(); - + const testTitleText = await page.getByTestId("test-result-info-title").textContent(); const navCounterText = await page.getByTestId("test-result-nav-current").textContent(); const pressPrevArrow = await page.getByTestId("test-result-nav-next").isDisabled(); - + if (pressPrevArrow) { await page.getByTestId("test-result-nav-prev").click(); } else { await page.getByTestId("test-result-nav-next").click(); } - + await expect(page.getByTestId("test-result-nav-current")).not.toHaveText(navCounterText); await expect(page.getByTestId("test-result-info-title")).not.toHaveText(testTitleText); - + if (pressPrevArrow) { await page.getByTestId("test-result-nav-next").click(); } else { await page.getByTestId("test-result-nav-prev").click(); } - + await expect(page.getByTestId("test-result-nav-current")).toHaveText(navCounterText); await expect(page.getByTestId("test-result-info-title")).toHaveText(testTitleText); }); - + test("test result fullname copies to clipboard", async ({ page, context }) => { const passedLeaf = page.getByTestId("tree-leaf").nth(0); - + await passedLeaf.click(); await context.grantPermissions(["clipboard-read", "clipboard-write"]); await page.getByTestId("test-result-fullname-copy").click(); - + const handle = await page.evaluateHandle(() => globalThis.navigator.clipboard.readText()); const clipboardContent = await handle.jsonValue(); - + expect(clipboardContent).toEqual("sample.js#0 sample passed test"); }); - + test("failed test contains error message and stack", async ({ page }) => { await page.getByTestId("tree-leaf-status-failed").click(); await expect(page.getByTestId("test-result-error-message")).toHaveText("Assertion error: Expected 1 to be 2"); @@ -146,7 +122,7 @@ test.describe("allure-awesome", () => { await page.getByTestId("test-result-error-message").click(); await expect(page.getByTestId("test-result-error-trace")).toHaveText("failed test trace"); }); - + test("broken test contains error message and stack", async ({ page }) => { await page.getByTestId("tree-leaf-status-broken").click(); await expect(page.getByTestId("test-result-error-message")).toHaveText("An unexpected error"); @@ -154,6 +130,5 @@ test.describe("allure-awesome", () => { await page.getByTestId("test-result-error-message").click(); await expect(page.getByTestId("test-result-error-trace")).toHaveText("broken test trace"); }); - }) -}) - + }); +}); diff --git a/packages/e2e/test/allure-awesome/tree.test.ts b/packages/e2e/test/allure-awesome/tree.test.ts index 74a4572..267b974 100644 --- a/packages/e2e/test/allure-awesome/tree.test.ts +++ b/packages/e2e/test/allure-awesome/tree.test.ts @@ -1,31 +1,17 @@ -import type { AllureStaticServer } from "@allurereport/static-server"; -import { serve } from "@allurereport/static-server"; import { expect, test } from "@playwright/test"; import { layer } from "allure-js-commons"; import { Stage, Status } from "allure-js-commons"; -import { mkdtemp, rm } from "node:fs/promises"; -import { tmpdir } from "node:os"; -import { resolve } from "node:path"; -import { generateTestResults } from "../utils/index.js"; +import { type ReportBootstrap, boostrapReport } from "../utils/index.js"; -let server: AllureStaticServer; -let host: string; -let allureTestResultsDir: string; -let allureReportDir: string; +let bootstrap: ReportBootstrap; test.beforeAll(async () => { const now = Date.now(); - const temp = tmpdir(); - allureTestResultsDir = await mkdtemp(resolve(temp, "allure-results-")); - allureReportDir = await mkdtemp(resolve(temp, "allure-report-")); - - await generateTestResults({ + bootstrap = await boostrapReport({ reportConfig: { - name: "Sample allure report" + name: "Sample allure report", }, - resultsDir: allureTestResultsDir, - reportDir: allureReportDir, testResults: [ { name: "0 sample passed test", @@ -73,34 +59,24 @@ test.beforeAll(async () => { start: now + 4000, stage: Stage.PENDING, }, - ] - }); - - server = await serve({ - servePath: resolve(allureReportDir, "./awesome"), + ], }); - host = `http://localhost:${server.port}`; }); test.afterAll(async () => { - try { - await rm(allureTestResultsDir, { recursive: true }); - await rm(allureReportDir, { recursive: true }); - } catch (ignored) {} - - await server?.stop(); + await bootstrap.shutdown(); }); test.beforeEach(async ({ page }) => { await layer("e2e"); - await page.goto(host); + await page.goto(bootstrap.url); }); test.describe("allure-awesome", () => { test.describe("tree", () => { test("all types of tests are displayed", async ({ page }) => { const treeLeaves = page.getByTestId("tree-leaf"); - + await expect(treeLeaves).toHaveCount(5); await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("0 sample passed test"); await expect(treeLeaves.nth(0).getByTestId("tree-leaf-status-passed")).toBeVisible(); @@ -113,7 +89,7 @@ test.describe("allure-awesome", () => { await expect(treeLeaves.nth(4).getByTestId("tree-leaf-title")).toHaveText("4 sample unknown test"); await expect(treeLeaves.nth(4).getByTestId("tree-leaf-status-unknown")).toBeVisible(); }); - + test("statistics in metadata renders information about the tests", async ({ page }) => { await expect(page.getByTestId("metadata-item-total").getByTestId("metadata-value")).toHaveText("5"); await expect(page.getByTestId("metadata-item-passed").getByTestId("metadata-value")).toHaveText("1"); @@ -122,51 +98,50 @@ test.describe("allure-awesome", () => { await expect(page.getByTestId("metadata-item-skipped").getByTestId("metadata-value")).toHaveText("1"); await expect(page.getByTestId("metadata-item-unknown").getByTestId("metadata-value")).toHaveText("1"); }); - + test("tree tabs filter tests by the status", async ({ page }) => { const treeLeaves = page.getByTestId("tree-leaf"); - + await expect(treeLeaves).toHaveCount(5); - + await page.getByTestId("tab-passed").click(); await expect(treeLeaves).toHaveCount(1); await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("0 sample passed test"); - + await page.getByTestId("tab-failed").click(); await expect(treeLeaves).toHaveCount(1); await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("1 sample failed test"); - + await page.getByTestId("tab-broken").click(); await expect(treeLeaves).toHaveCount(1); await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("2 sample broken test"); - + await page.getByTestId("tab-skipped").click(); await expect(treeLeaves).toHaveCount(1); await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("3 sample skipped test"); - + await page.getByTestId("tab-unknown").click(); await expect(treeLeaves).toHaveCount(1); await expect(treeLeaves.nth(0).getByTestId("tree-leaf-title")).toHaveText("4 sample unknown test"); - + await page.getByTestId("tab-all").click(); await expect(treeLeaves).toHaveCount(5); }); - + test("test result page opens after test result click", async ({ page }) => { const passedLeaf = page.getByTestId("tree-leaf").nth(0); - + await passedLeaf.click(); - + await expect(page.getByTestId("test-result-info-title")).toHaveText("0 sample passed test"); await expect(page.getByTestId("tree-leaf-status-passed")).toBeVisible(); await expect(page.getByTestId("test-result-fullname")).toHaveText("sample.js#0 sample passed test"); }); - + test("search filters tests on typing", async ({ page }) => { await expect(page.getByTestId("tree-leaf")).toHaveCount(5); await page.getByTestId("search-input").fill("0 sample"); await expect(page.getByTestId("tree-leaf")).toHaveCount(1); }); - }) -}) - + }); +}); diff --git a/packages/e2e/test/utils/index.ts b/packages/e2e/test/utils/index.ts index 7994436..077e485 100644 --- a/packages/e2e/test/utils/index.ts +++ b/packages/e2e/test/utils/index.ts @@ -1,8 +1,24 @@ import { AllureReport, FileSystemReportFiles, type FullConfig } from "@allurereport/core"; import AllureAwesomePlugin from "@allurereport/plugin-awesome"; +import { serve } from "@allurereport/static-server"; import { type TestResult } from "allure-js-commons"; import { FileSystemWriter, ReporterRuntime } from "allure-js-commons/sdk/reporter"; -import { readdirSync } from "node:fs" +import { mkdtemp, rm } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { resolve } from "node:path"; + +export type GeneratorParams = { + reportDir: string; + resultsDir: string; + testResults: Partial[]; + reportConfig?: Omit; + pluginConfig?: any; +}; + +export interface ReportBootstrap { + url: string; + shutdown: () => Promise; +} export const randomNumber = (min: number, max: number) => { if (min > max) { @@ -12,20 +28,17 @@ export const randomNumber = (min: number, max: number) => { return Math.random() * (max - min) + min; }; -export const generateTestResults = async (payload: { - reportDir: string; - resultsDir: string; - testResults: Partial[]; - reportConfig: Omit; -}) => { - const { reportConfig, reportDir, resultsDir, testResults } = payload; +export const generateTestResults = async (payload: GeneratorParams) => { + const { reportConfig, reportDir, resultsDir, pluginConfig, testResults } = payload; const report = new AllureReport({ plugins: [ { id: "awesome", enabled: true, plugin: new AllureAwesomePlugin({}), - options: {}, + options: { + ...pluginConfig, + }, }, ], ...reportConfig, @@ -48,3 +61,31 @@ export const generateTestResults = async (payload: { await report.readDirectory(resultsDir); await report.done(); }; + +export const boostrapReport = async (params: Omit): Promise => { + const temp = tmpdir(); + const allureTestResultsDir = await mkdtemp(resolve(temp, "allure-results-")); + const allureReportDir = await mkdtemp(resolve(temp, "allure-report-")); + + await generateTestResults({ + ...params, + resultsDir: allureTestResultsDir, + reportDir: allureReportDir, + }); + + const server = await serve({ + servePath: resolve(allureReportDir, "./awesome"), + }); + + return { + url: `http://localhost:${server.port}`, + shutdown: async () => { + await server?.stop(); + + try { + await rm(allureTestResultsDir, { recursive: true }); + await rm(allureReportDir, { recursive: true }); + } catch (ignored) {} + }, + }; +};