webship-js 1.0.10 → 1.0.11
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/package.json +1 -1
- package/steplist.js +101 -64
package/package.json
CHANGED
package/steplist.js
CHANGED
|
@@ -2,7 +2,21 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const fs = require('fs');
|
|
5
|
-
|
|
5
|
+
var insidProject = false;
|
|
6
|
+
var basePath = '';
|
|
7
|
+
var projectPath = '';
|
|
8
|
+
|
|
9
|
+
const currentPath = process.argv[1].split("node_modules");
|
|
10
|
+
basePath = currentPath[0].substring(0, currentPath[0].lastIndexOf("/"));
|
|
11
|
+
basePath = basePath + '/';
|
|
12
|
+
projectPath = basePath + "node_modules/webship-js/";
|
|
13
|
+
|
|
14
|
+
if(currentPath.length > 1){
|
|
15
|
+
insidProject = true;
|
|
16
|
+
}
|
|
17
|
+
else{
|
|
18
|
+
insidProject = false;
|
|
19
|
+
}
|
|
6
20
|
|
|
7
21
|
/**
|
|
8
22
|
* -----------------------------------------------------
|
|
@@ -11,44 +25,47 @@ const conf = require('./nightwatch.conf.js');
|
|
|
11
25
|
*/
|
|
12
26
|
const { ArgumentParser } = require('argparse');
|
|
13
27
|
const { version } = require('./package.json');
|
|
14
|
-
|
|
28
|
+
|
|
15
29
|
const parser = new ArgumentParser({
|
|
16
30
|
description: 'Argparse example'
|
|
17
31
|
});
|
|
18
32
|
|
|
19
33
|
parser.add_argument('-v', '--version', { action: 'version', version });
|
|
20
|
-
parser.add_argument('-l', '--list',
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
34
|
+
parser.add_argument('-l', '--list',
|
|
35
|
+
{
|
|
36
|
+
help: 'Display step definitions list without information.',
|
|
37
|
+
action: 'store_true',
|
|
38
|
+
default: true,
|
|
39
|
+
});
|
|
26
40
|
|
|
27
|
-
parser.add_argument('-i', '--
|
|
28
|
-
{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
41
|
+
parser.add_argument('-i', '--info',
|
|
42
|
+
{
|
|
43
|
+
help: 'Display step definitions list with information.',
|
|
44
|
+
action: 'store_true',
|
|
45
|
+
});
|
|
32
46
|
|
|
33
|
-
parser.add_argument('-c', '--config',
|
|
34
|
-
{
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
47
|
+
parser.add_argument('-c', '--config',
|
|
48
|
+
{
|
|
49
|
+
help: 'Add your nightwatch config file, Example: -c="nightwatch.conf.js" OR -c=nightwatch.conf.js OR -c nightwatch.conf.js',
|
|
50
|
+
default: 'nightwatch.conf.js',
|
|
51
|
+
});
|
|
38
52
|
|
|
39
|
-
parser.add_argument('-s', '--src_folders',
|
|
40
|
-
{
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
53
|
+
parser.add_argument('-s', '--src_folders',
|
|
54
|
+
{
|
|
55
|
+
help: 'Add your step definitions folder/s path, Example: -s="path/to/folder1" OR -s="path/to/folder1 path/to/folder2", You can add as much as you want of folder paths',
|
|
56
|
+
default: "",
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
parser.add_argument('-f', '--format',
|
|
60
|
+
{
|
|
61
|
+
help: 'Choose step definitions list format style. \n(1) stdout-spaces. \n(2) stdout-dashes \n(3) html-spaces. \n(4) html-dashes. Example: -f=stdout-dashes OR -f stdout-dashes',
|
|
62
|
+
default: "stdout-spaces",
|
|
63
|
+
});
|
|
44
64
|
|
|
45
|
-
parser.add_argument('-f', '--format',
|
|
46
|
-
{
|
|
47
|
-
help: 'Choose step definitions list format style, just add a number. (1) stdout-space. (2) stdout-dashes. Example: -f=1 OR -f 2',
|
|
48
|
-
default: "1",
|
|
49
|
-
});
|
|
50
|
-
|
|
51
65
|
var argsParse = parser.parse_args();
|
|
66
|
+
if(currentPath.length > 1){
|
|
67
|
+
argsParse.format = 'html-spaces';
|
|
68
|
+
}
|
|
52
69
|
|
|
53
70
|
/**
|
|
54
71
|
* -----------------------------------------------------
|
|
@@ -61,21 +78,23 @@ var argsParse = parser.parse_args();
|
|
|
61
78
|
* (--src_folder) tag added in nodejs command line.
|
|
62
79
|
*/
|
|
63
80
|
let foldersPath = [];
|
|
64
|
-
function setFoldersPath(value) {
|
|
81
|
+
function setFoldersPath(value, type) {
|
|
65
82
|
value.forEach((element) => {
|
|
66
|
-
|
|
83
|
+
var elementPath = '';
|
|
84
|
+
if(insidProject == true && !process.argv.find(element => element == type)){
|
|
85
|
+
elementPath = projectPath + element;
|
|
86
|
+
}
|
|
87
|
+
else if(insidProject == false && !process.argv.find(element => element == type)){
|
|
88
|
+
elementPath = basePath + element;
|
|
89
|
+
}
|
|
90
|
+
else{
|
|
91
|
+
elementPath = element;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
foldersPath.push(elementPath);
|
|
67
95
|
});
|
|
68
96
|
}
|
|
69
97
|
|
|
70
|
-
/**
|
|
71
|
-
* Output Format name variable
|
|
72
|
-
*
|
|
73
|
-
* Set and Get Output Format exist in (--format) tag added
|
|
74
|
-
* in nodejs command line.
|
|
75
|
-
*/
|
|
76
|
-
let outputFormat = 'stdout-spaces';
|
|
77
|
-
function setOutputFormat(value) { outputFormat = value; }
|
|
78
|
-
|
|
79
98
|
/**
|
|
80
99
|
* Start with Function.
|
|
81
100
|
*
|
|
@@ -86,18 +105,18 @@ function setOutputFormat(value) { outputFormat = value; }
|
|
|
86
105
|
* @return {array} The array has only lines startsWith words chosen.
|
|
87
106
|
*/
|
|
88
107
|
function startWith(stepsList) {
|
|
89
|
-
if(argsParse.
|
|
108
|
+
if (argsParse.info == true) {
|
|
90
109
|
return (stepsList.startsWith('Given') ||
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
110
|
+
stepsList.startsWith('Then') ||
|
|
111
|
+
stepsList.startsWith('When') ||
|
|
112
|
+
stepsList.startsWith('/**') ||
|
|
113
|
+
stepsList.startsWith('* ') ||
|
|
114
|
+
stepsList.startsWith('*/'));
|
|
96
115
|
}
|
|
97
|
-
else if(argsParse.list == true){
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
116
|
+
else if (argsParse.list == true) {
|
|
117
|
+
return (stepsList.startsWith('Given') ||
|
|
118
|
+
stepsList.startsWith('Then') ||
|
|
119
|
+
stepsList.startsWith('When'));
|
|
101
120
|
}
|
|
102
121
|
}
|
|
103
122
|
|
|
@@ -134,9 +153,12 @@ function stepsCleanList(stepsList) {
|
|
|
134
153
|
} else if (!element.startsWith('/**') && !element.startsWith('*/')) {
|
|
135
154
|
const filter1 = element.split('$/');
|
|
136
155
|
const filter2 = filter1[0].replace('(/^', ' ');
|
|
137
|
-
|
|
156
|
+
|
|
138
157
|
if (stepComment !== '') {
|
|
139
|
-
if (
|
|
158
|
+
if (argsParse.format.startsWith('html')){
|
|
159
|
+
stepComment = `<div class="info">${stepComment}</div>\r\n`;
|
|
160
|
+
newStepsList.push(`${filter2}\r\n${stepComment}`);
|
|
161
|
+
}
|
|
140
162
|
else newStepsList.push(`${filter2}\r\n${stepComment}`);
|
|
141
163
|
} else newStepsList.push(filter2);
|
|
142
164
|
|
|
@@ -149,7 +171,7 @@ function stepsCleanList(stepsList) {
|
|
|
149
171
|
function srcFolderPaths(path) {
|
|
150
172
|
const paths = path.split(' ');
|
|
151
173
|
|
|
152
|
-
setFoldersPath(paths);
|
|
174
|
+
setFoldersPath(paths, '-s');
|
|
153
175
|
}
|
|
154
176
|
|
|
155
177
|
/**
|
|
@@ -159,18 +181,28 @@ function srcFolderPaths(path) {
|
|
|
159
181
|
* all folders contain step definitions js files.
|
|
160
182
|
*/
|
|
161
183
|
|
|
162
|
-
|
|
184
|
+
if(insidProject == true && !process.argv.find(element => element == "-c")){
|
|
185
|
+
argsParse.config = projectPath + argsParse.config;
|
|
186
|
+
}
|
|
187
|
+
else if(insidProject == false && !process.argv.find(element => element == "-c")){
|
|
188
|
+
argsParse.config = basePath + argsParse.config;
|
|
189
|
+
}
|
|
163
190
|
|
|
164
|
-
|
|
165
|
-
configPathsArray = configPath.src_folders;
|
|
191
|
+
const configPath = require(argsParse.config);
|
|
166
192
|
|
|
167
|
-
|
|
193
|
+
let configPathsArray = [];
|
|
168
194
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
195
|
+
configPathsArray = configPath.src_folders;
|
|
196
|
+
setFoldersPath(configPathsArray, '-c');
|
|
172
197
|
|
|
173
|
-
|
|
198
|
+
if (foldersPath.length === 0) {
|
|
199
|
+
configPathsArray = argsParse.src_folders;
|
|
200
|
+
setFoldersPath(configPathsArray, '-c');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if(process.argv.find(element => element == '-s')){
|
|
204
|
+
srcFolderPaths(argsParse.src_folders);
|
|
205
|
+
}
|
|
174
206
|
|
|
175
207
|
/**
|
|
176
208
|
* Step definitions list
|
|
@@ -185,7 +217,7 @@ foldersPath.forEach((folderPath) => {
|
|
|
185
217
|
}
|
|
186
218
|
|
|
187
219
|
files.forEach((file) => {
|
|
188
|
-
fs.readFile(
|
|
220
|
+
fs.readFile(`${folderPath}/${file}`, 'utf8', (err, data) => {
|
|
189
221
|
if (err) {
|
|
190
222
|
throw new Error(err);
|
|
191
223
|
}
|
|
@@ -196,11 +228,16 @@ foldersPath.forEach((folderPath) => {
|
|
|
196
228
|
const stepsList = stepsCleanList(stepsStartWith);
|
|
197
229
|
|
|
198
230
|
stepsList.forEach((element) => {
|
|
199
|
-
if (argsParse.format ==
|
|
231
|
+
if (argsParse.format == 'stdout-spaces') {
|
|
200
232
|
console.log(element + '\n');
|
|
201
|
-
} else if (argsParse.format ==
|
|
233
|
+
} else if (argsParse.format == 'stdout-dashes') {
|
|
202
234
|
console.log(element + '\n');
|
|
235
|
+
} else if (argsParse.format == 'html-spaces') {
|
|
236
|
+
console.log('<div>' + element + '</div><br/>');
|
|
237
|
+
} else if (argsParse.format == 'html-dashes') {
|
|
238
|
+
console.log('<div>' + element + '</div><br/>');
|
|
203
239
|
}
|
|
240
|
+
|
|
204
241
|
});
|
|
205
242
|
});
|
|
206
243
|
});
|