🌐 AI搜索 & 代理 主页
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
8 changes: 6 additions & 2 deletions packages/allure-hermione/docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## Running hermione tests locally

The easiest way to run Hermione tests locally is [Selenium standalone grid](https://www.npmjs.com/package/selenium-standalone).
The easiest way to run Hermione tests locally
is [Selenium standalone grid](https://www.npmjs.com/package/selenium-standalone).

```shell
npm i -g selenium-standalone # install the package globally
Expand All @@ -20,7 +21,10 @@ module.exports = {
};
```

Tests in the package already runs the grid before themselves, so you don't need to start it manually.
Tests in the package already runs the grid before themselves, so you don't need to start it
manually.

**Don't forget to compile the reporter before running tests**!

## Using repeater

Expand Down
103 changes: 74 additions & 29 deletions packages/allure-hermione/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export type TestIDFactory = (testId?: string) => string;
const hostname = os.hostname();

const hermioneAllureReporter = (hermione: Hermione, opts: AllureReportOptions) => {
const { ALLURE_REPORTER_DEV_MODE } = process.env;
const loadedTests: Map<string, Hermione.Test> = new Map();
const runningTests: Map<string, AllureTest> = new Map();
const runtime = new AllureRuntime({
resultsDir: "allure-results",
Expand All @@ -60,6 +62,47 @@ const hermioneAllureReporter = (hermione: Hermione, opts: AllureReportOptions) =

return () => `${context.browserId}:${context.id()}`;
};
/**
* Create Allure test from Hermione test object with all the possible initial labels
*
* @param test Hermione test object
* @returns Allure test
*/
const createAllureTest = (test: Hermione.Test): AllureTest => {
const { ALLURE_HOST_NAME, ALLURE_THREAD_NAME } = process.env;
const thread = ALLURE_THREAD_NAME || test.sessionId;
const hostnameLabel = ALLURE_HOST_NAME || hostname;
const currentTest = new AllureTest(runtime, Date.now());
const [parentSuite, suite, ...subSuites] = getSuitePath(test);

currentTest.name = test.title;
currentTest.fullName = test.fullTitle();
currentTest.historyId = md5(test.fullTitle());
currentTest.stage = Stage.RUNNING;

currentTest.addLabel(LabelName.HOST, hostnameLabel);
currentTest.addLabel(LabelName.LANGUAGE, "javascript");
currentTest.addLabel(LabelName.FRAMEWORK, "hermione");
currentTest.addParameter("browser", test.browserId);

if (thread) {
currentTest.addLabel(LabelName.THREAD, thread);
}

if (parentSuite) {
currentTest.addLabel(LabelName.PARENT_SUITE, parentSuite);
}

if (suite) {
currentTest.addLabel(LabelName.SUITE, suite);
}

if (subSuites.length > 0) {
currentTest.addLabel(LabelName.SUB_SUITE, subSuites.join(" > "));
}

return currentTest;
};
const handleTestError = (test: Hermione.Test, error: Hermione.TestError) => {
const testId = getTestId(test);
const currentTest = runningTests.get(testId())!;
Expand Down Expand Up @@ -227,40 +270,22 @@ const hermioneAllureReporter = (hermione: Hermione, opts: AllureReportOptions) =
}
});
});
hermione.on(hermione.events.AFTER_TESTS_READ, (collection) => {
// cache all the tests to handle skipped tests in future
collection.eachTest((test) => {
const testId = getTestId(test);

loadedTests.set(testId(), test);
});
});
hermione.on(hermione.events.TEST_BEGIN, (test) => {
// test hasn't been actually started
if (!test.sessionId) {
throw new Error("Test session hasn't been started correctly! Check the driver availability.");
return;
}

const testId = getTestId(test);
const { ALLURE_HOST_NAME, ALLURE_THREAD_NAME } = process.env;
const thread = ALLURE_THREAD_NAME || test.sessionId;
const hostnameLabel = ALLURE_HOST_NAME || hostname;
const currentTest = new AllureTest(runtime, Date.now());
const [parentSuite, suite, ...subSuites] = getSuitePath(test);

currentTest.name = test.title;
currentTest.fullName = test.fullTitle();
currentTest.historyId = md5(test.fullTitle());
currentTest.stage = Stage.RUNNING;

currentTest.addLabel(LabelName.HOST, hostnameLabel);
currentTest.addLabel(LabelName.LANGUAGE, "javascript");
currentTest.addLabel(LabelName.FRAMEWORK, "hermione");
currentTest.addLabel(LabelName.THREAD, thread);
currentTest.addParameter("browser", test.browserId);

if (parentSuite) {
currentTest.addLabel(LabelName.PARENT_SUITE, parentSuite);
}

if (suite) {
currentTest.addLabel(LabelName.SUITE, suite);
}

if (subSuites.length > 0) {
currentTest.addLabel(LabelName.SUB_SUITE, subSuites.join(" > "));
}
const currentTest = createAllureTest(test);

runningTests.set(testId(), currentTest);
});
Expand All @@ -282,6 +307,11 @@ const hermioneAllureReporter = (hermione: Hermione, opts: AllureReportOptions) =
currentTest.status = Status.FAILED;
});
hermione.on(hermione.events.TEST_END, (test) => {
// test hasn't been started
if (!test.startTime) {
return;
}

const testId = getTestId(test);
const currentTest = runningTests.get(testId())!;

Expand All @@ -291,8 +321,23 @@ const hermioneAllureReporter = (hermione: Hermione, opts: AllureReportOptions) =

currentTest.stage = Stage.FINISHED;
currentTest.endTest(Date.now());
loadedTests.delete(testId());
runningTests.delete(testId());
});
hermione.on(hermione.events.END, () => {
// all tests have been finished
if (loadedTests.size === 0) {
return;
}

loadedTests.forEach((test) => {
const currentTest = createAllureTest(test);

currentTest.status = Status.SKIPPED;
currentTest.stage = Stage.FINISHED;
currentTest.endTest();
});
});

// it needs for tests because we need to read runtime writer data redefined in hermione config
// eslint-disable-next-line
Expand Down
7 changes: 5 additions & 2 deletions packages/allure-hermione/test/.hermione.conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module.exports = {
gridUrl: "http://localhost:4444/wd/hub",
httpTimeout: 50000,
sessionQuitTimeout: 50000,
sets: {
desktop: {
browsers: ["headless"],
Expand All @@ -8,9 +10,10 @@ module.exports = {
},
browsers: {
headless: {
automationProtocol: "webdriver",
desiredCapabilities: {
browserName: "chrome",
"goog:chromeOptions": {
browserName: "firefox",
"moz:firefoxOptions": {
args: ["--headless"],
},
},
Expand Down
3 changes: 0 additions & 3 deletions packages/allure-hermione/test/fixtures/allureId.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/allure-hermione/test/fixtures/attachments.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
it("adds json attachment", async ({ browser, currentTest }) => {
it("json", async ({ browser, currentTest }) => {
await browser.attach(currentTest.id(), JSON.stringify({ foo: "bar" }), "application/json");
});
3 changes: 0 additions & 3 deletions packages/allure-hermione/test/fixtures/epic.js

This file was deleted.

9 changes: 0 additions & 9 deletions packages/allure-hermione/test/fixtures/failedSteps.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/allure-hermione/test/fixtures/feature.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/allure-hermione/test/fixtures/issue.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/allure-hermione/test/fixtures/label.js

This file was deleted.

43 changes: 43 additions & 0 deletions packages/allure-hermione/test/fixtures/labels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
it("custom", async ({ browser, currentTest }) => {
await browser.label(currentTest.id(), "foo", "bar");
});

it("allureId", async ({ browser, currentTest }) => {
await browser.id(currentTest.id(), "42");
});

it("epic", async ({ browser, currentTest }) => {
await browser.epic(currentTest.id(), "foo");
});

it("owner", async ({ browser, currentTest }) => {
await browser.owner(currentTest.id(), "foo");
});

it("parentSuite", async ({ browser, currentTest }) => {
await browser.parentSuite(currentTest.id(), "foo");
});

it("subSuite", async ({ browser, currentTest }) => {
await browser.subSuite(currentTest.id(), "foo");
});

it("severity", async ({ browser, currentTest }) => {
await browser.severity(currentTest.id(), "foo");
});

it("story", async ({ browser, currentTest }) => {
await browser.story(currentTest.id(), "foo");
});

it("suite", async ({ browser, currentTest }) => {
await browser.suite(currentTest.id(), "foo");
});

it("tag", async ({ browser, currentTest }) => {
await browser.tag(currentTest.id(), "foo");
});

it("feature", async ({ browser, currentTest }) => {
await browser.feature(currentTest.id(), "foo");
});
3 changes: 0 additions & 3 deletions packages/allure-hermione/test/fixtures/link.js

This file was deleted.

11 changes: 11 additions & 0 deletions packages/allure-hermione/test/fixtures/links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
it("custom", async ({ browser, currentTest }) => {
await browser.link(currentTest.id(), "http://example.org", "bar", "foo");
});

it("tms", async ({ browser, currentTest }) => {
await browser.tms(currentTest.id(), "foo", "http://example.org");
});

it("issue", async ({ browser, currentTest }) => {
await browser.issue(currentTest.id(), "foo", "http://example.org");
});
3 changes: 0 additions & 3 deletions packages/allure-hermione/test/fixtures/owner.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
it("adds parameter", async ({ browser, currentTest }) => {
it("custom", async ({ browser, currentTest }) => {
await browser.parameter(currentTest.id(), "foo", "bar", {
excluded: false,
mode: "hidden",
Expand Down
3 changes: 0 additions & 3 deletions packages/allure-hermione/test/fixtures/parentSuite.js

This file was deleted.

9 changes: 0 additions & 9 deletions packages/allure-hermione/test/fixtures/passedSteps.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/allure-hermione/test/fixtures/severity.js

This file was deleted.

10 changes: 10 additions & 0 deletions packages/allure-hermione/test/fixtures/skipped.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
it.skip("native", () => {});

describe("", () => {
it.skip("suite", () => {});
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we also need fixture for the describe.skip?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They actually have problem with tests only, let's keep this implementation only for tests and add suites handling later

describe("", () => {
hermione.skip.in("headless");
it("browser", () => {});
});
19 changes: 19 additions & 0 deletions packages/allure-hermione/test/fixtures/steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
it("passed", async ({ browser, currentTest }) => {
await browser.step(currentTest.id(), "first step name", async (s1) => {
await s1.step("second step name", async (s2) => {
await s2.step("third step name", (s3) => {
s3.label("foo", "bar");
});
});
});
});

it("failed", async ({ browser, currentTest }) => {
await browser.step(currentTest.id(), "first step name", async (s1) => {
await s1.step("second step name", async (s2) => {
await s2.step("third step name", (s3) => {
throw new Error("foo");
});
});
});
});
3 changes: 0 additions & 3 deletions packages/allure-hermione/test/fixtures/story.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/allure-hermione/test/fixtures/subSuite.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/allure-hermione/test/fixtures/suite.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/allure-hermione/test/fixtures/tag.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/allure-hermione/test/fixtures/tms.js

This file was deleted.

5 changes: 5 additions & 0 deletions packages/allure-hermione/test/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import glob from "glob";
import Mocha from "mocha";
import selenium from "selenium-standalone";
import "source-map-support/register";
import { TestResult } from "allure-js-commons";

export const getTestResultByName = (results: TestResult[], name: string) =>
results.find((result) => result.name === name)!;

(async () => {
await selenium.install();

const seleniumProcess = await selenium.start();

const mocha = new Mocha({
timeout: 30000,
reporter: "mocha-multi-reporters",
Expand Down
Loading