From f5e962635e3b8e27091c1135362ef6935a146930 Mon Sep 17 00:00:00 2001 From: epszaw Date: Fri, 31 May 2024 18:54:27 +0200 Subject: [PATCH] add legacy api fixtures for mocha --- .../src/sdk/reporter/ReporterRuntime.ts | 2 +- packages/allure-mocha/src/legacy.ts | 2 +- .../samples/legacy/categories.spec.mjs | 23 +++ .../samples/legacy/description.spec.mjs | 6 + .../samples/legacy/descriptionHtml.spec.mjs | 6 + .../samples/legacy/environmentInfo.spec.mjs | 8 + .../samples/legacy/fixtures/renamed.spec.mjs | 10 ++ .../samples/legacy/labels/bdd/epic.spec.mjs | 6 + .../legacy/labels/bdd/feature.spec.mjs | 6 + .../samples/legacy/labels/bdd/story.spec.mjs | 6 + .../samples/legacy/labels/custom.spec.mjs | 6 + .../samples/legacy/labels/layer.spec.mjs | 6 + .../samples/legacy/labels/owner.spec.mjs | 6 + .../legacy/labels/severities/blocker.spec.mjs | 6 + .../labels/severities/critical.spec.mjs | 6 + .../legacy/labels/severities/minor.spec.mjs | 6 + .../legacy/labels/severities/normal.spec.mjs | 6 + .../legacy/labels/severities/trivial.spec.mjs | 6 + .../legacy/labels/suites/parentSuite.spec.mjs | 6 + .../legacy/labels/suites/subSuite.spec.mjs | 6 + .../legacy/labels/suites/suite.spec.mjs | 6 + .../samples/legacy/labels/tags.spec.mjs | 7 + .../samples/legacy/links/issue.spec.mjs | 6 + .../samples/legacy/links/namedLink.spec.mjs | 6 + .../samples/legacy/links/tms.spec.mjs | 6 + .../samples/legacy/links/urlOnlyLink.spec.mjs | 6 + .../samples/legacy/links/urlTypeLink.spec.mjs | 6 + .../testWithExcludedParameter.spec.mjs | 8 + .../testWithHiddenParameter.spec.mjs | 6 + .../testWithMaskedParameter.spec.mjs | 6 + .../parameters/testWithParameter.spec.mjs | 8 + .../legacy/steps/brokenLogStep.spec.mjs | 10 ++ .../samples/legacy/steps/brokenStep.spec.mjs | 8 + .../legacy/steps/failedLogStep.spec.js | 10 ++ .../samples/legacy/steps/failedStep.spec.mjs | 9 ++ .../samples/legacy/steps/lambdaStep.spec.mjs | 6 + .../samples/legacy/steps/logStep.spec.mjs | 6 + .../samples/legacy/steps/renamedStep.spec.mjs | 10 ++ .../legacy/steps/skippedLogStep.spec.mjs | 10 ++ .../legacy/steps/stepReturnsPromise.spec.mjs | 11 ++ .../legacy/steps/stepReturnsValue.spec.mjs | 11 ++ .../legacy/steps/stepWithAttachment.spec.mjs | 8 + .../legacy/steps/stepWithParameter.spec.mjs | 10 ++ .../legacy/steps/twoNestedSteps.spec.mjs | 8 + .../legacy/steps/twoStepsInRow.spec.mjs | 7 + .../samples/legacy/testAttachment.spec.mjs | 6 + .../legacy/testAttachmentFromStep.spec.mjs | 10 ++ .../api/runtime/legacy/attachments.test.ts | 21 +++ .../test/spec/api/runtime/legacy/bdd.test.ts | 57 ++++++++ .../spec/api/runtime/legacy/labels.test.ts | 24 +++ .../spec/api/runtime/legacy/links.test.ts | 71 +++++++++ .../spec/api/runtime/legacy/metadata.test.ts | 138 ++++++++++++++++++ .../api/runtime/legacy/parameters.test.ts | 107 ++++++++++++++ .../spec/api/runtime/legacy/suites.test.ts | 51 +++++++ .../test/spec/api/runtime/legacy/tags.test.ts | 24 +++ 55 files changed, 837 insertions(+), 2 deletions(-) create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/categories.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/description.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/descriptionHtml.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/environmentInfo.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/fixtures/renamed.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/labels/bdd/epic.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/labels/bdd/feature.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/labels/bdd/story.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/labels/custom.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/labels/layer.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/labels/owner.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/blocker.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/critical.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/minor.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/normal.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/trivial.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/labels/suites/parentSuite.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/labels/suites/subSuite.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/labels/suites/suite.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/labels/tags.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/links/issue.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/links/namedLink.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/links/tms.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/links/urlOnlyLink.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/links/urlTypeLink.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/parameters/testWithExcludedParameter.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/parameters/testWithHiddenParameter.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/parameters/testWithMaskedParameter.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/parameters/testWithParameter.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/steps/brokenLogStep.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/steps/brokenStep.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/steps/failedLogStep.spec.js create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/steps/failedStep.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/steps/lambdaStep.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/steps/logStep.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/steps/renamedStep.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/steps/skippedLogStep.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/steps/stepReturnsPromise.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/steps/stepReturnsValue.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/steps/stepWithAttachment.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/steps/stepWithParameter.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/steps/twoNestedSteps.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/steps/twoStepsInRow.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/testAttachment.spec.mjs create mode 100644 packages/allure-mocha/test/fixtures/samples/legacy/testAttachmentFromStep.spec.mjs create mode 100644 packages/allure-mocha/test/spec/api/runtime/legacy/attachments.test.ts create mode 100644 packages/allure-mocha/test/spec/api/runtime/legacy/bdd.test.ts create mode 100644 packages/allure-mocha/test/spec/api/runtime/legacy/labels.test.ts create mode 100644 packages/allure-mocha/test/spec/api/runtime/legacy/links.test.ts create mode 100644 packages/allure-mocha/test/spec/api/runtime/legacy/metadata.test.ts create mode 100644 packages/allure-mocha/test/spec/api/runtime/legacy/parameters.test.ts create mode 100644 packages/allure-mocha/test/spec/api/runtime/legacy/suites.test.ts create mode 100644 packages/allure-mocha/test/spec/api/runtime/legacy/tags.test.ts diff --git a/packages/allure-js-commons/src/sdk/reporter/ReporterRuntime.ts b/packages/allure-js-commons/src/sdk/reporter/ReporterRuntime.ts index 84c13be33..4ad49d353 100644 --- a/packages/allure-js-commons/src/sdk/reporter/ReporterRuntime.ts +++ b/packages/allure-js-commons/src/sdk/reporter/ReporterRuntime.ts @@ -874,7 +874,7 @@ export class ReporterRuntime { this.writeAttachmentForItem(message.data, step ?? root); }; - private writeAttachmentForItem = (attachment: RawAttachment, item: StepResult | TestResult | FixtureResult) => { + writeAttachmentForItem = (attachment: RawAttachment, item: StepResult | TestResult | FixtureResult) => { const attachmentFilename = this.buildAttachmentFileName(attachment); this.writer.writeAttachment( diff --git a/packages/allure-mocha/src/legacy.ts b/packages/allure-mocha/src/legacy.ts index d46d98c89..082ac0636 100644 --- a/packages/allure-mocha/src/legacy.ts +++ b/packages/allure-mocha/src/legacy.ts @@ -26,7 +26,7 @@ class LegacyAllureApi { subSuite = (name: string) => Promise.resolve(commons.subSuite(name)); label = (name: string, value: string) => Promise.resolve(commons.label(name, value)); parameter = (name: string, value: any, options?: ParameterOptions) => - Promise.resolve(commons.parameter(name, serialize(value), options)); + Promise.resolve(commons.parameter(name, serialize(value) as string, options)); link = (url: string, name?: string, type?: string) => Promise.resolve(commons.link(url, type, name)); issue = (name: string, url: string) => Promise.resolve(commons.issue(url, name)); tms = (name: string, url: string) => Promise.resolve(commons.tms(url, name)); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/categories.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/categories.spec.mjs new file mode 100644 index 000000000..f39b6053d --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/categories.spec.mjs @@ -0,0 +1,23 @@ +// cjs: const { it } = require("mocha"); +// cjs: const { allure } = require("allure-mocha/runtime"); +// cjs: const { Status } = require("allure-js-commons"); +// esm: import { it } from "mocha"; +// esm: import { allure } from "allure-mocha/runtime"; +// esm: import { Status } from "allure-js-commons"; + +it("a test run with categories", () => { + allure.writeCategoriesDefinitions([ + { + name: "foo", + description: "bar", + messageRegex: "broken", + matchedStatuses: [Status.BROKEN], + }, + { + name: "baz", + description: "qux", + messageRegex: "failure", + matchedStatuses: [Status.FAILED], + }, + ]); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/description.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/description.spec.mjs new file mode 100644 index 000000000..5ffec3555 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/description.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with a description", () => { + allure.description("foo"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/descriptionHtml.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/descriptionHtml.spec.mjs new file mode 100644 index 000000000..71156c7b7 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/descriptionHtml.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with a description in HTML", () => { + allure.descriptionHtml("foo"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/environmentInfo.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/environmentInfo.spec.mjs new file mode 100644 index 000000000..e5ecd6b00 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/environmentInfo.spec.mjs @@ -0,0 +1,8 @@ +// cjs: const { it } = require("mocha"); +// cjs: const { allure } = require("allure-mocha/runtime"); +// esm: import { it } from "mocha"; +// esm: import { allure } from "allure-mocha/runtime"; + +it("a test run with env info", () => { + allure.writeEnvironmentInfo({ foo: "bar", baz: "qux" }); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/fixtures/renamed.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/fixtures/renamed.spec.mjs new file mode 100644 index 000000000..77568de38 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/fixtures/renamed.spec.mjs @@ -0,0 +1,10 @@ +import { beforeEach, describe, it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +describe("a suite with before", () => { + beforeEach("an initial name", () => { + allure.displayName("a new name"); + }); + + it("a test affected by a renamed fixture", () => {}); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/labels/bdd/epic.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/labels/bdd/epic.spec.mjs new file mode 100644 index 000000000..e11d0d308 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/labels/bdd/epic.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with an epic", () => { + allure.epic("foo"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/labels/bdd/feature.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/labels/bdd/feature.spec.mjs new file mode 100644 index 000000000..af2d850c8 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/labels/bdd/feature.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with a feature", () => { + allure.feature("foo"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/labels/bdd/story.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/labels/bdd/story.spec.mjs new file mode 100644 index 000000000..d3c543bdf --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/labels/bdd/story.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with a story", () => { + allure.story("foo"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/labels/custom.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/labels/custom.spec.mjs new file mode 100644 index 000000000..7dd244ac5 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/labels/custom.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with a custom label", () => { + allure.label("foo", "bar"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/labels/layer.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/labels/layer.spec.mjs new file mode 100644 index 000000000..3426d6ad4 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/labels/layer.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with a layer", () => { + allure.layer("foo"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/labels/owner.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/labels/owner.spec.mjs new file mode 100644 index 000000000..3edf3d273 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/labels/owner.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with an owner", () => { + allure.owner("foo"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/blocker.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/blocker.spec.mjs new file mode 100644 index 000000000..4b988722a --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/blocker.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a blocker", () => { + allure.severity("blocker"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/critical.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/critical.spec.mjs new file mode 100644 index 000000000..2b178a941 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/critical.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a critical test", () => { + allure.severity("critical"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/minor.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/minor.spec.mjs new file mode 100644 index 000000000..139bc6054 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/minor.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a minor test", () => { + allure.severity("minor"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/normal.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/normal.spec.mjs new file mode 100644 index 000000000..1c731b500 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/normal.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a normal test", () => { + allure.severity("normal"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/trivial.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/trivial.spec.mjs new file mode 100644 index 000000000..a5a057c3f --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/trivial.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a trivial test", () => { + allure.severity("trivial"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/labels/suites/parentSuite.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/labels/suites/parentSuite.spec.mjs new file mode 100644 index 000000000..1122fa819 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/labels/suites/parentSuite.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with a parent suite", () => { + allure.parentSuite("foo"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/labels/suites/subSuite.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/labels/suites/subSuite.spec.mjs new file mode 100644 index 000000000..0c288e8f6 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/labels/suites/subSuite.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with a sub-suite", () => { + allure.subSuite("foo"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/labels/suites/suite.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/labels/suites/suite.spec.mjs new file mode 100644 index 000000000..1c1221a40 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/labels/suites/suite.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with a suite", () => { + allure.suite("foo"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/labels/tags.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/labels/tags.spec.mjs new file mode 100644 index 000000000..e3b9d056d --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/labels/tags.spec.mjs @@ -0,0 +1,7 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with tags", () => { + allure.tag("foo"); + allure.tag("bar"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/links/issue.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/links/issue.spec.mjs new file mode 100644 index 000000000..79aed6f95 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/links/issue.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with an issue link", () => { + allure.issue("baz", "https://foo.bar"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/links/namedLink.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/links/namedLink.spec.mjs new file mode 100644 index 000000000..44a8a1410 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/links/namedLink.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with a named link", () => { + allure.link("https://foo.bar", "baz"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/links/tms.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/links/tms.spec.mjs new file mode 100644 index 000000000..0d79d0566 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/links/tms.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with a tms link", () => { + allure.tms("baz", "https://foo.bar"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/links/urlOnlyLink.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/links/urlOnlyLink.spec.mjs new file mode 100644 index 000000000..35321a5a7 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/links/urlOnlyLink.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with a url only link", () => { + allure.link("https://foo.bar"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/links/urlTypeLink.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/links/urlTypeLink.spec.mjs new file mode 100644 index 000000000..ddf1a9e73 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/links/urlTypeLink.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with a link of a custom type", () => { + allure.link("https://foo.bar", "baz", "qux"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/parameters/testWithExcludedParameter.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/parameters/testWithExcludedParameter.spec.mjs new file mode 100644 index 000000000..404a0b83d --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/parameters/testWithExcludedParameter.spec.mjs @@ -0,0 +1,8 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +["bar", "baz"].forEach((v) => { + it("a test with an excluded parameter", () => { + allure.parameter("foo", v, { excluded: true }); + }); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/parameters/testWithHiddenParameter.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/parameters/testWithHiddenParameter.spec.mjs new file mode 100644 index 000000000..71acbc2bd --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/parameters/testWithHiddenParameter.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with a hidden parameter", () => { + allure.parameter("foo", "bar", { mode: "hidden" }); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/parameters/testWithMaskedParameter.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/parameters/testWithMaskedParameter.spec.mjs new file mode 100644 index 000000000..3b06997b1 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/parameters/testWithMaskedParameter.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a test with a masked parameter", () => { + allure.parameter("foo", "bar", { mode: "masked" }); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/parameters/testWithParameter.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/parameters/testWithParameter.spec.mjs new file mode 100644 index 000000000..77d877be7 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/parameters/testWithParameter.spec.mjs @@ -0,0 +1,8 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +["bar", "baz", { key: 10 }].forEach((v) => { + it("a test with a parameter", () => { + allure.parameter("foo", v); + }); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/steps/brokenLogStep.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/steps/brokenLogStep.spec.mjs new file mode 100644 index 000000000..0290b3e63 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/steps/brokenLogStep.spec.mjs @@ -0,0 +1,10 @@ +// cjs: const { it } = require("mocha"); +// cjs: const { allure } = require("allure-mocha/runtime"); +// cjs: const { Status } = require("allure-js-commons"); +// esm: import { it } from "mocha"; +// esm: import { allure } from "allure-mocha/runtime"; +// esm: import { Status } from "allure-js-commons"; + +it("a broken log step", () => { + allure.logStep("foo", Status.BROKEN); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/steps/brokenStep.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/steps/brokenStep.spec.mjs new file mode 100644 index 000000000..9bdff6041 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/steps/brokenStep.spec.mjs @@ -0,0 +1,8 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a broken step", () => { + allure.step("foo", () => { + throw new Error("foo"); + }); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/steps/failedLogStep.spec.js b/packages/allure-mocha/test/fixtures/samples/legacy/steps/failedLogStep.spec.js new file mode 100644 index 000000000..fc8980137 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/steps/failedLogStep.spec.js @@ -0,0 +1,10 @@ +// cjs: const { it } = require("mocha"); +// cjs: const { allure } = require("allure-mocha/runtime"); +// cjs: const { Status } = require("allure-js-commons"); +// esm: import { it } from "mocha"; +// esm: import { allure } from "allure-mocha/runtime"; +// esm: import { Status } from "allure-js-commons"; + +it("a failed log step", () => { + allure.logStep("foo", Status.FAILED); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/steps/failedStep.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/steps/failedStep.spec.mjs new file mode 100644 index 000000000..039a55e65 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/steps/failedStep.spec.mjs @@ -0,0 +1,9 @@ +import { expect } from "chai"; +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a failed step", () => { + allure.step("foo", () => { + expect("foo").eq("bar", "baz"); + }); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/steps/lambdaStep.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/steps/lambdaStep.spec.mjs new file mode 100644 index 000000000..db8009636 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/steps/lambdaStep.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a lambda step", () => { + allure.step("foo", () => {}); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/steps/logStep.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/steps/logStep.spec.mjs new file mode 100644 index 000000000..dd82a3785 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/steps/logStep.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a log step", () => { + allure.step("foo"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/steps/renamedStep.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/steps/renamedStep.spec.mjs new file mode 100644 index 000000000..c65eb3660 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/steps/renamedStep.spec.mjs @@ -0,0 +1,10 @@ +// cjs: const { it } = require("mocha"); +// cjs: const { allure } = require("allure-mocha/runtime"); +// esm: import { it } from "mocha"; +// esm: import { allure } from "allure-mocha/runtime"; + +it("a test with a renamed step", () => { + allure.step("foo", (ctx) => { + ctx.name("bar"); + }); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/steps/skippedLogStep.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/steps/skippedLogStep.spec.mjs new file mode 100644 index 000000000..0954cdd88 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/steps/skippedLogStep.spec.mjs @@ -0,0 +1,10 @@ +// cjs: const { it } = require("mocha"); +// cjs: const { allure } = require("allure-mocha/runtime"); +// cjs: const { Status } = require("allure-js-commons"); +// esm: import { it } from "mocha"; +// esm: import { allure } from "allure-mocha/runtime"; +// esm: import { Status } from "allure-js-commons"; + +it("a skipped log step", () => { + allure.logStep("foo", Status.SKIPPED); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/steps/stepReturnsPromise.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/steps/stepReturnsPromise.spec.mjs new file mode 100644 index 000000000..5cb1439ec --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/steps/stepReturnsPromise.spec.mjs @@ -0,0 +1,11 @@ +// cjs: const { it } = require("mocha"); +// cjs: const { allure } = require("allure-mocha/runtime"); +// esm: import { it } from "mocha"; +// esm: import { allure } from "allure-mocha/runtime"; + +it("a test with a step that returns a value promise", async () => { + const result = await allure.step("foo", async () => await new Promise((r) => setTimeout(() => r("bar"), 50))); + if (result !== "bar") { + throw new Error(`Unexpected value ${result}`); + } +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/steps/stepReturnsValue.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/steps/stepReturnsValue.spec.mjs new file mode 100644 index 000000000..bb98f4781 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/steps/stepReturnsValue.spec.mjs @@ -0,0 +1,11 @@ +// cjs: const { it } = require("mocha"); +// cjs: const { allure } = require("allure-mocha/runtime"); +// esm: import { it } from "mocha"; +// esm: import { allure } from "allure-mocha/runtime"; + +it("a test with a step that returns a value", () => { + const result = allure.step("foo", () => "bar"); + if (result !== "bar") { + throw new Error(`Unexpected value ${result}`); + } +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/steps/stepWithAttachment.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/steps/stepWithAttachment.spec.mjs new file mode 100644 index 000000000..e78a4ce50 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/steps/stepWithAttachment.spec.mjs @@ -0,0 +1,8 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("a step with an attachment", () => { + allure.step("step", () => { + allure.attachment("foo.txt", Buffer.from("bar"), "text/plain"); + }); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/steps/stepWithParameter.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/steps/stepWithParameter.spec.mjs new file mode 100644 index 000000000..398a714b1 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/steps/stepWithParameter.spec.mjs @@ -0,0 +1,10 @@ +// cjs: const { it } = require("mocha"); +// cjs: const { allure } = require("allure-mocha/runtime"); +// esm: import { it } from "mocha"; +// esm: import { allure } from "allure-mocha/runtime"; + +it("a step with a parameter", () => { + allure.step("foo", (ctx) => { + ctx.parameter("bar", "baz"); + }); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/steps/twoNestedSteps.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/steps/twoNestedSteps.spec.mjs new file mode 100644 index 000000000..3855e68f3 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/steps/twoNestedSteps.spec.mjs @@ -0,0 +1,8 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("two nested steps", () => { + allure.step("foo", () => { + allure.step("bar", () => {}); + }); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/steps/twoStepsInRow.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/steps/twoStepsInRow.spec.mjs new file mode 100644 index 000000000..a44692b60 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/steps/twoStepsInRow.spec.mjs @@ -0,0 +1,7 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("two steps in a row", () => { + allure.step("foo", () => {}); + allure.step("bar", () => {}); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/testAttachment.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/testAttachment.spec.mjs new file mode 100644 index 000000000..f1f13d36f --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/testAttachment.spec.mjs @@ -0,0 +1,6 @@ +import { it } from "mocha"; +import { allure } from "allure-mocha/runtime"; + +it("test attachment", () => { + allure.attachment("foo.txt", Buffer.from("bar"), "text/plain"); +}); diff --git a/packages/allure-mocha/test/fixtures/samples/legacy/testAttachmentFromStep.spec.mjs b/packages/allure-mocha/test/fixtures/samples/legacy/testAttachmentFromStep.spec.mjs new file mode 100644 index 000000000..cd7e803b3 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/samples/legacy/testAttachmentFromStep.spec.mjs @@ -0,0 +1,10 @@ +// cjs: const { it } = require("mocha"); +// cjs: const { allure } = require("allure-mocha/runtime"); +// esm: import { it } from "mocha"; +// esm: import { allure } from "allure-mocha/runtime"; + +it("testAttachment from a step", () => { + allure.step("foo", () => { + allure.testAttachment("bar.txt", Buffer.from("baz"), "text/plain"); + }); +}); diff --git a/packages/allure-mocha/test/spec/api/runtime/legacy/attachments.test.ts b/packages/allure-mocha/test/spec/api/runtime/legacy/attachments.test.ts new file mode 100644 index 000000000..30a954bc5 --- /dev/null +++ b/packages/allure-mocha/test/spec/api/runtime/legacy/attachments.test.ts @@ -0,0 +1,21 @@ +import { beforeAll, describe, expect, it } from "vitest"; +import type { AllureResults } from "allure-js-commons/sdk"; +import { runMochaInlineTest } from "../../../../utils"; + +describe("legacy test attachments API", () => { + let results: AllureResults; + beforeAll(async () => { + results = await runMochaInlineTest(["legacy", "testAttachment"]); + }); + + it("test may contain an attachment", () => { + const testAttachments = results.tests.find((t) => t.name === "test attachment")?.attachments; + + expect(testAttachments).toHaveLength(1); + expect(testAttachments).toContainEqual(expect.objectContaining({ name: "foo.txt", type: "text/plain" })); + const source = testAttachments![0].source; + const contentInBase64 = results.attachments[source] as string; + const decodedContent = Buffer.from(contentInBase64, "base64").toString("utf8"); + expect(decodedContent).toEqual("bar"); + }); +}); diff --git a/packages/allure-mocha/test/spec/api/runtime/legacy/bdd.test.ts b/packages/allure-mocha/test/spec/api/runtime/legacy/bdd.test.ts new file mode 100644 index 000000000..126a9e772 --- /dev/null +++ b/packages/allure-mocha/test/spec/api/runtime/legacy/bdd.test.ts @@ -0,0 +1,57 @@ +import { beforeAll, describe, expect, it } from "vitest"; +import type { TestResult } from "allure-js-commons"; +import { LabelName } from "allure-js-commons"; +import { runMochaInlineTest } from "../../../../utils"; + +describe("legacy bdd labels API", () => { + let tests: TestResult[] = []; + beforeAll(async () => { + ({ tests } = await runMochaInlineTest( + ["legacy", "labels", "bdd", "epic"], + ["legacy", "labels", "bdd", "feature"], + ["legacy", "labels", "bdd", "story"], + )); + }); + + it("an epic can be added at runtime", () => { + expect(tests).toContainEqual( + expect.objectContaining({ + name: "a test with an epic", + labels: expect.arrayContaining([ + { + name: LabelName.EPIC, + value: "foo", + }, + ]), + }), + ); + }); + + it("a feature can be added at runtime", () => { + expect(tests).toContainEqual( + expect.objectContaining({ + name: "a test with a feature", + labels: expect.arrayContaining([ + { + name: LabelName.FEATURE, + value: "foo", + }, + ]), + }), + ); + }); + + it("a story can be added at runtime", () => { + expect(tests).toContainEqual( + expect.objectContaining({ + name: "a test with a story", + labels: expect.arrayContaining([ + { + name: LabelName.STORY, + value: "foo", + }, + ]), + }), + ); + }); +}); diff --git a/packages/allure-mocha/test/spec/api/runtime/legacy/labels.test.ts b/packages/allure-mocha/test/spec/api/runtime/legacy/labels.test.ts new file mode 100644 index 000000000..16c4a92a1 --- /dev/null +++ b/packages/allure-mocha/test/spec/api/runtime/legacy/labels.test.ts @@ -0,0 +1,24 @@ +import { beforeAll, describe, expect, it } from "vitest"; +import type { TestResult } from "allure-js-commons"; +import { runMochaInlineTest } from "../../../../utils"; + +describe("legacy label runtime API", () => { + let tests: TestResult[]; + beforeAll(async () => { + ({ tests } = await runMochaInlineTest(["legacy", "labels", "custom"])); + }); + + it("may add a custom label to a test", () => { + expect(tests).toContainEqual( + expect.objectContaining({ + name: "a test with a custom label", + labels: expect.arrayContaining([ + { + name: "foo", + value: "bar", + }, + ]), + }), + ); + }); +}); diff --git a/packages/allure-mocha/test/spec/api/runtime/legacy/links.test.ts b/packages/allure-mocha/test/spec/api/runtime/legacy/links.test.ts new file mode 100644 index 000000000..f00c6d973 --- /dev/null +++ b/packages/allure-mocha/test/spec/api/runtime/legacy/links.test.ts @@ -0,0 +1,71 @@ +import { beforeAll, describe, expect, it } from "vitest"; +import type { TestResult } from "allure-js-commons"; +import { runMochaInlineTest } from "../../../../utils"; + +describe("legacy link API", () => { + const testMap = new Map(); + beforeAll(async () => { + const { tests } = await runMochaInlineTest( + ["legacy", "links", "urlOnlyLink"], + ["legacy", "links", "urlTypeLink"], + ["legacy", "links", "namedLink"], + ["legacy", "links", "issue"], + ["legacy", "links", "tms"], + ); + for (const test of tests) { + testMap.set(test.name as string, test as TestResult); + } + }); + + it("should have test with a url only link", () => { + const links = testMap.get("a test with a url only link")!.links; + expect(links).toEqual([ + { + url: "https://foo.bar", + }, + ]); + }); + + it("should have test with a link of a custom type", () => { + const links = testMap.get("a test with a link of a custom type")!.links; + expect(links).toEqual([ + { + url: "https://foo.bar", + name: "baz", + type: "qux", + }, + ]); + }); + + it("should have test with a named link", () => { + const links = testMap.get("a test with a named link")!.links; + expect(links).toEqual([ + { + url: "https://foo.bar", + name: "baz", + }, + ]); + }); + + it("should have test with an issue", () => { + const links = testMap.get("a test with an issue link")!.links; + expect(links).toEqual([ + { + url: "https://foo.bar", + type: "issue", + name: "baz", + }, + ]); + }); + + it("should have test with a tms", () => { + const links = testMap.get("a test with a tms link")!.links; + expect(links).toEqual([ + { + url: "https://foo.bar", + type: "tms", + name: "baz", + }, + ]); + }); +}); diff --git a/packages/allure-mocha/test/spec/api/runtime/legacy/metadata.test.ts b/packages/allure-mocha/test/spec/api/runtime/legacy/metadata.test.ts new file mode 100644 index 000000000..f975ee9cb --- /dev/null +++ b/packages/allure-mocha/test/spec/api/runtime/legacy/metadata.test.ts @@ -0,0 +1,138 @@ +import { beforeAll, describe, expect, it } from "vitest"; +import type { TestResult } from "allure-js-commons"; +import { runMochaInlineTest } from "../../../../utils"; + +describe("legacy test metadata api", () => { + let tests: TestResult[]; + beforeAll(async () => { + ({ tests } = await runMochaInlineTest( + ["legacy", "description"], + ["legacy", "descriptionHtml"], + ["legacy", "labels", "owner"], + ["legacy", "labels", "layer"], + ["legacy", "labels", "severities", "blocker"], + ["legacy", "labels", "severities", "critical"], + ["legacy", "labels", "severities", "minor"], + ["legacy", "labels", "severities", "normal"], + ["legacy", "labels", "severities", "trivial"], + )); + }); + + it("can set a test's description", () => { + expect(tests).toContainEqual( + expect.objectContaining({ + name: "a test with a description", + description: "foo", + }), + ); + }); + + it("can set a test's descriptionHtml", () => { + expect(tests).toContainEqual( + expect.objectContaining({ + name: "a test with a description in HTML", + descriptionHtml: "foo", + }), + ); + }); + + it("can set a test's owner", () => { + expect(tests).toContainEqual( + expect.objectContaining({ + name: "a test with an owner", + labels: expect.arrayContaining([ + { + name: "owner", + value: "foo", + }, + ]), + }), + ); + }); + + describe("for severity", () => { + it("can make test a blocker", () => { + expect(tests).toContainEqual( + expect.objectContaining({ + name: "a blocker", + labels: expect.arrayContaining([ + { + name: "severity", + value: "blocker", + }, + ]), + }), + ); + }); + + it("can make test critical", () => { + expect(tests).toContainEqual( + expect.objectContaining({ + name: "a critical test", + labels: expect.arrayContaining([ + { + name: "severity", + value: "critical", + }, + ]), + }), + ); + }); + + it("can make test normal", () => { + expect(tests).toContainEqual( + expect.objectContaining({ + name: "a normal test", + labels: expect.arrayContaining([ + { + name: "severity", + value: "normal", + }, + ]), + }), + ); + }); + + it("can make test minor", () => { + expect(tests).toContainEqual( + expect.objectContaining({ + name: "a minor test", + labels: expect.arrayContaining([ + { + name: "severity", + value: "minor", + }, + ]), + }), + ); + }); + + it("can make test trivial", () => { + expect(tests).toContainEqual( + expect.objectContaining({ + name: "a trivial test", + labels: expect.arrayContaining([ + { + name: "severity", + value: "trivial", + }, + ]), + }), + ); + }); + }); + + it("can set a test's layer", () => { + expect(tests).toContainEqual( + expect.objectContaining({ + name: "a test with a layer", + labels: expect.arrayContaining([ + { + name: "layer", + value: "foo", + }, + ]), + }), + ); + }); +}); diff --git a/packages/allure-mocha/test/spec/api/runtime/legacy/parameters.test.ts b/packages/allure-mocha/test/spec/api/runtime/legacy/parameters.test.ts new file mode 100644 index 000000000..32978a067 --- /dev/null +++ b/packages/allure-mocha/test/spec/api/runtime/legacy/parameters.test.ts @@ -0,0 +1,107 @@ +import { beforeAll, describe, expect, it } from "vitest"; +import type { TestResult } from "allure-js-commons"; +import { runMochaInlineTest } from "../../../../utils"; + +describe("legacy runtime parameters API", () => { + const testMap = new Map(); + beforeAll(async () => { + const results = await runMochaInlineTest( + ["legacy", "parameters", "testWithParameter"], + ["legacy", "parameters", "testWithMaskedParameter"], + ["legacy", "parameters", "testWithHiddenParameter"], + ["legacy", "parameters", "testWithExcludedParameter"], + ); + for (const testResult of results.tests) { + if (testMap.has(testResult.name as string)) { + testMap.get(testResult.name as string)!.push(testResult as TestResult); + } else { + testMap.set(testResult.name as string, [testResult as TestResult]); + } + } + }); + + it("can be added to test", () => { + const tests = testMap.get("a test with a parameter"); + expect(tests).toHaveLength(3); + expect(tests).toContainEqual( + expect.objectContaining({ + parameters: [ + { + name: "foo", + value: "bar", + }, + ], + }), + ); + expect(tests).toContainEqual( + expect.objectContaining({ + parameters: [ + { + name: "foo", + value: "baz", + }, + ], + }), + ); + expect(tests).toContainEqual( + expect.objectContaining({ + parameters: [ + { + name: "foo", + // eslint-disable-next-line + value: '{"key":10}', + }, + ], + }), + ); + }); + + it("can be masked", () => { + const tests = testMap.get("a test with a masked parameter"); + expect(tests).toHaveLength(1); + expect(tests![0].parameters).toEqual([ + { + name: "foo", + value: "bar", + mode: "masked", + }, + ]); + }); + + it("can be hidden", () => { + const tests = testMap.get("a test with a hidden parameter"); + expect(tests).toHaveLength(1); + expect(tests![0].parameters).toEqual([ + { + name: "foo", + value: "bar", + mode: "hidden", + }, + ]); + }); + + it("can be excluded", () => { + const tests = testMap.get("a test with an excluded parameter"); + expect(tests).toEqual([ + expect.objectContaining({ + parameters: [ + { + name: "foo", + value: "bar", + excluded: true, + }, + ], + }), + expect.objectContaining({ + parameters: [ + { + name: "foo", + value: "baz", + excluded: true, + }, + ], + }), + ]); + expect(tests![0].historyId).toEqual(tests![1].historyId); + }); +}); diff --git a/packages/allure-mocha/test/spec/api/runtime/legacy/suites.test.ts b/packages/allure-mocha/test/spec/api/runtime/legacy/suites.test.ts new file mode 100644 index 000000000..95be99287 --- /dev/null +++ b/packages/allure-mocha/test/spec/api/runtime/legacy/suites.test.ts @@ -0,0 +1,51 @@ +import { beforeAll, describe, expect, it } from "vitest"; +import type { TestResult } from "allure-js-commons"; +import { runMochaInlineTest } from "../../../../utils"; + +describe("legacy suites API", () => { + const testMap = new Map(); + + beforeAll(async () => { + const { tests } = await runMochaInlineTest( + ["legacy", "labels", "suites", "parentSuite"], + ["legacy", "labels", "suites", "suite"], + ["legacy", "labels", "suites", "subSuite"], + ); + for (const testResult of tests) { + testMap.set(testResult.name as string, testResult as TestResult); + } + }); + + it("adds a parent suite label", () => { + expect(testMap.get("a test with a parent suite")).toMatchObject({ + labels: expect.arrayContaining([ + { + name: "parentSuite", + value: "foo", + }, + ]), + }); + }); + + it("adds a suite label", () => { + expect(testMap.get("a test with a suite")).toMatchObject({ + labels: expect.arrayContaining([ + { + name: "suite", + value: "foo", + }, + ]), + }); + }); + + it("adds a subSuite label", () => { + expect(testMap.get("a test with a sub-suite")).toMatchObject({ + labels: expect.arrayContaining([ + { + name: "subSuite", + value: "foo", + }, + ]), + }); + }); +}); diff --git a/packages/allure-mocha/test/spec/api/runtime/legacy/tags.test.ts b/packages/allure-mocha/test/spec/api/runtime/legacy/tags.test.ts new file mode 100644 index 000000000..3ee247c80 --- /dev/null +++ b/packages/allure-mocha/test/spec/api/runtime/legacy/tags.test.ts @@ -0,0 +1,24 @@ +import { expect, it } from "vitest"; +import { LabelName } from "allure-js-commons"; +import { runMochaInlineTest } from "../../../../utils"; + +it("tags can be added via legacy API", async () => { + const { tests } = await runMochaInlineTest(["legacy", "labels", "tags"]); + + expect(tests).toHaveLength(1); + expect(tests).toContainEqual( + expect.objectContaining({ + name: "a test with tags", + labels: expect.arrayContaining([ + { + name: LabelName.TAG, + value: "foo", + }, + { + name: LabelName.TAG, + value: "bar", + }, + ]), + }), + ); +});