-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
1,011 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import * as commons from "allure-js-commons"; | ||
import type { ContentType, ParameterOptions } from "allure-js-commons"; | ||
import { Stage, Status } from "allure-js-commons"; | ||
import type { Category } from "allure-js-commons/sdk"; | ||
import { getStatusFromError, isPromise } from "allure-js-commons/sdk"; | ||
import { serialize } from "allure-js-commons/sdk/reporter"; | ||
import { getLegacyApiRuntime } from "./legacyUtils.js"; | ||
|
||
interface StepInterface { | ||
parameter(name: string, value: string): void; | ||
|
||
name(name: string): void; | ||
} | ||
|
||
interface AttachmentOptions { | ||
contentType: ContentType | string; | ||
fileExtension?: string; | ||
} | ||
|
||
class LegacyAllureApi { | ||
epic = (epic: string) => Promise.resolve(commons.epic(epic)); | ||
feature = (feature: string) => Promise.resolve(commons.feature(feature)); | ||
story = (story: string) => Promise.resolve(commons.story(story)); | ||
suite = (name: string) => Promise.resolve(commons.suite(name)); | ||
parentSuite = (name: string) => Promise.resolve(commons.parentSuite(name)); | ||
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) 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)); | ||
description = (markdown: string) => Promise.resolve(commons.description(markdown)); | ||
descriptionHtml = (html: string) => Promise.resolve(commons.descriptionHtml(html)); | ||
owner = (owner: string) => Promise.resolve(commons.owner(owner)); | ||
severity = (severity: string) => Promise.resolve(commons.severity(severity)); | ||
layer = (layer: string) => Promise.resolve(commons.layer(layer)); | ||
id = (allureId: string) => Promise.resolve(commons.allureId(allureId)); | ||
tag = (tag: string) => Promise.resolve(commons.tag(tag)); | ||
writeEnvironmentInfo = (info: Record<string, string>) => { | ||
getLegacyApiRuntime()?.writer.writeEnvironmentInfo(info); | ||
}; | ||
writeCategoriesDefinitions = (categories: Category[]) => { | ||
getLegacyApiRuntime()?.writer.writeCategoriesDefinitions(categories); | ||
}; | ||
attachment = (name: string, content: Buffer | string, options: ContentType | string | AttachmentOptions) => | ||
Promise.resolve(commons.attachment(name, content, typeof options === "string" ? options : options.contentType)); | ||
testAttachment = (name: string, content: Buffer | string, options: ContentType | string | AttachmentOptions) => { | ||
const runtime = getLegacyApiRuntime(); | ||
const currentTest = runtime?.getCurrentTest(); | ||
if (currentTest) { | ||
runtime?.writeAttachmentForItem( | ||
{ | ||
name, | ||
content: Buffer.from(content).toString("base64"), | ||
contentType: typeof options === "string" ? options : options.contentType, | ||
encoding: "base64", | ||
fileExtension: typeof options === "string" ? undefined : options.fileExtension, | ||
}, | ||
currentTest, | ||
); | ||
} | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
logStep = (name: string, status?: Status) => { | ||
this.step(name, () => { | ||
getLegacyApiRuntime()?.updateStep((s) => (s.status = status)); | ||
}); | ||
}; | ||
// It's sync-first. That's why we can't simply reuse commons.step. | ||
step = <T>(name: string, body: (step: StepInterface) => T): T => { | ||
const runtime = getLegacyApiRuntime(); | ||
runtime?.applyRuntimeMessages([ | ||
{ | ||
type: "step_start", | ||
data: { | ||
name, | ||
start: Date.now(), | ||
}, | ||
}, | ||
]); | ||
try { | ||
const result = body({ | ||
name: this.renameStep, | ||
parameter: this.addStepParameter, | ||
}); | ||
if (isPromise(result)) { | ||
const promise = result as Promise<any>; | ||
return promise | ||
.then((v) => { | ||
this.stopStepSuccess(); | ||
return v; | ||
}) | ||
.catch((e) => { | ||
this.stopStepWithError(e); | ||
throw e; | ||
}) as T; | ||
} | ||
this.stopStepSuccess(); | ||
return result; | ||
} catch (e) { | ||
this.stopStepWithError(e); | ||
throw e; | ||
} | ||
}; | ||
|
||
private renameStep = (name: string) => { | ||
getLegacyApiRuntime()?.applyRuntimeMessages([ | ||
{ | ||
type: "step_metadata", | ||
data: { name }, | ||
}, | ||
]); | ||
}; | ||
|
||
private addStepParameter = (name: string, value: string) => { | ||
getLegacyApiRuntime()?.applyRuntimeMessages([ | ||
{ | ||
type: "step_metadata", | ||
data: { | ||
parameters: [{ name, value }], | ||
}, | ||
}, | ||
]); | ||
}; | ||
|
||
private stopStepSuccess = () => { | ||
getLegacyApiRuntime()?.applyRuntimeMessages([ | ||
{ | ||
type: "step_stop", | ||
data: { | ||
status: Status.PASSED, | ||
stage: Stage.FINISHED, | ||
stop: Date.now(), | ||
}, | ||
}, | ||
]); | ||
}; | ||
|
||
private stopStepWithError = (error: unknown) => { | ||
const { message, stack } = error as Error; | ||
getLegacyApiRuntime()?.applyRuntimeMessages([ | ||
{ | ||
type: "step_stop", | ||
data: { | ||
status: getStatusFromError(error as Error), | ||
stage: Stage.FINISHED, | ||
stop: Date.now(), | ||
statusDetails: { | ||
message, | ||
trace: stack, | ||
}, | ||
}, | ||
}, | ||
]); | ||
}; | ||
} | ||
|
||
export const allure = new LegacyAllureApi(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { ReporterRuntime } from "allure-js-commons/sdk/reporter"; | ||
|
||
const ALLURE_TEST_RUNTIME_KEY = "__allure_mocha_legacy_runtime__"; | ||
|
||
export const getLegacyApiRuntime = () => (globalThis as any)[ALLURE_TEST_RUNTIME_KEY] as ReporterRuntime; | ||
|
||
export const setLegacyApiRuntime = (runtime: ReporterRuntime) => | ||
((globalThis as any)[ALLURE_TEST_RUNTIME_KEY] = runtime); |
23 changes: 23 additions & 0 deletions
23
packages/allure-mocha/test/fixtures/samples/legacy/categories.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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], | ||
}, | ||
]); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/description.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { it } from "mocha"; | ||
import { allure } from "allure-mocha/runtime"; | ||
|
||
it("a test with a description", () => { | ||
allure.description("foo"); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/descriptionHtml.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/allure-mocha/test/fixtures/samples/legacy/environmentInfo.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" }); | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/allure-mocha/test/fixtures/samples/legacy/fixtures/renamed.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", () => {}); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/labels/bdd/epic.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { it } from "mocha"; | ||
import { allure } from "allure-mocha/runtime"; | ||
|
||
it("a test with an epic", () => { | ||
allure.epic("foo"); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/labels/bdd/feature.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { it } from "mocha"; | ||
import { allure } from "allure-mocha/runtime"; | ||
|
||
it("a test with a feature", () => { | ||
allure.feature("foo"); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/labels/bdd/story.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { it } from "mocha"; | ||
import { allure } from "allure-mocha/runtime"; | ||
|
||
it("a test with a story", () => { | ||
allure.story("foo"); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/labels/custom.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/labels/layer.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { it } from "mocha"; | ||
import { allure } from "allure-mocha/runtime"; | ||
|
||
it("a test with a layer", () => { | ||
allure.layer("foo"); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/labels/owner.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { it } from "mocha"; | ||
import { allure } from "allure-mocha/runtime"; | ||
|
||
it("a test with an owner", () => { | ||
allure.owner("foo"); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/blocker.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { it } from "mocha"; | ||
import { allure } from "allure-mocha/runtime"; | ||
|
||
it("a blocker", () => { | ||
allure.severity("blocker"); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/critical.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { it } from "mocha"; | ||
import { allure } from "allure-mocha/runtime"; | ||
|
||
it("a critical test", () => { | ||
allure.severity("critical"); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/minor.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { it } from "mocha"; | ||
import { allure } from "allure-mocha/runtime"; | ||
|
||
it("a minor test", () => { | ||
allure.severity("minor"); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/normal.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { it } from "mocha"; | ||
import { allure } from "allure-mocha/runtime"; | ||
|
||
it("a normal test", () => { | ||
allure.severity("normal"); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/labels/severities/trivial.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { it } from "mocha"; | ||
import { allure } from "allure-mocha/runtime"; | ||
|
||
it("a trivial test", () => { | ||
allure.severity("trivial"); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/labels/suites/parentSuite.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { it } from "mocha"; | ||
import { allure } from "allure-mocha/runtime"; | ||
|
||
it("a test with a parent suite", () => { | ||
allure.parentSuite("foo"); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/labels/suites/subSuite.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { it } from "mocha"; | ||
import { allure } from "allure-mocha/runtime"; | ||
|
||
it("a test with a sub-suite", () => { | ||
allure.subSuite("foo"); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/labels/suites/suite.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { it } from "mocha"; | ||
import { allure } from "allure-mocha/runtime"; | ||
|
||
it("a test with a suite", () => { | ||
allure.suite("foo"); | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/allure-mocha/test/fixtures/samples/legacy/labels/tags.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/links/issue.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/allure-mocha/test/fixtures/samples/legacy/links/namedLink.spec.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
}); |
Oops, something went wrong.