webship-js 1.0.5 → 1.0.6

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/.eslintignore ADDED
@@ -0,0 +1,4 @@
1
+ node_modules
2
+ ./node_modules
3
+ */node_modules
4
+ nightwatch.conf.js
package/.eslintrc.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "extends": [
3
+ "airbnb-base"
4
+ ],
5
+ "root": true,
6
+ "env": {
7
+ "browser": true,
8
+ "node": true
9
+ },
10
+ "globals": {
11
+ "loadjs": true
12
+ },
13
+ "rules": {
14
+ "consistent-return": ["off"],
15
+ "no-underscore-dangle": ["off"],
16
+ "max-nested-callbacks": ["warn", 5],
17
+ "import/no-mutable-exports": ["warn"],
18
+ "no-console": ["off"],
19
+ "no-plusplus": ["warn", {
20
+ "allowForLoopAfterthoughts": true
21
+ }],
22
+ "no-param-reassign": ["off"],
23
+ "no-prototype-builtins": ["off"],
24
+ "valid-jsdoc": ["warn", {
25
+ "prefer": {
26
+ "returns": "return",
27
+ "property": "prop"
28
+ },
29
+ "requireReturn": false
30
+ }],
31
+ "no-unused-vars": ["warn"],
32
+ "operator-linebreak": ["error", "after", { "overrides": { "?": "ignore", ":": "ignore" } }]
33
+ }
34
+ }
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const conf = require('../nightwatch.conf.js');
5
+
6
+ /**
7
+ * Folders Path Array variable
8
+ *
9
+ * Set and Get folders path exist in (--config) tag and
10
+ * (--src_folder) tag added in nodejs command line
11
+ */
12
+ let foldersPath = [];
13
+ function setFoldersPath(value) {
14
+ value.forEach((element) => {
15
+ foldersPath.push(element);
16
+ });
17
+ }
18
+
19
+ /**
20
+ * Output Format name variable
21
+ *
22
+ * Set and Get Output Format exist in (--format) tag added
23
+ * in nodejs command line
24
+ */
25
+ let outputFormat = 'stdout-spaces';
26
+ function setOutputFormat(value) { outputFormat = value; }
27
+
28
+ /**
29
+ * Start with Function.
30
+ *
31
+ * Return list of array items that start with
32
+ * (Given, Then, When, /** ,* , *\).
33
+ *
34
+ * @param {array} stepsList The full step-definitions file lines list
35
+ * @return {array} The array has only lines startsWith words chosen
36
+ */
37
+ function startWith(stepsList) {
38
+ return (stepsList.startsWith('Given') ||
39
+ stepsList.startsWith('Then') ||
40
+ stepsList.startsWith('When') ||
41
+ stepsList.startsWith('/**') ||
42
+ stepsList.startsWith('* ') ||
43
+ stepsList.startsWith('*/'));
44
+ }
45
+
46
+ /**
47
+ * Filter Step Definitions
48
+ *
49
+ * @param {array} stepsList The step definitions array is sent to filter
50
+ * by startsWith words chosen
51
+ * @return {array} Step definitions filtered array
52
+ */
53
+ function callStartsWith(stepsList) {
54
+ return stepsList.filter(startWith);
55
+ }
56
+
57
+ /**
58
+ * Clean Steps List
59
+ *
60
+ * Return list of array items cleand from unreadable chars
61
+ *
62
+ * @param {array} stepsList The step definitions array before clean
63
+ * unreadable signs
64
+ * @return {array} The step definitions cleaned array
65
+ */
66
+ function stepsCleanList(stepsList) {
67
+ let stepComment = '';
68
+ const newStepsList = [];
69
+
70
+ stepsList.forEach((element) => {
71
+ if (element.startsWith('* ')) {
72
+ element = element.replace('* ', '');
73
+
74
+ if (stepComment === '') stepComment = element;
75
+ else stepComment = `${stepComment}\r\n${element}`;
76
+ } else if (!element.startsWith('/**') && !element.startsWith('*/')) {
77
+ const filter1 = element.split('$/');
78
+ const filter2 = filter1[0].replace('(/^', ' ');
79
+
80
+ if (stepComment !== '') {
81
+ if (outputFormat.startsWith('html')) newStepsList.push(`${filter2}\r\n<div>${stepComment}</div>`);
82
+ else newStepsList.push(`${filter2}\r\n${stepComment}`);
83
+ } else newStepsList.push(filter2);
84
+
85
+ stepComment = '';
86
+ }
87
+ });
88
+ return newStepsList;
89
+ }
90
+
91
+ function srcFolderPaths(path) {
92
+ const splitConfig = path.split('=');
93
+ const pathsLine = splitConfig[1];
94
+ const paths = pathsLine.split(' ');
95
+
96
+ setFoldersPath(paths);
97
+ }
98
+
99
+ for (let i = 2; i < process.argv.length; i++) {
100
+ if (process.argv[i].startsWith('--config')) {
101
+ const splitConfig = process.argv[i].split('=');
102
+ const path = splitConfig[1];
103
+ const configPath = require(path);
104
+
105
+ let configPathsArray = [];
106
+ configPathsArray = configPath.src_folders;
107
+
108
+ setFoldersPath(configPathsArray);
109
+ } else if (process.argv[i].startsWith('--src_folders')) {
110
+ srcFolderPaths(process.argv[i]);
111
+ } else if (process.argv[i].startsWith('--format')) {
112
+ setOutputFormat(process.argv[i].split('=')[1]);
113
+ }
114
+ }
115
+
116
+ if (foldersPath.length === 0) foldersPath = conf.src_folders;
117
+
118
+ foldersPath.forEach((folderPath) => {
119
+ fs.readdir(folderPath, (err, files) => {
120
+ if (err) {
121
+ return console.log(`Unable to scan directory: ${err}`);
122
+ }
123
+
124
+ files.forEach((file) => {
125
+ fs.readFile(`./${folderPath}/${file}`, 'utf8', (err, data) => {
126
+ if (err) {
127
+ throw new Error(err);
128
+ }
129
+ const contentLines = data.split('\n');
130
+ const contentTrimmed = contentLines.map((element) => element.trim());
131
+
132
+ const stepsStartWith = callStartsWith(contentTrimmed);
133
+ const stepsList = stepsCleanList(stepsStartWith);
134
+
135
+ stepsList.forEach((element) => {
136
+ if (outputFormat.startsWith('stdout')) {
137
+ console.log(element);
138
+ } else if (outputFormat.startsWith('html')) {
139
+ console.log(`<div>${element}</div>`);
140
+ } else { console.log(element); }
141
+ });
142
+ });
143
+ });
144
+ });
145
+ });
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const conf = require('../nightwatch.conf.js');
5
+
6
+ /**
7
+ * Folders Path Array variable
8
+ *
9
+ * Set and Get folders path exist in (--config) tag and
10
+ * (--src_folder) tag added in nodejs command line
11
+ */
12
+ let foldersPath = [];
13
+ function setFoldersPath(value) {
14
+ value.forEach((element) => {
15
+ foldersPath.push(element);
16
+ });
17
+ }
18
+
19
+ /**
20
+ * Output Format name variable
21
+ *
22
+ * Set and Get Output Format exist in (--format) tag added
23
+ * in nodejs command line
24
+ */
25
+ let outputFormat = 'stdout-spaces';
26
+ function setOutputFormat(value) { outputFormat = value; }
27
+
28
+ /**
29
+ * Start with Function.
30
+ *
31
+ * Return list of array items that start with (Given, Then, When).
32
+ *
33
+ * @param {array} stepsList The full step-definitions file lines list
34
+ * @return {array} The array has only lines startsWith words chosen
35
+ */
36
+ function startWith(stepsList) {
37
+ return (stepsList.startsWith('Given') ||
38
+ stepsList.startsWith('Then') ||
39
+ stepsList.startsWith('When'));
40
+ }
41
+
42
+ /**
43
+ * Filter Step Definitions
44
+ *
45
+ * @param {array} stepsList The step definitions array is sent to filter
46
+ * by startsWith words chosen
47
+ * @return {array} Step definitions filtered array
48
+ */
49
+ function callStartsWith(stepsList) {
50
+ return stepsList.filter(startWith);
51
+ }
52
+
53
+ /**
54
+ * Clean Steps List
55
+ *
56
+ * Return list of array items cleand from unreadable chars
57
+ *
58
+ * @param {array} stepsList The step definitions array before clean
59
+ * unreadable signs
60
+ * @return {array} The step definitions cleaned array
61
+ */
62
+ function stepsCleanList(stepsList) {
63
+ const newStepsList = [];
64
+
65
+ stepsList.forEach((element) => {
66
+ const filter1 = element.split('$/');
67
+ const filter2 = filter1[0].replace('(/^', ' ');
68
+
69
+ newStepsList.push(filter2);
70
+ });
71
+ return newStepsList;
72
+ }
73
+
74
+ function srcFolderPaths(path) {
75
+ const splitConfig = path.split('=');
76
+ const pathsLine = splitConfig[1];
77
+ const paths = pathsLine.split(' ');
78
+
79
+ setFoldersPath(paths);
80
+ }
81
+
82
+ for (let i = 2; i < process.argv.length; i++) {
83
+ if (process.argv[i].startsWith('--config')) {
84
+ const splitConfig = process.argv[i].split('=');
85
+ const path = splitConfig[1];
86
+ const configPath = require(path);
87
+
88
+ let configPathsArray = [];
89
+ configPathsArray = configPath.src_folders;
90
+
91
+ setFoldersPath(configPathsArray);
92
+ } else if (process.argv[i].startsWith('--src_folders')) {
93
+ srcFolderPaths(process.argv[i]);
94
+ } else if (process.argv[i].startsWith('--format')) {
95
+ setOutputFormat(process.argv[i].split('=')[1]);
96
+ }
97
+ }
98
+
99
+ if (foldersPath.length === 0) foldersPath = conf.src_folders;
100
+
101
+ foldersPath.forEach((folderPath) => {
102
+ fs.readdir(folderPath, (err, files) => {
103
+ if (err) {
104
+ return console.log(`Unable to scan directory: ${err}`);
105
+ }
106
+
107
+ files.forEach((file) => {
108
+ fs.readFile(`./${folderPath}/${file}`, 'utf8', (err, data) => {
109
+ if (err) {
110
+ throw new Error(err);
111
+ }
112
+ const contentLines = data.split('\n');
113
+ const contentTrimmed = contentLines.map((element) => element.trim());
114
+
115
+ const stepsStartWith = callStartsWith(contentTrimmed);
116
+ const stepsList = stepsCleanList(stepsStartWith);
117
+
118
+ stepsList.forEach((element) => {
119
+ if (outputFormat.startsWith('stdout')) {
120
+ console.log(element);
121
+ } else if (outputFormat.startsWith('html')) {
122
+ console.log(`<div>${element}</div>`);
123
+ } else { console.log(element); }
124
+ });
125
+ });
126
+ });
127
+ });
128
+ });
package/package.json CHANGED
@@ -1,13 +1,18 @@
1
1
  {
2
2
  "name": "webship-js",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Webship JS automated functional testing.",
5
5
  "main": "index.js",
6
6
  "directories": {
7
7
  "test": "test"
8
8
  },
9
+ "engines": {
10
+ "yarn": ">= 1.6",
11
+ "node": ">= 16.0"
12
+ },
9
13
  "scripts": {
10
- "test": "nightwatch --format @cucumber/pretty-formatter --format-options '{\"colorsEnabled\": true}' --format-options '{\"theme\": {\"feature keyword\":[\"bold\",\"blue\"],\"feature name\":[\"blue\",\"underline\"],\"feature description\":[\"blueBright\"],\"scenario keyword\":[\"bold\",\"magenta\"],\"scenario name\":[\"magenta\",\"underline\"],\"step keyword\":[\"bold\",\"green\"],\"step text\":[\"greenBright\",\"italic\"]}}' --format json:./tests/reports/cucumber-report-$( date '+%Y-%m-%d_%H-%M' ).json --format html:./tests/reports/cucumber-report-$( date '+%Y-%m-%d_%H-%M' ).html"
14
+ "test": "nightwatch --format @cucumber/pretty-formatter --format-options '{\"colorsEnabled\": true}' --format-options '{\"theme\": {\"feature keyword\":[\"bold\",\"blue\"],\"feature name\":[\"blue\",\"underline\"],\"feature description\":[\"blueBright\"],\"scenario keyword\":[\"bold\",\"magenta\"],\"scenario name\":[\"magenta\",\"underline\"],\"step keyword\":[\"bold\",\"green\"],\"step text\":[\"greenBright\",\"italic\"]}}' --format json:./tests/reports/cucumber-report-$( date '+%Y-%m-%d_%H-%M' ).json --format html:./tests/reports/cucumber-report-$( date '+%Y-%m-%d_%H-%M' ).html",
15
+ "lint:js": "node ./node_modules/eslint/bin/eslint.js --config=.eslintrc.json ."
11
16
  },
12
17
  "repository": {
13
18
  "type": "git",
@@ -23,9 +28,15 @@
23
28
  "@cucumber/cucumber": "*",
24
29
  "@cucumber/pretty-formatter": "^1.0.0-alpha.2",
25
30
  "chromedriver": "*",
26
- "eslint": "^7.32.0",
27
31
  "geckodriver": "*",
32
+ "eslint": "~8.0",
33
+ "eslint-config-airbnb-base": "^15.0.0",
34
+ "eslint-plugin-import": "^2.25.4",
28
35
  "mocha": "^9.1.3",
29
36
  "nightwatch": "^2.1.7"
30
- }
37
+ },
38
+ "bin":{
39
+ "webship-js-dl" : "./bin/webship-js-dl.js",
40
+ "webship-js-di" : "./bin/webship-js-di.js"
41
+ }
31
42
  }
@@ -1,21 +1,17 @@
1
- const {Given} = require('@cucumber/cucumber');
2
- const {When, Before} = require('@cucumber/cucumber');
3
- const {Then} = require('@cucumber/cucumber');
1
+ const { Given } = require('@cucumber/cucumber');
2
+ const { When, Before } = require('@cucumber/cucumber');
3
+ const { Then } = require('@cucumber/cucumber');
4
4
 
5
5
  /**
6
- * some description
7
- * for first given function
6
+ * webship.js step definitions
7
+ * inside webship-js backage
8
8
  */
9
- Given(/^I go to "([^"]*)?"$/, function(url) {
10
- return browser.url(url);
11
- });
9
+ Given(/^I go to "([^"]*)?"$/, (url) => browser.url(url));
12
10
 
13
- Then(/^I should( not)* see "([^"]*)?"$/, function(negativeCase, expectedText) {
11
+ Then(/^I should( not)* see "([^"]*)?"$/, (negativeCase, expectedText) => {
14
12
  if (negativeCase) {
15
13
  return browser.assert.not.textContains('body', expectedText);
16
14
  }
17
-
15
+
18
16
  return browser.assert.textContains('body', expectedText);
19
17
  });
20
-
21
-
package/bin/webship-js-di DELETED
@@ -1,87 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const fs = require('fs');
4
- conf = require("./../nightwatch.conf.js");
5
- const FoldersPath = conf.src_folders;
6
-
7
- // console.log(process.argv);
8
-
9
- for(var i=2; i<process.argv.length; i++)
10
- FoldersPath.push(process.argv[i]);
11
-
12
- FoldersPath.forEach(Folder_Path => {
13
-
14
- fs.readdir(Folder_Path, function (err, files) {
15
-
16
- if (err) {
17
- return console.log('Unable to scan directory: ' + err);
18
- }
19
-
20
- files.forEach(file => {
21
- fs.readFile('./' + Folder_Path + '/' + file, 'utf8', (err, data) => {
22
- if(err){
23
- throw new Error(err);
24
- }
25
- const SplitByLine_Arr = data.split("\n");
26
- const Trim_Arr = SplitByLine_Arr.map(element => {
27
- return element.trim();
28
- });
29
- const StartWith_Arr = Trim_Arr.filter(StartWith);
30
- const Steps_Arr = CleanStepsList(StartWith_Arr);
31
-
32
- Steps_Arr.forEach(element => {
33
- console.log(element);
34
- });
35
- });
36
- });
37
- });
38
- });
39
-
40
- /**
41
- * Start with Function.
42
- *
43
- * Return list of array items start with (Given, Then, When,*).
44
- *
45
- * @param ArrLine
46
- * @returns array
47
- */
48
- function StartWith(ArrLine) {
49
- return (ArrLine.startsWith('Given')
50
- || ArrLine.startsWith('Then')
51
- || ArrLine.startsWith('When')
52
- || ArrLine.startsWith('*'));
53
- }
54
-
55
- /**
56
- * Clean Steps List
57
- *
58
- * Return list of array items cleand from unreadable chars
59
- *
60
- * @param ListArr
61
- * @returns
62
- */
63
- function CleanStepsList(ListArr) {
64
- var StepComment = '';
65
- var NewArr = Array();
66
-
67
- ListArr.forEach((element, index) => {
68
-
69
- if(element.startsWith("* ")){
70
- StepComment = StepComment + element.substring(2) + '\r\n';
71
- }
72
- else if(element.startsWith("/**") || element.startsWith("*/")){
73
-
74
- }
75
- else
76
- {
77
- const Filter1 = element.split("$/");
78
- const Filter2 = Filter1[0].replace("(/^", ' ');
79
-
80
- NewArr.push(Filter2 + '\r\n' + StepComment);
81
- StepComment = '';
82
- }
83
-
84
- });
85
- return NewArr;
86
- }
87
-
package/bin/webship-js-dl DELETED
@@ -1,70 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const fs = require('fs');
4
-
5
- conf = require("./../nightwatch.conf.js");
6
- var FoldersPath = conf.src_folders;
7
-
8
- for(var i=2; i<process.argv.length; i++)
9
- FoldersPath.push(process.argv[i]);
10
-
11
- FoldersPath.forEach(Folder_Path => {
12
-
13
- fs.readdir(Folder_Path, function (err, files) {
14
-
15
- if (err) {
16
- return console.log('Unable to scan directory: ' + err);
17
- }
18
-
19
- files.forEach(file => {
20
- fs.readFile('./' + Folder_Path + '/' + file, 'utf8', (err, data) => {
21
- if(err){
22
- throw new Error(err);
23
- }
24
- const SplitByLine_Arr = data.split("\n");
25
- const Trim_Arr = SplitByLine_Arr.map(element => {
26
- return element.trim();
27
- });
28
- const StartWith_Arr = Trim_Arr.filter(StartWith);
29
- const Steps_Arr = CleanStepsList(StartWith_Arr);
30
-
31
- Steps_Arr.forEach(element => {
32
- console.log(element);
33
- });
34
- });
35
- });
36
- });
37
- });
38
-
39
- /**
40
- * Start with Function.
41
- *
42
- * Return list of array items start with (Given, Then, When).
43
- *
44
- * @param ArrLine
45
- * @returns array
46
- */
47
- function StartWith(ArrLine) {
48
- return (ArrLine.startsWith('Given')
49
- || ArrLine.startsWith('Then')
50
- || ArrLine.startsWith('When'));
51
- }
52
-
53
- /**
54
- * Clean Steps List
55
- *
56
- * Return list of array items cleand from unreadable chars
57
- *
58
- * @param ListArr
59
- * @returns
60
- */
61
- function CleanStepsList(ListArr) {
62
- ListArr.forEach((element, index) => {
63
- const Filter1 = element.split("$/");
64
- const Filter2 = Filter1[0].replace("(/^", ' ');
65
-
66
- ListArr[index] = Filter2;
67
- });
68
- return Arr;
69
- }
70
-