allure-cucumberjs 2.15.0 → 3.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,70 +12,29 @@
12
12
 
13
13
  ---
14
14
 
15
- ## Basic usage
15
+ ## Installation
16
16
 
17
17
  Install the required packages using your favorite package manager:
18
18
 
19
19
  ```shell
20
- # using npm
21
- npm install --save-dev allure-js-commons allure-cucumberjs
22
- # using yarn
23
- yarn add -D allure-js-commons allure-cucumberjs
24
- # using pnpm
25
- pnpm add -D allure-js-commons allure-cucumberjs
20
+ npm add -D allure-cucumberjs
26
21
  ```
27
22
 
28
- Create the reporter file:
23
+ Create `reporter.js` with following content:
29
24
 
30
25
  ```js
31
26
  // reporter.js
32
- import { AllureRuntime } from "allure-js-commons";
33
- import { CucumberJSAllureFormatter } from "allure-cucumberjs";
34
-
35
- export default class extends CucumberJSAllureFormatter {
36
- constructor(options) {
37
- super(options, new AllureRuntime({ resultsDir: "./allure-results" }), {
38
- labels: [
39
- {
40
- pattern: [/@feature:(.*)/],
41
- name: "epic",
42
- },
43
- {
44
- pattern: [/@severity:(.*)/],
45
- name: "severity",
46
- },
47
- ],
48
- links: [
49
- {
50
- pattern: [/@issue=(.*)/],
51
- type: "issue",
52
- urlTemplate: "http://localhost:8080/issue/%s",
53
- },
54
- {
55
- pattern: [/@tms=(.*)/],
56
- type: "tms",
57
- urlTemplate: "http://localhost:8080/tms/%s",
58
- },
59
- ],
60
- });
61
- }
62
- }
63
- ```
64
-
65
- Then let know `cucumber-js` about the reporter via CLI parameter:
27
+ const AllureCucumberReporter = require("allure-cucumberjs/reporter");
66
28
 
67
- ```shell
68
- cucumber-js --format ./path/to/reporter.js
29
+ export default AllureCucumberReporter;
69
30
  ```
70
31
 
71
- Or via configuration file:
32
+ Then add following lines to the CucumberJS configuration file:
72
33
 
73
- ```js
34
+ ```diff
74
35
  // config.js
75
- module.exports = {
76
- default: {
77
- format: "./path/to/reporter.js",
78
- },
36
+ export default {
37
+ + format: "./path/to/reporter.js",
79
38
  };
80
39
  ```
81
40
 
@@ -85,120 +44,150 @@ And then run CLI with `config` parameter:
85
44
  cucumber-js --config ./config.js
86
45
  ```
87
46
 
88
- If you want to retain default formatter add some dummy file as output:
47
+ ## Reporter options
89
48
 
90
- ```shell
91
- cucumber-js --format ./path/to/reporter.js:./dummy.txt
92
- ```
49
+ Some reporter settings can be set by following options:
50
+
51
+ | Option | Description | Default |
52
+ | ---------- |-------------------------------------------------------------------------------------------------| ------------------ |
53
+ | resultsDir | Path to results folder | `./allure-results` |
54
+ | links | Links templates to make runtime methods calls simpler and process Cucumber tags as Allure links | `undefined` |
55
+ | labels | Labels templates to process Cucumber tags as Allure labels | `undefined` |
93
56
 
94
57
  ## Using Allure API
95
58
 
96
- You're able to call Allure API methods injected to the `World` object by the reporter.
97
- By default, the feature is available out of the box for single thread mode.
59
+ To start using Allure Runtime API you need to add the following import into your `./feature/support/world.js` file:
60
+
61
+ ```js
62
+ import "allure-cucumberjs";
63
+ ```
98
64
 
99
- Example:
65
+ Then, you can call Allure Runtime API methods directly in your step definitions:
100
66
 
101
67
  ```js
102
68
  import { Given } from "@cucumber/cucumber";
69
+ import { label, attachment, step } from "allure-js-commons";
103
70
 
104
- Given(/my step/, async function () {
105
- await this.step("step can have anonymous body function", async function () {
106
- await this.label("label_name", "label_value");
107
- await this.attach(JSON.stringify({ foo: "bar " }), "application/json");
71
+ Given(/my step/, async () => {
72
+ await step("step can have anonymous body function", async () => {
73
+ await label("label_name", "label_value");
74
+ await attachment(JSON.stringify({ foo: "bar " }), "application/json");
108
75
  });
109
76
 
110
- await this.step("by the way, body function can be arrow one", async (step) => {
111
- await step.label("label_name", "label_value");
112
- await step.attach(JSON.stringify({ foo: "bar " }), "application/json");
77
+ await step("by the way, body function can be arrow one", async () => {
78
+ await label("label_name", "label_value");
79
+ await attachment(JSON.stringify({ foo: "bar " }), "application/json");
113
80
  });
114
81
  });
115
82
  ```
116
83
 
117
- If you want to keep the functoinality in `parallel` mode, set `CucumberAllureWorld` as
118
- world constructor:
84
+ ### Using Allure Cucumber World
119
85
 
120
- ```diff
121
- - import { Given } from "@cucumber/cucumber"
122
- + import { Given, setWorldConstructor } from "@cucumber/cucumber"
123
- + import { CucumberAllureWorld } from "allure-cucumberjs"
124
-
125
- + setWorldConstructor(CucumberAllureWorld)
86
+ If you prefer to use custom Allure World instead of global Allure API, you can use `AllureCucumberWorld` class:
126
87
 
127
- Given(/my step/, async function () {
128
- await this.step("step can have anonymous body function", async function () {
129
- await this.label("label_name", "label_value")
130
- await this.attach(JSON.stringify({ foo: "bar "}), "application/json")
131
- })
88
+ ```js
89
+ import { AllureCucumberWorld } from "allure-cucumberjs";
90
+ import { setWorldConstructor } from "@cucumber/cucumber";
132
91
 
133
- await this.step("by the way, body function can be arrow one", async (step) => {
134
- await step.label("label_name", "label_value")
135
- await step.attach(JSON.stringify({ foo: "bar "}), "application/json")
136
- })
137
- })
92
+ setWorldConstructor(AllureCucumberWorld);
138
93
  ```
139
94
 
140
- Follow the same approach when you need to use your own `World` implementation. Just extend it from
141
- `CucumberAllureWorld`:
95
+ Then you'll be able to use Allure Runtime API through `this` in your step definition files:
142
96
 
143
- ```diff
144
- - import { Given } from "@cucumber/cucumber"
145
- + import { Given, setWorldConstructor } from "@cucumber/cucumber"
146
- + import { CucumberAllureWorld } from "allure-cucumberjs"
97
+ ```js
98
+ import { Given } from "@cucumber/cucumber";
99
+
100
+ Given(/my step/, async function() {
101
+ const self = this;
102
+
103
+ await self.step("step can have anonymous body function", async function() {
104
+ await self.label("label_name", "label_value");
105
+ await self.attachment(JSON.stringify({ foo: "bar " }), "application/json");
106
+ });
147
107
 
148
- + class MyWorld extends CucumberAllureWorld {
149
- + hello() {
150
- + console.log('say hello!')
151
- + }
152
- + }
108
+ await self.step("by the way, body function can be arrow one", async function() {
109
+ await self.label("label_name", "label_value");
110
+ await self.attachment(JSON.stringify({ foo: "bar " }), "application/json");
111
+ });
112
+ });
113
+ ```
153
114
 
154
- + setWorldConstructor(MyWorld)
115
+ If you run your Cucumber features using single thread mode, `AllureCucumberWorld` is set automatically.
155
116
 
156
- Given(/my step/, async function () {
157
- + this.hello()
117
+ ### Links usage
158
118
 
159
- await this.step("step can have anonymous body function", async function () {
160
- await this.label("label_name", "label_value")
161
- await this.attach(JSON.stringify({ foo: "bar "}), "application/json")
162
- })
119
+ ```js
120
+ const { Given } = require("@cucumber/cucumber");
121
+ import { link, issue, tms } from "allure-js-commons";
163
122
 
164
- await this.step("by the way, body function can be arrow one", async (step) => {
165
- await step.label("label_name", "label_value")
166
- await step.attach(JSON.stringify({ foo: "bar "}), "application/json")
167
- })
168
- })
123
+ Given("step name", async () => {
124
+ await link("link_type", "https://allurereport.org", "Allure Report");
125
+ await issue("Issue Name", "https://github.com/allure-framework/allure-js/issues/352");
126
+ await tms("Task Name", "https://github.com/allure-framework/allure-js/tasks/352");
127
+ });
169
128
  ```
170
129
 
171
- ## TypeScript
130
+ You can also configure links formatters to make usage much more convenient. `%s`
131
+ in `urlTemplate` parameter will be replaced by given value.
172
132
 
173
- To properly type your cucumber tests you need to declare `CustomWorld` type and use it.
133
+ ```diff
134
+ // config.js
135
+ export default {
136
+ format: "./path/to/reporter.js",
137
+ + formatOptions: {
138
+ + links: [
139
+ + {
140
+ + pattern: [/@issue=(.*)/],
141
+ + type: "issue",
142
+ + urlTemplate: "https://example.com/issues/%s",
143
+ + nameTemplate: "Issue: %s",
144
+ + },
145
+ + {
146
+ + pattern: [/@tms=(.*)/],
147
+ + type: "tms",
148
+ + urlTemplate: "https://example.com/tasks/%s",
149
+ + },
150
+ + ],
151
+ + }
152
+ };
153
+ ```
174
154
 
175
- ```ts
176
- import { Given } from "@cucumber/cucumber";
177
- import { CucumberAllureWorld } from "allure-cucumberjs";
155
+ Then you can assign link using shorter notation:
178
156
 
179
- if (process.env.PARALLEL) {
180
- setWorldConstructor(CucumberAllureWorld);
181
- }
157
+ ```js
158
+ const { Given } = require("@cucumber/cucumber");
159
+ import { link, issue, tms } from "allure-js-commons";
160
+
161
+ Given("step name", async () => {
162
+ await issue("351");
163
+ await issue("352", "Issue Name");
164
+ await tms("351");
165
+ await tms("352", "Task Name");
166
+ await link("custom", "352");
167
+ await link("custom", "352", "Link name");
168
+ });
169
+ ```
182
170
 
183
- type CustomWorld = {
184
- someCustomOptions: string;
185
- } & CucumberAllureWorld;
171
+ Links patterns also work with Cucumber tags which match `pattern` parameter:
186
172
 
187
- Given("A cat fact is recieved", async function (this: CustomWorld) {
188
- await this.step("example name", async () => {
189
- await this.label("test label", "value");
190
- });
191
- });
173
+ ```gherkin
174
+ @issue=0
175
+ Feature: links
176
+
177
+ @issue=1 @tms=2
178
+ Scenario: a
179
+ Given a step
192
180
  ```
193
181
 
194
182
  ### Parameters usage
195
183
 
196
184
  ```ts
197
185
  import { Given } from "@cucumber/cucumber";
186
+ import { step, parameter } from "allure-js-commons";
198
187
 
199
- Given(/my step/, async function () {
200
- await this.step("step can have anonymous body function", async function () {
201
- await this.parameter("parameterName", "parameterValue");
188
+ Given(/my step/, async () => {
189
+ await step("step can have anonymous body function", async () => {
190
+ await parameter("parameterName", "parameterValue");
202
191
  });
203
192
  });
204
193
  ```
@@ -211,10 +200,11 @@ Also addParameter takes an third optional parameter with the hidden and excluded
211
200
 
212
201
  ```ts
213
202
  import { Given } from "@cucumber/cucumber";
203
+ import { step, parameter } from "allure-js-commons";
214
204
 
215
- Given(/my step/, async function () {
216
- await this.step("step can have anonymous body function", async function () {
217
- await this.parameter("parameterName", "parameterValue", { mode: "hidden", excluded: true });
205
+ Given(/my step/, async () => {
206
+ await step("step can have anonymous body function", async () => {
207
+ await parameter("parameterName", "parameterValue", { mode: "hidden", excluded: true });
218
208
  });
219
209
  });
220
210
  ```
@@ -224,11 +214,15 @@ Given(/my step/, async function () {
224
214
  For cross-browser testing simply add a parameter using Allure API with the browser name to the `World` instance inside your scenario, i.e.:
225
215
 
226
216
  ```js
227
- await this.parameter('Browser', 'firefox')
217
+ import { parameter } from "allure-js-commons";
218
+
219
+ await parameter('Browser', 'firefox')
228
220
  ```
229
221
 
230
222
  For better presentation, you can also group suites by browser names, i.e.:
231
223
 
232
224
  ```js
233
- await this.parentSuite('Firefox')
225
+ import { parentSuite } from "allure-js-commons";
226
+
227
+ await parentSuite('Firefox')
234
228
  ```
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "AllureCucumberTestRuntime", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _runtime2.AllureCucumberTestRuntime;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "AllureCucumberWorld", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _world.AllureCucumberWorld;
16
+ }
17
+ });
18
+ var _cucumber = require("@cucumber/cucumber");
19
+ var _runtime = require("allure-js-commons/sdk/runtime");
20
+ var _runtime2 = require("./runtime.js");
21
+ var _world = require("./world.js");
22
+ (0, _cucumber.Before)(function () {
23
+ // TODO: we can implement testplan logic there
24
+ (0, _runtime.setGlobalTestRuntime)(
25
+ // @ts-ignore
26
+ new _runtime2.AllureCucumberTestRuntime({
27
+ attach: this.attach,
28
+ log: this.log,
29
+ parameters: this.parameters
30
+ }));
31
+ });
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_cucumber","require","_runtime","_runtime2","_world","Before","setGlobalTestRuntime","AllureCucumberTestRuntime","attach","log","parameters"],"sources":["../../src/index.ts"],"sourcesContent":["import { Before } from \"@cucumber/cucumber\";\nimport { setGlobalTestRuntime } from \"allure-js-commons/sdk/runtime\";\nimport { AllureCucumberTestRuntime } from \"./runtime.js\";\nimport { AllureCucumberWorld } from \"./world.js\";\n\nBefore(function () {\n // TODO: we can implement testplan logic there\n setGlobalTestRuntime(\n // @ts-ignore\n new AllureCucumberTestRuntime({\n attach: this.attach,\n log: this.log,\n parameters: this.parameters,\n }),\n );\n});\n\nexport { AllureCucumberTestRuntime, AllureCucumberWorld };\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,gBAAM,EAAC,YAAY;EACjB;EACA,IAAAC,6BAAoB;EAClB;EACA,IAAIC,mCAAyB,CAAC;IAC5BC,MAAM,EAAE,IAAI,CAACA,MAAM;IACnBC,GAAG,EAAE,IAAI,CAACA,GAAG;IACbC,UAAU,EAAE,IAAI,CAACA;EACnB,CAAC,CACH,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","names":[],"sources":["../../src/model.ts"],"sourcesContent":["import type { LabelName, LinkType } from \"allure-js-commons\";\nimport type { Config } from \"allure-js-commons/sdk/reporter\";\n\nexport type LabelConfig = {\n pattern: RegExp[];\n name: LabelName | string;\n};\n\nexport type LinkConfig = {\n pattern: RegExp[];\n urlTemplate: string;\n type: LinkType | string;\n};\n\nexport interface AllureCucumberReporterConfig extends Omit<Config, \"writer\" | \"links\"> {\n testMode?: boolean;\n links?: LinkConfig[];\n labels?: LabelConfig[];\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }