Skip to content

Commit

Permalink
compress test utils
Browse files Browse the repository at this point in the history
  • Loading branch information
epszaw committed Dec 13, 2024
1 parent 623d585 commit 00c61a0
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 156 deletions.
81 changes: 28 additions & 53 deletions packages/e2e/test/allure-awesome/reportOptions.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
})
})


});
});
67 changes: 21 additions & 46 deletions packages/e2e/test/allure-awesome/testResult.test.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -73,87 +59,76 @@ 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");
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");
});
})
})

});
});
71 changes: 23 additions & 48 deletions packages/e2e/test/allure-awesome/tree.test.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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();
Expand All @@ -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");
Expand All @@ -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);
});
})
})

});
});
Loading

0 comments on commit 00c61a0

Please sign in to comment.