Skip to content

Commit

Permalink
fix: labels consistency across packages
Browse files Browse the repository at this point in the history
  • Loading branch information
todti authored and baev committed Aug 12, 2024
1 parent 9e0e6b6 commit 5966e2d
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 71 deletions.
12 changes: 7 additions & 5 deletions packages/allure-cucumberjs/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
type TestStepResult,
TestStepResultStatus,
} from "@cucumber/messages";
import os from "node:os";
import { extname } from "node:path";
import process from "node:process";
import type { Label, Link, TestResult } from "allure-js-commons";
Expand All @@ -21,6 +20,8 @@ import {
createDefaultWriter,
createStepResult,
getEnvironmentLabels,
getHostLabel,
getPackageLabelFromPath,
getWorstStepResultStatus,
md5,
} from "allure-js-commons/sdk/reporter";
Expand Down Expand Up @@ -246,12 +247,11 @@ export default class AllureCucumberReporter extends Formatter {
fullName,
};

const hostLabel = getHostLabel();
const packageLabel = getPackageLabelFromPath(fullName);

result.labels!.push(...getEnvironmentLabels());
result.labels!.push(
{
name: LabelName.HOST,
value: os.hostname(),
},
{
name: LabelName.LANGUAGE,
value: "javascript",
Expand All @@ -260,6 +260,8 @@ export default class AllureCucumberReporter extends Formatter {
name: LabelName.FRAMEWORK,
value: "cucumberjs",
},
packageLabel,
hostLabel,
{
name: LabelName.THREAD,
value: data.workerId || ALLURE_THREAD_NAME || process.pid.toString(),
Expand Down
12 changes: 10 additions & 2 deletions packages/allure-jasmine/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import * as allure from "allure-js-commons";
import { Stage, Status } from "allure-js-commons";
import { LabelName, Stage, Status } from "allure-js-commons";
import type { RuntimeMessage } from "allure-js-commons/sdk";
import { getMessageAndTraceFromError, getStatusFromError, isPromise } from "allure-js-commons/sdk";
import type { FixtureType, ReporterConfig } from "allure-js-commons/sdk/reporter";
import {
ReporterRuntime,
createDefaultWriter,
getEnvironmentLabels,
getHostLabel,
getPackageLabelFromPath,
getSuiteLabels,
getThreadLabel,
hasSkipLabel,
} from "allure-js-commons/sdk/reporter";
import { MessageTestRuntime, setGlobalTestRuntime } from "allure-js-commons/sdk/runtime";
Expand Down Expand Up @@ -132,7 +135,7 @@ export default class AllureJasmineReporter implements jasmine.CustomReporter {
}
}

specDone(spec: jasmine.SpecResult): void {
specDone(spec: jasmine.SpecResult & { filename: string }): void {
if (!this.currentAllureTestUuid) {
return;
}
Expand All @@ -144,6 +147,11 @@ export default class AllureJasmineReporter implements jasmine.CustomReporter {

result.labels.push(...suitesLabels);
result.labels.push(...getEnvironmentLabels());
result.labels.push({ name: LabelName.LANGUAGE, value: "javascript" });
result.labels.push({ name: LabelName.FRAMEWORK, value: "jasmine" });
result.labels.push(getHostLabel());
result.labels.push(getPackageLabelFromPath(spec.filename));
result.labels.push(getThreadLabel());

if (spec.status === "pending" || spec.status === "disabled" || spec.status === "excluded") {
result.status = Status.SKIPPED;
Expand Down
99 changes: 44 additions & 55 deletions packages/allure-jasmine/test/spec/suites.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,60 +29,49 @@ it("sets labels", async () => {
`,
});

expect(tests).toHaveLength(3);
expect(tests).toEqual(
expect.arrayContaining([
expect.objectContaining({
name: "should pass 1",
labels: [
{
name: LabelName.PARENT_SUITE,
value: "first suite",
},
{
name: LabelName.SUITE,
value: "second suite",
},
{
name: LabelName.SUB_SUITE,
value: "third suite > fourth suite > fifth suite",
},
],
}),
expect.objectContaining({
name: "should pass 2",
labels: [
{
name: LabelName.PARENT_SUITE,
value: "first suite",
},
{
name: LabelName.SUITE,
value: "second suite",
},
{
name: LabelName.SUB_SUITE,
value: "third suite > fourth suite > fifth suite",
},
],
}),
expect.objectContaining({
name: "should pass 3",
labels: [
{
name: LabelName.PARENT_SUITE,
value: "first suite",
},
{
name: LabelName.SUITE,
value: "second suite",
},
{
name: LabelName.SUB_SUITE,
value: "third suite > fourth suite > fifth suite",
},
],
}),
]),
const expectedValue = {
value: expect.any(String),
};

const testObject = [
{
name: LabelName.LANGUAGE,
value: "javascript",
},
{
name: LabelName.FRAMEWORK,
value: "jasmine",
},
{
name: LabelName.HOST,
...expectedValue,
},
{
name: LabelName.PACKAGE,
...expectedValue,
},
{ name: LabelName.THREAD, ...expectedValue },
{
name: LabelName.PARENT_SUITE,
value: "first suite",
},
{
name: LabelName.SUITE,
value: "second suite",
},
{
name: LabelName.SUB_SUITE,
value: "third suite > fourth suite > fifth suite",
},
];

const testExpectations = tests.map(() =>
expect.objectContaining({
name: expect.any(String),
labels: expect.arrayContaining(testObject),
}),
);

expect(tests).toHaveLength(3);
expect(tests).toEqual(expect.arrayContaining(testExpectations));
});
4 changes: 2 additions & 2 deletions packages/allure-jest/src/environmentFactory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { EnvironmentContext, JestEnvironment, JestEnvironmentConfig } from "@jest/environment";
import type { Circus } from "@jest/types";
import os from "node:os";
import { dirname, sep } from "node:path";
import { sep } from "node:path";
import process from "node:process";
import * as allure from "allure-js-commons";
import { LabelName, Stage, Status } from "allure-js-commons";
Expand Down Expand Up @@ -191,7 +191,7 @@ const createJestEnvironment = <T extends typeof JestEnvironment>(Base: T): T =>

const threadLabel = ALLURE_THREAD_NAME || JEST_WORKER_ID || process.pid.toString();
const hostLabel = ALLURE_HOST_NAME || hostname;
const packageLabel = dirname(this.testPath).split(sep).join(".");
const packageLabel = this.testPath.replace(sep, ".");

this.#startScope();
const testUuid = this.runtime.startTest(
Expand Down
2 changes: 1 addition & 1 deletion packages/allure-playwright/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class AllureReporter implements ReporterV2 {
fullName: `${relativeFile}:${test.location.line}:${test.location.column}`,
};

result.labels!.push({ name: LabelName.LANGUAGE, value: "JavaScript" });
result.labels!.push({ name: LabelName.LANGUAGE, value: "javascript" });
result.labels!.push({ name: LabelName.FRAMEWORK, value: "Playwright" });
result.labels!.push({ name: "titlePath", value: suite.titlePath().join(" > ") });
result.labels!.push({ name: LabelName.PACKAGE, value: pathElements.join(".") });
Expand Down
4 changes: 2 additions & 2 deletions packages/allure-playwright/test/spec/suites.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ it("reports a single suite structure", async () => {
expect.arrayContaining([
{
name: LabelName.LANGUAGE,
value: "JavaScript",
value: "javascript",
},
{
name: LabelName.FRAMEWORK,
Expand Down Expand Up @@ -98,7 +98,7 @@ it("reports a multiple nested suites structure", async () => {
expect.arrayContaining([
{
name: LabelName.LANGUAGE,
value: "JavaScript",
value: "javascript",
},
{
name: LabelName.FRAMEWORK,
Expand Down
18 changes: 14 additions & 4 deletions packages/newman-reporter-allure/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
import type { EventEmitter } from "events";
import type { ConsoleEvent, Cursor, NewmanRunExecutionAssertion } from "newman";
import type { CollectionDefinition, Event, HeaderList, Item, Request, Response } from "postman-collection";
import type { Label } from "allure-js-commons";
import { ContentType, LabelName, Stage, Status } from "allure-js-commons";
import type { ReporterConfig } from "allure-js-commons/sdk/reporter";
import {
ReporterRuntime,
createDefaultWriter,
getEnvironmentLabels,
getHostLabel,
getPackageLabelFromPath,
getSuiteLabels,
getThreadLabel,
} from "allure-js-commons/sdk/reporter";
import type { PmItem, RunningItem } from "./model.js";
import { extractMeta } from "./utils.js";
Expand Down Expand Up @@ -74,9 +78,7 @@ class AllureReporter {
return;
}

const execScript = args.executions[0]?.script.exec?.join("\n");

currentPmItem.prerequest = execScript;
currentPmItem.prerequest = args.executions[0]?.script.exec?.join("\n");
}

onBeforeItem(err: any, args: { item: Item; cursor: Cursor }) {
Expand All @@ -91,15 +93,23 @@ class AllureReporter {
const item = args.item;
const fullName = this.#getFullName(item);
const testPath = this.#pathToItem(item);
const hostLabel = getHostLabel();
const threadLabel = getThreadLabel();
const packageLabelFromPath: Label = getPackageLabelFromPath("");

const { labels } = extractMeta(args.item.events);

this.currentTest = this.allureRuntime.startTest({
name: args.item.name,
fullName,
stage: Stage.RUNNING,
labels: [
{ name: LabelName.LANGUAGE, value: "javascript" },
{ name: LabelName.FRAMEWORK, value: "newman" },
{ name: LabelName.HOST, value: "localhost" },
{ name: LabelName.PACKAGE, value: "" },
hostLabel,
threadLabel,
packageLabelFromPath,
...labels,
...getEnvironmentLabels(),
],
Expand Down

0 comments on commit 5966e2d

Please sign in to comment.