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

Add links names patterns #973

Merged
merged 3 commits into from
May 23, 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
1 change: 1 addition & 0 deletions packages/allure-codeceptjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module.exports.config = {
+ {
+ type: "${LinkType.ISSUE}",
+ urlTemplate: "https://example.org/issues/%s",
+ nameTemplate: "Issue: %s",
+ },
+ {
+ type: "${LinkType.TMS}",
Expand Down
1 change: 1 addition & 0 deletions packages/allure-cucumberjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export default {
+ pattern: [/@issue=(.*)/],
+ type: "issue",
+ urlTemplate: "https://example.com/issues/%s",
+ nameTemplate: "Issue: %s",
+ },
+ {
+ pattern: [/@tms=(.*)/],
Expand Down
3 changes: 2 additions & 1 deletion packages/allure-cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ module.exports = {
+ links: [
+ {
+ type: "issue",
+ urlTemplate: "https://example.org/issues/%s"
+ urlTemplate: "https://example.org/issues/%s",
+ nameTemplate: "Issue: %s",
+ },
+ {
+ type: "tms",
Expand Down
3 changes: 2 additions & 1 deletion packages/allure-jasmine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ const reporter = new AllureJasmineReporter({
+ links: [
+ {
+ type: "issue",
+ urlTemplate: "https://example.org/issues/%s"
+ urlTemplate: "https://example.org/issues/%s",
+ nameTemplate: "Issue: %s",
+ },
+ {
+ type: "tms",
Expand Down
3 changes: 2 additions & 1 deletion packages/allure-jest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ const config = {
+ links: [
+ {
+ type: "issue",
+ urlTemplate: "https://example.org/issues/%s"
+ urlTemplate: "https://example.org/issues/%s",
+ nameTemplate: "Issue: %s",
+ },
+ {
+ type: "tms",
Expand Down
1 change: 1 addition & 0 deletions packages/allure-js-commons/src/sdk/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AllureContextProvider } from "./context/index.js";
export interface LinkConfig {
type: string;
urlTemplate: string;
nameTemplate?: string;
}

export interface Config {
Expand Down
11 changes: 11 additions & 0 deletions packages/allure-js-commons/src/sdk/ReporterRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,19 @@ export class ReporterRuntime {

const url = matcher.urlTemplate.replace("%s", link.url);

// we shouldn't need to reassign already assigned name
if (link.name || !matcher.nameTemplate) {
return {
...link,
url,
};
}

const name = matcher.nameTemplate.replace("%s", link.url);

return {
...link,
name,
url,
};
});
Expand Down
91 changes: 91 additions & 0 deletions packages/allure-js-commons/test/sdk/node/ReporterRuntime.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import { describe, expect, it } from "vitest";
import { Link } from "../../../src/model.js";
import { AllureNodeReporterRuntime } from "../../../src/sdk/node/index.js";
import { mockWriter } from "../../utils/writer.js";

const fixtures = {
links: [
{
url: "1",
name: "issue-1",
type: "issue",
},
{
url: "2",
type: "tms",
},
{
url: "3",
type: "custom",
},
] as Link[],
};

describe("AllureNodeReporterRuntime", () => {
describe("writeAttachmentFromPath", () => {
it("should use extension from fileExtension option if specified", () => {
Expand Down Expand Up @@ -67,4 +86,76 @@ describe("AllureNodeReporterRuntime", () => {
expect(writeAttachmentFromPathCall[1]).to.be.eq("attachment content");
});
});

describe("applyRuntimeMessages", () => {
it("keeps links as they are when links configuration is not provided", () => {
const writer = mockWriter();
const runtime = new AllureNodeReporterRuntime({ writer });

runtime.startTest({});
runtime.applyRuntimeMessages([
{
type: "metadata",
data: {
links: fixtures.links,
},
},
]);
runtime.writeTest();

expect(writer.writeResult).toHaveBeenCalledWith(
expect.objectContaining({
links: fixtures.links,
}),
);
});

it("transforms links according the runtime configuration", () => {
const writer = mockWriter();
const runtime = new AllureNodeReporterRuntime({
writer,
links: [
{
type: "issue",
urlTemplate: "https://allurereport.org/issues/%s",
nameTemplate: "Issue %s",
},
{
type: "tms",
urlTemplate: "https://allurereport.org/tasks/%s",
nameTemplate: "Task %s",
},
],
});

runtime.startTest({});
runtime.applyRuntimeMessages([
{
type: "metadata",
data: {
links: fixtures.links,
},
},
]);
runtime.writeTest();

expect(writer.writeResult).toHaveBeenCalledWith(
expect.objectContaining({
links: [
{
type: "issue",
url: "https://allurereport.org/issues/1",
name: "issue-1",
},
{
type: "tms",
url: "https://allurereport.org/tasks/2",
name: "Task 2",
},
fixtures.links[2],
],
}),
);
});
});
});
3 changes: 2 additions & 1 deletion packages/allure-playwright/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ module.exports = {
+ links: [
+ {
+ type: "issue",
+ urlTemplate: "https://example.org/issues/%s"
+ urlTemplate: "https://example.org/issues/%s",
+ nameTemplate: "Issue: %s",
+ },
+ {
+ type: "tms",
Expand Down
3 changes: 2 additions & 1 deletion packages/allure-vitest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export default defineConfig({
+ links: [
+ {
+ type: "issue",
+ urlTemplate: "https://example.org/issues/%s"
+ urlTemplate: "https://example.org/issues/%s",
+ nameTemplate: "Issue: %s",
+ },
+ {
+ type: "tms",
Expand Down
Loading