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

Facade types correction #972

Merged
merged 5 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/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
test-results
test/fixtures
2 changes: 1 addition & 1 deletion packages/allure-codeceptjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
## Installation

```bash
npm i -D allure-js-commons allure-codeceptjs
npm i -D allure-codeceptjs
```

## Usage
Expand Down
268 changes: 34 additions & 234 deletions packages/allure-codeceptjs/src/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,242 +1,42 @@
import {
ContentType,
Label,
LabelName,
Link,
LinkType,
ParameterMode,
ParameterOptions,
RuntimeMessage,
Stage,
Status,
TestRuntime,
} from "allure-js-commons/sdk/node";
allureId,
epic,
feature,
issue,
layer,
owner,
parentSuite,
severity,
story,
subSuite,
suite,
tag,
tms,
} from "allure-js-commons";
import { MessageTestRuntime, RuntimeMessage } from "allure-js-commons/sdk/node";
import { AllureCodeceptJsReporter } from "./reporter.js";

export class AllureCodeceptJsTestRuntime implements TestRuntime {
constructor(private readonly reporter: AllureCodeceptJsReporter) {}

async label(name: LabelName | string, value: string) {
await this.sendMessage({
type: "metadata",
data: {
labels: [{ name, value }],
},
});
}

async labels(...labels: Label[]) {
await this.sendMessage({
type: "metadata",
data: {
labels,
},
});
}

async issue(url: string, name: string) {
await this.link(url, LinkType.ISSUE, name);
}

async tms(url: string, name: string) {
await this.link(url, LinkType.TMS, name);
}

async allureId(value: string) {
await this.label(LabelName.ALLURE_ID, value);
}

async epic(name: string) {
await this.label(LabelName.EPIC, name);
}

async feature(name: string) {
await this.label(LabelName.FEATURE, name);
}

async story(name: string) {
await this.label(LabelName.STORY, name);
}

async suite(name: string) {
await this.label(LabelName.SUITE, name);
}

async parentSuite(name: string) {
await this.label(LabelName.PARENT_SUITE, name);
}

async subSuite(name: string) {
await this.label(LabelName.SUB_SUITE, name);
}

async owner(name: string) {
await this.label(LabelName.OWNER, name);
}

async severity(name: string) {
await this.label(LabelName.SEVERITY, name);
}

async layer(name: string) {
await this.label(LabelName.LAYER, name);
}

async tag(name: string) {
await this.label(LabelName.TAG, name);
}

async tags(...tagsList: string[]) {
return this.labels(...tagsList.map((value) => ({ name: LabelName.TAG, value })));
}

async link(url: string, type?: LinkType | string, name?: string) {
await this.sendMessage({
type: "metadata",
data: {
links: [{ type, url, name }],
},
});
}

async links(...links: Link[]) {
await this.sendMessage({
type: "metadata",
data: {
links,
},
});
}

async parameter(name: string, value: string, options?: ParameterOptions) {
await this.sendMessage({
type: "metadata",
data: {
parameters: [
{
name,
value,
...options,
},
],
},
});
}

async description(markdown: string) {
await this.sendMessage({
type: "metadata",
data: {
description: markdown,
},
});
}

async descriptionHtml(html: string) {
await this.sendMessage({
type: "metadata",
data: {
descriptionHtml: html,
},
});
}

async displayName(name: string) {
await this.sendMessage({
type: "metadata",
data: {
displayName: name,
},
});
}

async historyId(value: string) {
await this.sendMessage({
type: "metadata",
data: {
historyId: value,
},
});
}

async testCaseId(value: string) {
await this.sendMessage({
type: "metadata",
data: {
testCaseId: value,
},
});
}

async attachment(name: string, content: Buffer | string, type: string | ContentType) {
await this.sendMessage({
type: "raw_attachment",
data: {
name,
content: Buffer.from(content).toString("base64"),
contentType: type,
encoding: "base64",
},
});
}

async step(name: string, body: () => void | PromiseLike<void>) {
await this.sendMessage({
type: "step_start",
data: {
name,
start: Date.now(),
},
});

try {
await body();

await this.sendMessage({
type: "step_stop",
data: {
status: Status.PASSED,
stage: Stage.FINISHED,
stop: Date.now(),
},
});
} catch (err) {
await this.sendMessage({
type: "step_stop",
data: {
status: Status.FAILED,
stage: Stage.FINISHED,
stop: Date.now(),
statusDetails: {
message: (err as Error).message,
trace: (err as Error).stack,
},
},
});

throw err;
}
}

async stepDisplayName(name: string) {
await this.sendMessage({
type: "step_metadata",
data: { name },
});
}

async stepParameter(name: string, value: string, mode?: ParameterMode) {
await this.sendMessage({
type: "step_metadata",
data: {
parameters: [{ name, value, mode }],
},
});
export class AllureCodeceptJsTestRuntime extends MessageTestRuntime {
constructor(private readonly reporter: AllureCodeceptJsReporter) {
super();
}

async sendMessage(message: RuntimeMessage) {
this.reporter.handleRuntimeMessage(message);

return Promise.resolve();
}
await Promise.resolve();
}

issue = issue;
tms = tms;
allureId = allureId;
epic = epic;
feature = feature;
layer = layer;
owner = owner;
parentSuite = parentSuite;
subSuite = subSuite;
suite = suite;
severity = severity;
story = story;
tag = tag;
}
3 changes: 2 additions & 1 deletion packages/allure-cucumberjs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Before } from "@cucumber/cucumber";
import { setGlobalTestRuntime } from "allure-js-commons/sdk/node";
import { AllureCucumberTestRuntime } from "./runtime.js";
import { AllureCucumberWorld } from "./world.js";

Before(function () {
// TODO: we can implement testplan logic there
Expand All @@ -13,4 +14,4 @@ Before(function () {
);
});

export { AllureCucumberTestRuntime };
export { AllureCucumberTestRuntime, AllureCucumberWorld };
7 changes: 4 additions & 3 deletions packages/allure-cucumberjs/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
getWorstStepResultStatus,
} from "allure-js-commons/sdk/node";
import { AllureCucumberReporterConfig, LabelConfig, LinkConfig } from "./model.js";
import { AllureCucumberTestRuntime } from "./runtime.js";
import { AllureCucumberWorld } from "./world.js";

const { ALLURE_THREAD_NAME } = process.env;

Expand Down Expand Up @@ -73,10 +73,11 @@ export default class AllureCucumberReporter extends Formatter {
this.beforeHooks = options.supportCodeLibrary.beforeTestCaseHookDefinitions;
this.afterHooks = options.supportCodeLibrary.afterTestCaseHookDefinitions;

// set custom Allure World for single thread mode
// set AllureCucumberWorld for single thread mode
if (options.supportCodeLibrary.World === World) {
// @ts-ignore
options.supportCodeLibrary.World = AllureCucumberTestRuntime;
// noinspection JSConstantReassignment
options.supportCodeLibrary.World = AllureCucumberWorld;
}
}

Expand Down
Loading
Loading