cucumber-reactive-reporter 1.0.0
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/LICENSE +21 -0
- package/README.md +48 -0
- package/dist/cucumber-reactive-reporter.cjs.js +313 -0
- package/dist/cucumber-reactive-reporter.esm.js +309 -0
- package/dist/package.json +86 -0
- package/dist/react/.DS_Store +0 -0
- package/dist/react/asset-manifest.json +26 -0
- package/dist/react/cucumber-results.json +2786 -0
- package/dist/react/favicon.png +0 -0
- package/dist/react/index.html +1 -0
- package/dist/react/precache-manifest.js +182 -0
- package/dist/react/service-worker.js +39 -0
- package/dist/react/static/css/2.css +4 -0
- package/dist/react/static/css/main.css +1 -0
- package/dist/react/static/js/2.LICENSE.txt +85 -0
- package/dist/react/static/js/2.js +2 -0
- package/dist/react/static/js/main.LICENSE.txt +1 -0
- package/dist/react/static/js/main.js +2 -0
- package/dist/react/static/js/runtime-main.js +1 -0
- package/dist/react/static/media/fontawesome-webfont.eot +0 -0
- package/dist/react/static/media/fontawesome-webfont.svg +2671 -0
- package/dist/react/static/media/fontawesome-webfont.ttf +0 -0
- package/dist/react/static/media/fontawesome-webfont.woff +0 -0
- package/dist/react/static/media/fontawesome-webfont.woff2 +0 -0
- package/dist/react/static/media/roboto-all-300-normal.woff +0 -0
- package/dist/react/static/media/roboto-all-400-normal.woff +0 -0
- package/dist/react/static/media/roboto-all-500-normal.woff +0 -0
- package/dist/react/static/media/roboto-all-700-normal.woff +0 -0
- package/dist/react/static/media/roboto-cyrillic-300-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-cyrillic-400-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-cyrillic-500-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-cyrillic-700-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-cyrillic-ext-300-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-cyrillic-ext-400-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-cyrillic-ext-500-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-cyrillic-ext-700-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-greek-300-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-greek-400-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-greek-500-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-greek-700-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-greek-ext-300-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-greek-ext-400-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-greek-ext-500-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-greek-ext-700-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-latin-300-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-latin-400-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-latin-500-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-latin-700-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-latin-ext-300-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-latin-ext-400-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-latin-ext-500-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-latin-ext-700-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-vietnamese-300-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-vietnamese-400-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-vietnamese-500-normal.woff2 +0 -0
- package/dist/react/static/media/roboto-vietnamese-700-normal.woff2 +0 -0
- package/package.json +88 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Nik
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[](https://vshymanskyy.github.io/StandWithUkraine)
|
|
2
|
+
|
|
3
|
+
<b>Cucumber report library based on react-redux and @mui
|
|
4
|
+
Parses output of cucumberjs
|
|
5
|
+
provides filtering via tags ans status and few other things.</b>
|
|
6
|
+
<br>
|
|
7
|
+
*have not been tested with latest cucumberjs
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```shell
|
|
13
|
+
$ npm install @unsuspecting-noob/cucumber-reactive-reporter
|
|
14
|
+
```
|
|
15
|
+
## Example usage:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import reporter from '@unsuspecting-noob/cucumber-reactive-reporter';
|
|
19
|
+
...
|
|
20
|
+
let reportFilePath="full path to cucumber output json";
|
|
21
|
+
let reportFolderPath="path to folder where the html report will go";
|
|
22
|
+
let meta = { //there will be a metadata section in the report that will display your key value pairs for posterity
|
|
23
|
+
"key1": "value1",
|
|
24
|
+
"fizz: "buzz"
|
|
25
|
+
};
|
|
26
|
+
await reporter.generate(reportFilePath, reportFolderPath, { title: "my tests", description: "My test suite description", metadata: meta });
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
#Sample page
|
|
30
|
+
[link](https://unsuspecting-noob.github.io/cucumber-reactive-reporter/index.html)
|
|
31
|
+
## TODOs and ideas for improvement:
|
|
32
|
+
|
|
33
|
+
1. consider adding hooks for linking to jira the way allure does it:
|
|
34
|
+
```
|
|
35
|
+
links: {
|
|
36
|
+
issue: {
|
|
37
|
+
pattern: [/@issue=(.*)/],
|
|
38
|
+
urlTemplate: "http://localhost:8080/issue/%s"
|
|
39
|
+
},
|
|
40
|
+
tms: {
|
|
41
|
+
pattern: [/@tms=(.*)/],
|
|
42
|
+
urlTemplate: "http://localhost:8080/tms/%s"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
2. patch more settings for intial render (before/after toggle, theme, filter etc.)
|
|
47
|
+
3. handle state "ambiguous" (probably lump em with errors), generate one when there are two test definitions with similar regex
|
|
48
|
+
4. Figure out a strategy for handling combined reports (from parallel runs)
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
4
|
+
|
|
5
|
+
var fs = _interopDefault(require('fs'));
|
|
6
|
+
var ncp = _interopDefault(require('ncp'));
|
|
7
|
+
var path = _interopDefault(require('path'));
|
|
8
|
+
var ut = _interopDefault(require('util'));
|
|
9
|
+
|
|
10
|
+
// import { createRequire } from 'module';
|
|
11
|
+
|
|
12
|
+
ncp.limit = 16;
|
|
13
|
+
|
|
14
|
+
let modulePath = require.resolve("./package.json"); //trick to resolve path to the installed module
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
options.filter - a RegExp instance, against which each file name is tested to determine whether to copy it or not, or a function taking single parameter: copied file name, returning true or false, determining whether to copy file or not.
|
|
18
|
+
|
|
19
|
+
options.transform - a function: function (read, write) { read.pipe(write) } used to apply streaming transforms while copying.
|
|
20
|
+
|
|
21
|
+
options.clobber - boolean=true. if set to false, ncp will not overwrite destination files that already exist.
|
|
22
|
+
|
|
23
|
+
options.dereference - boolean=false. If set to true, ncp will follow symbolic links. For example, a symlink in the source tree pointing to a regular file will become a regular file in the destination tree. Broken symlinks will result in errors.
|
|
24
|
+
|
|
25
|
+
options.stopOnErr - boolean=false. If set to true, ncp will behave like cp -r, and stop on the first error it encounters. By default, ncp continues copying, logging all errors and returning an array.
|
|
26
|
+
|
|
27
|
+
options.errs - stream. If options.stopOnErr is false, a stream can be provided, and errors will be written to this stream.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
let cp = (source, destination, options) => {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
ncp(source, destination, err => {
|
|
34
|
+
if (err) {
|
|
35
|
+
reject(new Error(err));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
resolve();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
let _makeSafe = input => {
|
|
44
|
+
input = input.replace(/&/g, '&');
|
|
45
|
+
input = input.replace(/</g, '<');
|
|
46
|
+
input = input.replace(/>/g, '>');
|
|
47
|
+
return input;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param source path to the cucumber results json
|
|
52
|
+
* @param dest folder path where html report gets written to
|
|
53
|
+
* @param options
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
const generate = async (source, dest, options) => {
|
|
58
|
+
options ? true : options = {};
|
|
59
|
+
const CUCUMBER_JSON_PATH = "_cucumber-results.json";
|
|
60
|
+
const SETTINGS_JSON_PATH = "_reporter_settings.json";
|
|
61
|
+
const HTML_PATH = path.join(path.dirname(modulePath), "react"); //defaults
|
|
62
|
+
|
|
63
|
+
const {
|
|
64
|
+
title = "Cucumber Report",
|
|
65
|
+
//report page title
|
|
66
|
+
description = "Cucumber report",
|
|
67
|
+
//description to be set at the page header
|
|
68
|
+
metadata = {}
|
|
69
|
+
} = options;
|
|
70
|
+
|
|
71
|
+
let __dirname = path.resolve();
|
|
72
|
+
|
|
73
|
+
if (path.isAbsolute(source) === false) {
|
|
74
|
+
source = path.join(__dirname, source);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fs.accessSync(source);
|
|
78
|
+
|
|
79
|
+
if (!dest) {
|
|
80
|
+
dest = path.dirname(source);
|
|
81
|
+
} else {
|
|
82
|
+
if (path.isAbsolute(dest) === false) {
|
|
83
|
+
dest = path.resolve(dest);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
console.log(`__dirname: ${__dirname}\n` + `html path: ${HTML_PATH}\n` + `source: ${source}\n` + `destination: ${dest}\n` + `title: ${title}\n` + `description: ${description}\n` + `metadata: ${ut.inspect(metadata, false, null)}\n`); //validate input json and make a copy
|
|
88
|
+
|
|
89
|
+
let str = fs.readFileSync(source).toString();
|
|
90
|
+
let obj = JSON.parse(str);
|
|
91
|
+
|
|
92
|
+
let out = _prepDataForStore(obj);
|
|
93
|
+
|
|
94
|
+
let modifiedJSON = JSON.stringify(out);
|
|
95
|
+
let destExists = true;
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
fs.accessSync(dest);
|
|
99
|
+
} catch (err) {
|
|
100
|
+
destExists = false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!destExists) {
|
|
104
|
+
fs.mkdirSync(dest, {
|
|
105
|
+
recursive: true
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
fs.writeFileSync(path.join(dest, CUCUMBER_JSON_PATH), modifiedJSON);
|
|
110
|
+
fs.writeFileSync(path.join(dest, SETTINGS_JSON_PATH), JSON.stringify(options));
|
|
111
|
+
await cp(HTML_PATH, dest); //swap out some tokens in the html
|
|
112
|
+
|
|
113
|
+
let indexPagePath = path.join(dest, "index.html");
|
|
114
|
+
let htmlStr = fs.readFileSync(indexPagePath, "utf8").toString();
|
|
115
|
+
let modified = htmlStr.replace(/-=title=-/g, _makeSafe(title));
|
|
116
|
+
fs.writeFileSync(indexPagePath, modified, "utf8");
|
|
117
|
+
console.log("done");
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
let _prepDataForStore = data => {
|
|
121
|
+
let state = {};
|
|
122
|
+
state.features = {};
|
|
123
|
+
state.features.list = [];
|
|
124
|
+
state.features.featuresMap = {};
|
|
125
|
+
state.scenarios = {};
|
|
126
|
+
state.scenarios.list = [];
|
|
127
|
+
state.scenarios.scenariosMap = {};
|
|
128
|
+
state.steps = {};
|
|
129
|
+
state.steps.stepsMap = {};
|
|
130
|
+
state.steps.totalDurationNanoSec = 0; //parse
|
|
131
|
+
|
|
132
|
+
let featureIndex = 0;
|
|
133
|
+
console.time("loadTotal");
|
|
134
|
+
|
|
135
|
+
for (let f of data) {
|
|
136
|
+
//FEATURE
|
|
137
|
+
//cucumber id field is not guaranteed to be unique for feature/scenario/step
|
|
138
|
+
f.id = `${featureIndex++}_${f.id}`;
|
|
139
|
+
|
|
140
|
+
_processFeature(state, f); //SCENARIO
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
let numScenarios = f.elements.length; //avoid multiple lookups;
|
|
144
|
+
|
|
145
|
+
if (f.elements && numScenarios) {
|
|
146
|
+
let sc_index = 0;
|
|
147
|
+
|
|
148
|
+
for (let sc of f.elements) {
|
|
149
|
+
//need to make scenario id unique as well
|
|
150
|
+
sc_index++;
|
|
151
|
+
let sc_id_arr = sc.id.split(";");
|
|
152
|
+
sc_id_arr[0] = f.id;
|
|
153
|
+
|
|
154
|
+
if (sc_id_arr.length) {
|
|
155
|
+
sc_id_arr[1] = `${sc_index - 1}_${sc_id_arr[1]}`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
sc.id = sc_id_arr.join(";");
|
|
159
|
+
|
|
160
|
+
_processScenario(state, f.id, sc); //STEPS
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
for (let st of sc.steps) {
|
|
164
|
+
_processStep(state, sc.id, st);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
console.timeEnd("loadTotal");
|
|
171
|
+
return state;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
let _processFeature = (state, f) => {
|
|
175
|
+
const {
|
|
176
|
+
description,
|
|
177
|
+
elements,
|
|
178
|
+
id,
|
|
179
|
+
keyword,
|
|
180
|
+
line,
|
|
181
|
+
name,
|
|
182
|
+
tags: [...tags],
|
|
183
|
+
uri
|
|
184
|
+
} = f;
|
|
185
|
+
const allTags = [...tags]; //figure out if it has failed stuff
|
|
186
|
+
|
|
187
|
+
let numFailedScenarios = 0;
|
|
188
|
+
let numSkippedScenarios = 0;
|
|
189
|
+
|
|
190
|
+
if (elements && elements.length) {
|
|
191
|
+
for (let el of elements) {
|
|
192
|
+
//collect scenario tags
|
|
193
|
+
if (el.tags && el.tags.length) {
|
|
194
|
+
let temp = allTags.map(t => t.name);
|
|
195
|
+
el.tags.forEach(tag => {
|
|
196
|
+
if (temp.includes(tag.name) === false) {
|
|
197
|
+
allTags.push(tag);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (el.steps && el.steps.length) {
|
|
203
|
+
for (let step of el.steps) {
|
|
204
|
+
if (step.result && step.result.status === "failed") {
|
|
205
|
+
numFailedScenarios++;
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (step.result && step.result.status === "skipped") {
|
|
210
|
+
numSkippedScenarios++;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
state.features.list.push(id);
|
|
219
|
+
state.features.featuresMap[id] = {
|
|
220
|
+
id,
|
|
221
|
+
description,
|
|
222
|
+
uri,
|
|
223
|
+
keyword,
|
|
224
|
+
name,
|
|
225
|
+
line,
|
|
226
|
+
tags,
|
|
227
|
+
allTags,
|
|
228
|
+
numFailedScenarios,
|
|
229
|
+
numSkippedScenarios
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
let _processScenario = (state, featureId, scenario) => {
|
|
234
|
+
const {
|
|
235
|
+
id,
|
|
236
|
+
keyword,
|
|
237
|
+
line,
|
|
238
|
+
name,
|
|
239
|
+
tags: [...tags],
|
|
240
|
+
type,
|
|
241
|
+
uri
|
|
242
|
+
} = scenario;
|
|
243
|
+
state.scenarios.list.push(id);
|
|
244
|
+
state.scenarios.scenariosMap[id] = {
|
|
245
|
+
failedSteps: 0,
|
|
246
|
+
featureId,
|
|
247
|
+
id,
|
|
248
|
+
keyword,
|
|
249
|
+
line,
|
|
250
|
+
name,
|
|
251
|
+
passedSteps: 0,
|
|
252
|
+
skippedSteps: 0,
|
|
253
|
+
tags,
|
|
254
|
+
type,
|
|
255
|
+
uri
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
let _processStep = (state, scenarioId, st) => {
|
|
260
|
+
const {
|
|
261
|
+
arguments: args,
|
|
262
|
+
embeddings,
|
|
263
|
+
hidden,
|
|
264
|
+
keyword,
|
|
265
|
+
line,
|
|
266
|
+
match: {
|
|
267
|
+
location
|
|
268
|
+
},
|
|
269
|
+
name,
|
|
270
|
+
result: {
|
|
271
|
+
duration,
|
|
272
|
+
error_message,
|
|
273
|
+
status
|
|
274
|
+
}
|
|
275
|
+
} = st;
|
|
276
|
+
let step = {
|
|
277
|
+
args,
|
|
278
|
+
duration,
|
|
279
|
+
embeddings,
|
|
280
|
+
error_message,
|
|
281
|
+
keyword,
|
|
282
|
+
line,
|
|
283
|
+
location,
|
|
284
|
+
name,
|
|
285
|
+
status
|
|
286
|
+
};
|
|
287
|
+
if (!state.steps.stepsMap[scenarioId]) state.steps.stepsMap[scenarioId] = {
|
|
288
|
+
steps: []
|
|
289
|
+
};
|
|
290
|
+
state.steps.stepsMap[scenarioId].steps.push(step);
|
|
291
|
+
|
|
292
|
+
if (isNaN(duration) === false) {
|
|
293
|
+
state.steps.totalDurationNanoSec = state.steps.totalDurationNanoSec + duration;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (!hidden || embeddings && embeddings.length) {
|
|
297
|
+
if (status === "passed") {
|
|
298
|
+
state.scenarios.scenariosMap[scenarioId].passedSteps++;
|
|
299
|
+
} else if (status === "skipped") {
|
|
300
|
+
state.scenarios.scenariosMap[scenarioId].skippedSteps++;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (status === "failed") {
|
|
305
|
+
state.scenarios.scenariosMap[scenarioId].failedSteps++;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
var index = {
|
|
310
|
+
generate: generate
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
module.exports = index;
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import ncp from 'ncp';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import ut from 'util';
|
|
5
|
+
|
|
6
|
+
// import { createRequire } from 'module';
|
|
7
|
+
|
|
8
|
+
ncp.limit = 16;
|
|
9
|
+
|
|
10
|
+
let modulePath = require.resolve("./package.json"); //trick to resolve path to the installed module
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
options.filter - a RegExp instance, against which each file name is tested to determine whether to copy it or not, or a function taking single parameter: copied file name, returning true or false, determining whether to copy file or not.
|
|
14
|
+
|
|
15
|
+
options.transform - a function: function (read, write) { read.pipe(write) } used to apply streaming transforms while copying.
|
|
16
|
+
|
|
17
|
+
options.clobber - boolean=true. if set to false, ncp will not overwrite destination files that already exist.
|
|
18
|
+
|
|
19
|
+
options.dereference - boolean=false. If set to true, ncp will follow symbolic links. For example, a symlink in the source tree pointing to a regular file will become a regular file in the destination tree. Broken symlinks will result in errors.
|
|
20
|
+
|
|
21
|
+
options.stopOnErr - boolean=false. If set to true, ncp will behave like cp -r, and stop on the first error it encounters. By default, ncp continues copying, logging all errors and returning an array.
|
|
22
|
+
|
|
23
|
+
options.errs - stream. If options.stopOnErr is false, a stream can be provided, and errors will be written to this stream.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
let cp = (source, destination, options) => {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
ncp(source, destination, err => {
|
|
30
|
+
if (err) {
|
|
31
|
+
reject(new Error(err));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
resolve();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
let _makeSafe = input => {
|
|
40
|
+
input = input.replace(/&/g, '&');
|
|
41
|
+
input = input.replace(/</g, '<');
|
|
42
|
+
input = input.replace(/>/g, '>');
|
|
43
|
+
return input;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param source path to the cucumber results json
|
|
48
|
+
* @param dest folder path where html report gets written to
|
|
49
|
+
* @param options
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
const generate = async (source, dest, options) => {
|
|
54
|
+
options ? true : options = {};
|
|
55
|
+
const CUCUMBER_JSON_PATH = "_cucumber-results.json";
|
|
56
|
+
const SETTINGS_JSON_PATH = "_reporter_settings.json";
|
|
57
|
+
const HTML_PATH = path.join(path.dirname(modulePath), "react"); //defaults
|
|
58
|
+
|
|
59
|
+
const {
|
|
60
|
+
title = "Cucumber Report",
|
|
61
|
+
//report page title
|
|
62
|
+
description = "Cucumber report",
|
|
63
|
+
//description to be set at the page header
|
|
64
|
+
metadata = {}
|
|
65
|
+
} = options;
|
|
66
|
+
|
|
67
|
+
let __dirname = path.resolve();
|
|
68
|
+
|
|
69
|
+
if (path.isAbsolute(source) === false) {
|
|
70
|
+
source = path.join(__dirname, source);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
fs.accessSync(source);
|
|
74
|
+
|
|
75
|
+
if (!dest) {
|
|
76
|
+
dest = path.dirname(source);
|
|
77
|
+
} else {
|
|
78
|
+
if (path.isAbsolute(dest) === false) {
|
|
79
|
+
dest = path.resolve(dest);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
console.log(`__dirname: ${__dirname}\n` + `html path: ${HTML_PATH}\n` + `source: ${source}\n` + `destination: ${dest}\n` + `title: ${title}\n` + `description: ${description}\n` + `metadata: ${ut.inspect(metadata, false, null)}\n`); //validate input json and make a copy
|
|
84
|
+
|
|
85
|
+
let str = fs.readFileSync(source).toString();
|
|
86
|
+
let obj = JSON.parse(str);
|
|
87
|
+
|
|
88
|
+
let out = _prepDataForStore(obj);
|
|
89
|
+
|
|
90
|
+
let modifiedJSON = JSON.stringify(out);
|
|
91
|
+
let destExists = true;
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
fs.accessSync(dest);
|
|
95
|
+
} catch (err) {
|
|
96
|
+
destExists = false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!destExists) {
|
|
100
|
+
fs.mkdirSync(dest, {
|
|
101
|
+
recursive: true
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
fs.writeFileSync(path.join(dest, CUCUMBER_JSON_PATH), modifiedJSON);
|
|
106
|
+
fs.writeFileSync(path.join(dest, SETTINGS_JSON_PATH), JSON.stringify(options));
|
|
107
|
+
await cp(HTML_PATH, dest); //swap out some tokens in the html
|
|
108
|
+
|
|
109
|
+
let indexPagePath = path.join(dest, "index.html");
|
|
110
|
+
let htmlStr = fs.readFileSync(indexPagePath, "utf8").toString();
|
|
111
|
+
let modified = htmlStr.replace(/-=title=-/g, _makeSafe(title));
|
|
112
|
+
fs.writeFileSync(indexPagePath, modified, "utf8");
|
|
113
|
+
console.log("done");
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
let _prepDataForStore = data => {
|
|
117
|
+
let state = {};
|
|
118
|
+
state.features = {};
|
|
119
|
+
state.features.list = [];
|
|
120
|
+
state.features.featuresMap = {};
|
|
121
|
+
state.scenarios = {};
|
|
122
|
+
state.scenarios.list = [];
|
|
123
|
+
state.scenarios.scenariosMap = {};
|
|
124
|
+
state.steps = {};
|
|
125
|
+
state.steps.stepsMap = {};
|
|
126
|
+
state.steps.totalDurationNanoSec = 0; //parse
|
|
127
|
+
|
|
128
|
+
let featureIndex = 0;
|
|
129
|
+
console.time("loadTotal");
|
|
130
|
+
|
|
131
|
+
for (let f of data) {
|
|
132
|
+
//FEATURE
|
|
133
|
+
//cucumber id field is not guaranteed to be unique for feature/scenario/step
|
|
134
|
+
f.id = `${featureIndex++}_${f.id}`;
|
|
135
|
+
|
|
136
|
+
_processFeature(state, f); //SCENARIO
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
let numScenarios = f.elements.length; //avoid multiple lookups;
|
|
140
|
+
|
|
141
|
+
if (f.elements && numScenarios) {
|
|
142
|
+
let sc_index = 0;
|
|
143
|
+
|
|
144
|
+
for (let sc of f.elements) {
|
|
145
|
+
//need to make scenario id unique as well
|
|
146
|
+
sc_index++;
|
|
147
|
+
let sc_id_arr = sc.id.split(";");
|
|
148
|
+
sc_id_arr[0] = f.id;
|
|
149
|
+
|
|
150
|
+
if (sc_id_arr.length) {
|
|
151
|
+
sc_id_arr[1] = `${sc_index - 1}_${sc_id_arr[1]}`;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
sc.id = sc_id_arr.join(";");
|
|
155
|
+
|
|
156
|
+
_processScenario(state, f.id, sc); //STEPS
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
for (let st of sc.steps) {
|
|
160
|
+
_processStep(state, sc.id, st);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
console.timeEnd("loadTotal");
|
|
167
|
+
return state;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
let _processFeature = (state, f) => {
|
|
171
|
+
const {
|
|
172
|
+
description,
|
|
173
|
+
elements,
|
|
174
|
+
id,
|
|
175
|
+
keyword,
|
|
176
|
+
line,
|
|
177
|
+
name,
|
|
178
|
+
tags: [...tags],
|
|
179
|
+
uri
|
|
180
|
+
} = f;
|
|
181
|
+
const allTags = [...tags]; //figure out if it has failed stuff
|
|
182
|
+
|
|
183
|
+
let numFailedScenarios = 0;
|
|
184
|
+
let numSkippedScenarios = 0;
|
|
185
|
+
|
|
186
|
+
if (elements && elements.length) {
|
|
187
|
+
for (let el of elements) {
|
|
188
|
+
//collect scenario tags
|
|
189
|
+
if (el.tags && el.tags.length) {
|
|
190
|
+
let temp = allTags.map(t => t.name);
|
|
191
|
+
el.tags.forEach(tag => {
|
|
192
|
+
if (temp.includes(tag.name) === false) {
|
|
193
|
+
allTags.push(tag);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (el.steps && el.steps.length) {
|
|
199
|
+
for (let step of el.steps) {
|
|
200
|
+
if (step.result && step.result.status === "failed") {
|
|
201
|
+
numFailedScenarios++;
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (step.result && step.result.status === "skipped") {
|
|
206
|
+
numSkippedScenarios++;
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
state.features.list.push(id);
|
|
215
|
+
state.features.featuresMap[id] = {
|
|
216
|
+
id,
|
|
217
|
+
description,
|
|
218
|
+
uri,
|
|
219
|
+
keyword,
|
|
220
|
+
name,
|
|
221
|
+
line,
|
|
222
|
+
tags,
|
|
223
|
+
allTags,
|
|
224
|
+
numFailedScenarios,
|
|
225
|
+
numSkippedScenarios
|
|
226
|
+
};
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
let _processScenario = (state, featureId, scenario) => {
|
|
230
|
+
const {
|
|
231
|
+
id,
|
|
232
|
+
keyword,
|
|
233
|
+
line,
|
|
234
|
+
name,
|
|
235
|
+
tags: [...tags],
|
|
236
|
+
type,
|
|
237
|
+
uri
|
|
238
|
+
} = scenario;
|
|
239
|
+
state.scenarios.list.push(id);
|
|
240
|
+
state.scenarios.scenariosMap[id] = {
|
|
241
|
+
failedSteps: 0,
|
|
242
|
+
featureId,
|
|
243
|
+
id,
|
|
244
|
+
keyword,
|
|
245
|
+
line,
|
|
246
|
+
name,
|
|
247
|
+
passedSteps: 0,
|
|
248
|
+
skippedSteps: 0,
|
|
249
|
+
tags,
|
|
250
|
+
type,
|
|
251
|
+
uri
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
let _processStep = (state, scenarioId, st) => {
|
|
256
|
+
const {
|
|
257
|
+
arguments: args,
|
|
258
|
+
embeddings,
|
|
259
|
+
hidden,
|
|
260
|
+
keyword,
|
|
261
|
+
line,
|
|
262
|
+
match: {
|
|
263
|
+
location
|
|
264
|
+
},
|
|
265
|
+
name,
|
|
266
|
+
result: {
|
|
267
|
+
duration,
|
|
268
|
+
error_message,
|
|
269
|
+
status
|
|
270
|
+
}
|
|
271
|
+
} = st;
|
|
272
|
+
let step = {
|
|
273
|
+
args,
|
|
274
|
+
duration,
|
|
275
|
+
embeddings,
|
|
276
|
+
error_message,
|
|
277
|
+
keyword,
|
|
278
|
+
line,
|
|
279
|
+
location,
|
|
280
|
+
name,
|
|
281
|
+
status
|
|
282
|
+
};
|
|
283
|
+
if (!state.steps.stepsMap[scenarioId]) state.steps.stepsMap[scenarioId] = {
|
|
284
|
+
steps: []
|
|
285
|
+
};
|
|
286
|
+
state.steps.stepsMap[scenarioId].steps.push(step);
|
|
287
|
+
|
|
288
|
+
if (isNaN(duration) === false) {
|
|
289
|
+
state.steps.totalDurationNanoSec = state.steps.totalDurationNanoSec + duration;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (!hidden || embeddings && embeddings.length) {
|
|
293
|
+
if (status === "passed") {
|
|
294
|
+
state.scenarios.scenariosMap[scenarioId].passedSteps++;
|
|
295
|
+
} else if (status === "skipped") {
|
|
296
|
+
state.scenarios.scenariosMap[scenarioId].skippedSteps++;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (status === "failed") {
|
|
301
|
+
state.scenarios.scenariosMap[scenarioId].failedSteps++;
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
var index = {
|
|
306
|
+
generate: generate
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
export default index;
|