diff --git a/packages/allure-codeceptjs/README.md b/packages/allure-codeceptjs/README.md index 5d83333ae..5f2b2a3c6 100644 --- a/packages/allure-codeceptjs/README.md +++ b/packages/allure-codeceptjs/README.md @@ -89,6 +89,7 @@ module.exports.config = { + { + type: "${LinkType.ISSUE}", + urlTemplate: "https://example.org/issues/%s", ++ nameTemplate: "Issue: %s", + }, + { + type: "${LinkType.TMS}", diff --git a/packages/allure-cucumberjs/README.md b/packages/allure-cucumberjs/README.md index 60a8cbfec..15059be8e 100644 --- a/packages/allure-cucumberjs/README.md +++ b/packages/allure-cucumberjs/README.md @@ -140,6 +140,7 @@ export default { + pattern: [/@issue=(.*)/], + type: "issue", + urlTemplate: "https://example.com/issues/%s", ++ nameTemplate: "Issue: %s", + }, + { + pattern: [/@tms=(.*)/], diff --git a/packages/allure-cypress/README.md b/packages/allure-cypress/README.md index 12cc18ad4..d99521be5 100644 --- a/packages/allure-cypress/README.md +++ b/packages/allure-cypress/README.md @@ -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", diff --git a/packages/allure-jasmine/README.md b/packages/allure-jasmine/README.md index 5cae1abe4..5a8e4babe 100644 --- a/packages/allure-jasmine/README.md +++ b/packages/allure-jasmine/README.md @@ -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", diff --git a/packages/allure-jest/README.md b/packages/allure-jest/README.md index 15c0af354..c82f4ea4a 100644 --- a/packages/allure-jest/README.md +++ b/packages/allure-jest/README.md @@ -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", diff --git a/packages/allure-js-commons/src/sdk/Config.ts b/packages/allure-js-commons/src/sdk/Config.ts index d90994130..4baa0325e 100644 --- a/packages/allure-js-commons/src/sdk/Config.ts +++ b/packages/allure-js-commons/src/sdk/Config.ts @@ -6,6 +6,7 @@ import { AllureContextProvider } from "./context/index.js"; export interface LinkConfig { type: string; urlTemplate: string; + nameTemplate?: string; } export interface Config { diff --git a/packages/allure-js-commons/src/sdk/ReporterRuntime.ts b/packages/allure-js-commons/src/sdk/ReporterRuntime.ts index 5761d9d3c..6dd3a2055 100644 --- a/packages/allure-js-commons/src/sdk/ReporterRuntime.ts +++ b/packages/allure-js-commons/src/sdk/ReporterRuntime.ts @@ -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, }; }); diff --git a/packages/allure-js-commons/test/sdk/node/ReporterRuntime.spec.ts b/packages/allure-js-commons/test/sdk/node/ReporterRuntime.spec.ts index 331fe6657..1e76fa51e 100644 --- a/packages/allure-js-commons/test/sdk/node/ReporterRuntime.spec.ts +++ b/packages/allure-js-commons/test/sdk/node/ReporterRuntime.spec.ts @@ -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", () => { @@ -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], + ], + }), + ); + }); + }); }); diff --git a/packages/allure-playwright/README.md b/packages/allure-playwright/README.md index 3149e18b5..145fc8c8f 100644 --- a/packages/allure-playwright/README.md +++ b/packages/allure-playwright/README.md @@ -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", diff --git a/packages/allure-vitest/README.md b/packages/allure-vitest/README.md index 5d00ac09b..9f0c744f0 100644 --- a/packages/allure-vitest/README.md +++ b/packages/allure-vitest/README.md @@ -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",