Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: labels consistency across packages #1105

Merged
merged 5 commits into from
Aug 15, 2024
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
2 changes: 2 additions & 0 deletions packages/allure-codeceptjs/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,6 @@ export class AllureCodeceptJsReporter extends AllureMochaReporter {
}

protected getFrameworkName = () => "codeceptjs";

protected getWorkerId = () => undefined;
}
25 changes: 0 additions & 25 deletions packages/allure-codeceptjs/test/spec/globalLabels.test.ts

This file was deleted.

113 changes: 113 additions & 0 deletions packages/allure-codeceptjs/test/spec/labels.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { expect, it } from "vitest";
import { runCodeceptJsInlineTest } from "../utils.js";

it("should add host & thread labels", async () => {
const { tests } = await runCodeceptJsInlineTest(
{
"nested/login.test.js": `
Feature("login-feature");
Scenario("failed-scenario", async ({ I }) => {
I.fail();
});
Scenario("passed-scenario", async ({ I }) => {
I.pass();
});
`,
},
{},
);

expect(tests).toEqual(
expect.arrayContaining([
expect.objectContaining({
name: "failed-scenario",
labels: expect.arrayContaining([
{
name: "host",
value: expect.any(String),
},
{
name: "thread",
value: expect.any(String),
},
]),
}),
expect.objectContaining({
name: "passed-scenario",
labels: expect.arrayContaining([
{
name: "host",
value: expect.any(String),
},
{
name: "thread",
value: expect.any(String),
},
]),
}),
]),
);
});

it("should add package label", async () => {
const { tests } = await runCodeceptJsInlineTest(
{
"nested/login.test.js": `
Feature("login-feature");
Scenario("failed-scenario", async ({ I }) => {
I.fail();
});
Scenario("passed-scenario", async ({ I }) => {
I.pass();
});
`,
},
{},
);

expect(tests).toEqual(
expect.arrayContaining([
expect.objectContaining({
name: "failed-scenario",
labels: expect.arrayContaining([
{
name: "package",
value: "nested.login.test.js",
},
]),
}),
expect.objectContaining({
name: "passed-scenario",
labels: expect.arrayContaining([
{
name: "package",
value: "nested.login.test.js",
},
]),
}),
]),
);
});

it("should add labels from env variables", async () => {
const { tests } = await runCodeceptJsInlineTest(
{
"sample.test.js": `
Feature("sample-feature");
Scenario("sample-scenario", async () => {});
`,
},
{
ALLURE_LABEL_A: "a",
ALLURE_LABEL_B: "b",
},
);

expect(tests).toHaveLength(1);
expect(tests[0].labels).toEqual(
expect.arrayContaining([
{ name: "A", value: "a" },
{ name: "B", value: "b" },
]),
);
});
30 changes: 10 additions & 20 deletions packages/allure-cucumberjs/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ 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";
import { ContentType, LabelName, Stage, Status } from "allure-js-commons";
import { getMessageAndTraceFromError } from "allure-js-commons/sdk";
Expand All @@ -21,14 +19,17 @@ import {
createDefaultWriter,
createStepResult,
getEnvironmentLabels,
getFrameworkLabel,
getHostLabel,
getLanguageLabel,
getPackageLabel,
getThreadLabel,
getWorstStepResultStatus,
md5,
} from "allure-js-commons/sdk/reporter";
import { AllureCucumberWorld } from "./legacy.js";
import type { AllureCucumberLinkConfig, AllureCucumberReporterConfig, LabelConfig } from "./model.js";

const { ALLURE_THREAD_NAME } = process.env;

export default class AllureCucumberReporter extends Formatter {
private readonly afterHooks: Record<string, TestCaseHookDefinition> = {};
private readonly beforeHooks: Record<string, TestCaseHookDefinition> = {};
Expand Down Expand Up @@ -248,22 +249,11 @@ export default class AllureCucumberReporter extends Formatter {

result.labels!.push(...getEnvironmentLabels());
result.labels!.push(
{
name: LabelName.HOST,
value: os.hostname(),
},
{
name: LabelName.LANGUAGE,
value: "javascript",
},
{
name: LabelName.FRAMEWORK,
value: "cucumberjs",
},
{
name: LabelName.THREAD,
value: data.workerId || ALLURE_THREAD_NAME || process.pid.toString(),
},
getLanguageLabel(),
getFrameworkLabel("cucumberjs"),
getPackageLabel(pickle.uri),
getHostLabel(),
getThreadLabel(data.workerId),
);

if (doc?.feature) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,90 @@ import { expect, it } from "vitest";
import { Stage, Status } from "allure-js-commons";
import { runCucumberInlineTest } from "../utils.js";

it("should add thread and host labels", async () => {
const { tests } = await runCucumberInlineTest(["simple"], ["simple"]);

expect(tests).toEqual(
expect.arrayContaining([
expect.objectContaining({
name: "passed",
labels: expect.arrayContaining([
{
name: "host",
value: expect.any(String),
},
{
name: "thread",
value: expect.any(String),
},
]),
}),
expect.objectContaining({
name: "failed",
labels: expect.arrayContaining([
{
name: "host",
value: expect.any(String),
},
{
name: "thread",
value: expect.any(String),
},
]),
}),
expect.objectContaining({
name: "broken",
labels: expect.arrayContaining([
{
name: "host",
value: expect.any(String),
},
{
name: "thread",
value: expect.any(String),
},
]),
}),
]),
);
});

it("should add thread package label", async () => {
const { tests } = await runCucumberInlineTest(["simple"], ["simple"]);

expect(tests).toEqual(
expect.arrayContaining([
expect.objectContaining({
name: "passed",
labels: expect.arrayContaining([
{
name: "package",
value: "features.simple.feature",
},
]),
}),
expect.objectContaining({
name: "failed",
labels: expect.arrayContaining([
{
name: "package",
value: "features.simple.feature",
},
]),
}),
expect.objectContaining({
name: "broken",
labels: expect.arrayContaining([
{
name: "package",
value: "features.simple.feature",
},
]),
}),
]),
);
});

it("sets label from env variables", async () => {
const { tests } = await runCucumberInlineTest(["simple"], ["simple"], undefined, undefined, {
ALLURE_LABEL_A: "a",
Expand Down
27 changes: 27 additions & 0 deletions packages/allure-cucumberjs/test/spec/simple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,30 @@ it("handles basic cases", async () => {
}),
);
});

it("should set full name", async () => {
const { tests } = await runCucumberInlineTest(["simple"], ["simple"]);

expect(tests).toHaveLength(3);
expect(tests).toContainEqual(
expect.objectContaining({
name: "passed",
fullName: "features/simple.feature#passed",
status: Status.PASSED,
}),
);
expect(tests).toContainEqual(
expect.objectContaining({
name: "failed",
fullName: "features/simple.feature#failed",
status: Status.FAILED,
}),
);
expect(tests).toContainEqual(
expect.objectContaining({
name: "broken",
fullName: "features/simple.feature#broken",
status: Status.BROKEN,
}),
);
});
21 changes: 12 additions & 9 deletions packages/allure-cypress/src/reporter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import type Cypress from "cypress";
import path from "node:path";
import { ContentType, LabelName, Stage, Status } from "allure-js-commons";
import { ContentType, Stage, Status } from "allure-js-commons";
import type { RuntimeMessage } from "allure-js-commons/sdk";
import {
ReporterRuntime,
createDefaultWriter,
getEnvironmentLabels,
getFrameworkLabel,
getHostLabel,
getLanguageLabel,
getPackageLabel,
getSuiteLabels,
getThreadLabel,
parseTestPlan,
} from "allure-js-commons/sdk/reporter";
import type {
Expand Down Expand Up @@ -261,17 +266,15 @@ export class AllureCypress {
fullName,
stage: Stage.RUNNING,
labels: [
{
name: LabelName.LANGUAGE,
value: "javascript",
},
{
name: LabelName.FRAMEWORK,
value: "cypress",
},
getLanguageLabel(),
getFrameworkLabel("cypress"),

...getSuiteLabels(context.suiteNames),
...metadataLabels,
...getEnvironmentLabels(),
getHostLabel(),
getThreadLabel(),
getPackageLabel(context.specPath),
],
},
[context.videoScope, ...context.suiteScopes, testScope],
Expand Down
29 changes: 0 additions & 29 deletions packages/allure-cypress/test/spec/globalLabels.test.ts

This file was deleted.

Loading
Loading