webship-js 1.0.6 → 1.0.8

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.
@@ -0,0 +1,208 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const fs = require('fs');
5
+ const conf = require('../nightwatch.conf.js');
6
+
7
+ /**
8
+ * -----------------------------------------------------
9
+ * Parse arguments
10
+ * -----------------------------------------------------
11
+ */
12
+ const { ArgumentParser } = require('argparse');
13
+ const { version } = require('../package.json');
14
+
15
+ const parser = new ArgumentParser({
16
+ description: 'Argparse example'
17
+ });
18
+
19
+ parser.add_argument('-v', '--version', { action: 'version', version });
20
+ parser.add_argument('-l', '--list',
21
+ {
22
+ help: 'Display step definitions list without information.',
23
+ action: 'store_true',
24
+ default: true,
25
+ });
26
+
27
+ parser.add_argument('-i', '--information',
28
+ {
29
+ help: 'Display step definitions list with information.',
30
+ action: 'store_true',
31
+ });
32
+
33
+ parser.add_argument('-c', '--config',
34
+ {
35
+ help: 'Add your nightwatch config file, Example: -c="config.js" OR -c=config.js OR -c config.js',
36
+ default: '../nightwatch.conf.js',
37
+ });
38
+
39
+ parser.add_argument('-s', '--src_folders',
40
+ {
41
+ 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',
42
+ default: "tests/step-definitions",
43
+ });
44
+
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
+ var argsParse = parser.parse_args();
52
+
53
+ /**
54
+ * -----------------------------------------------------
55
+ */
56
+
57
+ /**
58
+ * Folders Path Array variable
59
+ *
60
+ * Set and Get folders path exist in (--config) tag and
61
+ * (--src_folder) tag added in nodejs command line.
62
+ */
63
+ let foldersPath = [];
64
+ function setFoldersPath(value) {
65
+ value.forEach((element) => {
66
+ foldersPath.push(element);
67
+ });
68
+ }
69
+
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
+ /**
80
+ * Start with Function.
81
+ *
82
+ * Return list of array items that start with
83
+ * (Given, Then, When, /** ,* , *\).
84
+ *
85
+ * @param {array} stepsList The full step-definitions file lines list.
86
+ * @return {array} The array has only lines startsWith words chosen.
87
+ */
88
+ function startWith(stepsList) {
89
+ if(argsParse.information == true){
90
+ return (stepsList.startsWith('Given') ||
91
+ stepsList.startsWith('Then') ||
92
+ stepsList.startsWith('When') ||
93
+ stepsList.startsWith('/**') ||
94
+ stepsList.startsWith('* ') ||
95
+ stepsList.startsWith('*/'));
96
+ }
97
+ else if(argsParse.list == true){
98
+ return (stepsList.startsWith('Given') ||
99
+ stepsList.startsWith('Then') ||
100
+ stepsList.startsWith('When'));
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Filter Step Definitions
106
+ *
107
+ * @param {array} stepsList The step definitions array is sent to filter
108
+ * by startsWith words chosen.
109
+ * @return {array} Step definitions filtered array.
110
+ */
111
+ function callStartsWith(stepsList) {
112
+ return stepsList.filter(startWith);
113
+ }
114
+
115
+ /**
116
+ * Clean Steps List
117
+ *
118
+ * Return list of array items cleand from unreadable chars.
119
+ *
120
+ * @param {array} stepsList The step definitions array before
121
+ * clean unreadable signs.
122
+ * @return {array} The step definitions cleaned array.
123
+ */
124
+ function stepsCleanList(stepsList) {
125
+ let stepComment = '';
126
+ const newStepsList = [];
127
+
128
+ stepsList.forEach((element) => {
129
+ if (element.startsWith('* ')) {
130
+ element = element.replace('* ', '');
131
+
132
+ if (stepComment === '') stepComment = element;
133
+ else stepComment = `${stepComment}\r\n${element}`;
134
+ } else if (!element.startsWith('/**') && !element.startsWith('*/')) {
135
+ const filter1 = element.split('$/');
136
+ const filter2 = filter1[0].replace('(/^', ' ');
137
+
138
+ if (stepComment !== '') {
139
+ if (outputFormat.startsWith('html')) newStepsList.push(`${filter2}\r\n<div>${stepComment}</div>`);
140
+ else newStepsList.push(`${filter2}\r\n${stepComment}`);
141
+ } else newStepsList.push(filter2);
142
+
143
+ stepComment = '';
144
+ }
145
+ });
146
+ return newStepsList;
147
+ }
148
+
149
+ function srcFolderPaths(path) {
150
+ const paths = path.split(' ');
151
+
152
+ setFoldersPath(paths);
153
+ }
154
+
155
+ /**
156
+ * "foldersPath" array
157
+ *
158
+ * Fill "foldersPath" array process, that has paths of
159
+ * all folders contain step definitions js files.
160
+ */
161
+
162
+ const configPath = require(argsParse.config);
163
+
164
+ let configPathsArray = [];
165
+ configPathsArray = configPath.src_folders;
166
+
167
+ setFoldersPath(configPathsArray);
168
+
169
+ if (foldersPath.length === 0){
170
+ srcFolderPaths(argsParse.src_folders);
171
+ }
172
+
173
+ setOutputFormat(argsParse.format);
174
+
175
+ /**
176
+ * Step definitions list
177
+ *
178
+ * Get clear step definitions list from js
179
+ * step definitions files.
180
+ */
181
+ foldersPath.forEach((folderPath) => {
182
+ fs.readdir(folderPath, (err, files) => {
183
+ if (err) {
184
+ return console.log(`Unable to scan directory: ${err}`);
185
+ }
186
+
187
+ files.forEach((file) => {
188
+ fs.readFile(`./${folderPath}/${file}`, 'utf8', (err, data) => {
189
+ if (err) {
190
+ throw new Error(err);
191
+ }
192
+ const contentLines = data.split('\n');
193
+ const contentTrimmed = contentLines.map((element) => element.trim());
194
+
195
+ const stepsStartWith = callStartsWith(contentTrimmed);
196
+ const stepsList = stepsCleanList(stepsStartWith);
197
+
198
+ stepsList.forEach((element) => {
199
+ if (argsParse.format == 1) {
200
+ console.log(element + '\n');
201
+ } else if (argsParse.format == 2) {
202
+ console.log(element + '\n');
203
+ }
204
+ });
205
+ });
206
+ });
207
+ });
208
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webship-js",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Webship JS automated functional testing.",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -27,16 +27,20 @@
27
27
  "dependencies": {
28
28
  "@cucumber/cucumber": "*",
29
29
  "@cucumber/pretty-formatter": "^1.0.0-alpha.2",
30
- "chromedriver": "*",
31
- "geckodriver": "*",
30
+ "args-parser": "^1.3.0",
32
31
  "eslint": "~8.0",
33
32
  "eslint-config-airbnb-base": "^15.0.0",
34
33
  "eslint-plugin-import": "^2.25.4",
35
- "mocha": "^9.1.3",
36
34
  "nightwatch": "^2.1.7"
37
35
  },
38
- "bin":{
39
- "webship-js-dl" : "./bin/webship-js-dl.js",
40
- "webship-js-di" : "./bin/webship-js-di.js"
41
- }
36
+ "devDependencies": {
37
+ "chromedriver": "*",
38
+ "geckodriver": "*"
39
+ },
40
+ "files": [
41
+ "bin/"
42
+ ],
43
+ "bin": {
44
+ "steplist": "./bin/steplist.js"
45
+ }
42
46
  }
@@ -1,102 +0,0 @@
1
- version: 2.1
2
- defaults: &defaults
3
- docker:
4
- - image: cimg/base:stable-20.04
5
- auth:
6
- username: mydockerhub-user
7
- password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
8
- commands:
9
- webship-js-build:
10
- steps:
11
- - checkout
12
- ## Usefull must have utils.
13
- - run:
14
- name: Usefull must have utils
15
- command: |
16
- sudo apt -qq update
17
- sudo apt -qqy upgrade
18
- sudo apt -yqq install vim links lynx git diffutils htop curl wget p7zip-full unzip zip sed gcc g++ make libfreetype6-dev libaio1 libaio-dev libonig-dev libpng-dev
19
- sudo apt -yqq install xvfb libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 libnss3
20
-
21
- ## Configure and run the virtual display.
22
- - run:
23
- name: Configure and run the virtual display.
24
- command: Xvfb -ac :99 -screen 0 1600x1200x24 > /dev/null 2>&1
25
- background: true
26
-
27
- ## Install node js, npm, yarn, and gulp
28
- - run:
29
- name: Install node js
30
- command: |
31
- curl -sL https://deb.nodesource.com/setup_16.x | sudo bash -
32
- sudo apt install -y nodejs
33
- sudo npm install -g yarn
34
-
35
- ## Install Java.
36
- - run:
37
- name: Install Java
38
- command: |
39
- sudo apt update
40
- sudo apt install -y openjdk-11-jre openjdk-11-jre-headless openjdk-11-jdk openjdk-11-jdk-headless
41
-
42
- ## Install/Update Google Chrome browser.
43
- - run:
44
- name: Install/Update Google Chrome browser
45
- command: |
46
- sudo apt-get install libappindicator1 fonts-liberation libgbm1 libgtk-3-0 xdg-utils
47
- export CHROME_BIN=/usr/bin/google-chrome
48
- wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
49
- sudo dpkg -i google-chrome-stable_current_amd64.deb
50
- rm google-chrome-stable_current_amd64.deb
51
-
52
- ## Install/Update Chrome Driver.
53
- - run:
54
- name: Install/Update Chrome Driver
55
- command: |
56
- CHROME_DRIVER_VERSION=$(wget -qO- chromedriver.storage.googleapis.com/LATEST_RELEASE);
57
- echo $CHROME_DRIVER_VERSION;
58
- wget http://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip
59
- unzip chromedriver_linux64.zip
60
- sudo chmod +x chromedriver
61
- sudo mv -f chromedriver /usr/bin/
62
- rm chromedriver_linux64.zip
63
-
64
- ## Setup Apache2
65
- - run:
66
- name: Setup Apache2
67
- command: |
68
- sudo apt install -yqq apache2
69
-
70
- ## Run Selenium Standalone server.
71
- - run:
72
- name: Run Selenium Standalone server
73
- command: |
74
- if [[ ! -f /home/circleci/selenium-server-standalone-3.141.59.jar ]]; then wget -O /home/circleci/selenium-server-standalone-3.141.59.jar https://github.com/SeleniumHQ/selenium/releases/download/selenium-3.141.59/selenium-server-standalone-3.141.59.jar; fi
75
- cd /home/circleci/
76
- java -jar selenium-server-standalone-3.141.59.jar -port 4444
77
- background: true
78
-
79
- jobs:
80
- webship-js-testing:
81
- <<: *defaults
82
- steps:
83
- - webship-js-build
84
- ## Automated Functional Acceptance Testing
85
- - run:
86
- name: Automated Functional Acceptance Testing
87
- no_output_timeout: 30m
88
- command: |
89
- yarn install
90
- yarn test
91
-
92
- workflows:
93
- version: 2
94
- webship-js-workflow:
95
- jobs:
96
- - webship-js-testing:
97
- filters:
98
- tags:
99
- only: /^1.0.*/
100
- branches:
101
- only: /^1.0.x/
102
-
package/.eslintignore DELETED
@@ -1,4 +0,0 @@
1
- node_modules
2
- ./node_modules
3
- */node_modules
4
- nightwatch.conf.js
package/.eslintrc.json DELETED
@@ -1,34 +0,0 @@
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
- }
@@ -1,28 +0,0 @@
1
- name: Github Actions
2
-
3
- on: [push]
4
-
5
- jobs:
6
- build:
7
-
8
- runs-on: ubuntu-latest
9
-
10
- env:
11
- TEST_BASE_URL: https://webship.co
12
- SELENIUM_HOST: http://selenium:4444/wd/hub
13
-
14
- services:
15
- selenium:
16
- image: selenium/standalone-chrome
17
- # options: --health-cmd "curl http://selenium:4444" --health-interval=5s
18
- ports:
19
- - 4444:4444
20
-
21
- steps:
22
- - uses: actions/checkout@v3
23
- - name: Use Node.js
24
- uses: actions/setup-node@v3
25
- with:
26
- node-version: '16.x'
27
- - run: yarn install
28
- - run: yarn test
package/.gitlab-ci.yml DELETED
@@ -1,51 +0,0 @@
1
- image: node:16
2
-
3
- stages:
4
- - check
5
-
6
- check:
7
- stage: check
8
- script:
9
- # Dependencies for chromedriver, https://gist.github.com/mikesmullin/2636776#gistcomment-1742414
10
- # Otherwise we get this error: "error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory"
11
- - apt-get update -q -y
12
- - apt-get --yes install libnss3
13
- - apt-get --yes install libgconf-2-4
14
-
15
- # Install chrome
16
- # Based off of
17
- # - https://gitlab.com/gitlab-org/gitlab-build-images/blob/9dadb28021f15913a49897126a0cd6ab0149e44f/scripts/install-chrome
18
- # - https://askubuntu.com/a/510186/196148
19
- #
20
- # Add key
21
- - curl -sS -L https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
22
- # Add repo
23
- - echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
24
- - apt-get update -q -y
25
- - apt-get install -y google-chrome-stable
26
-
27
- - npm install chromedriver -g
28
- - npm install nightwatch -g
29
- - npm install https://gitlab.com/gitlab-org/gitlab-selenium-server.git -g
30
- - which chromedriver
31
- # The `&` at the end causes it to run in the background and not block the following commands
32
- - nohup chromedriver --port=4444 --url-base=wd/hub &
33
- - nohup gitlab-selenium-server &
34
- # Install cucumber & pretty formatter .
35
- - npm i @cucumber/cucumber
36
- - npm i @cucumber/pretty-formatter
37
-
38
- # Run your tests
39
- - npm test
40
-
41
- # Show the logs for the GitLab Selenium Server service
42
- - mkdir -p selenium/ && curl -s http://localhost:4545/logs.tar.gz | tar -xvzf - -C selenium/
43
- - mkdir -p selenium/ && curl http://localhost:4545/server-log --output selenium/server-log.txt
44
- artifacts:
45
- when: always
46
- paths:
47
- - selenium/
48
- variables:
49
- SELENIUM_REMOTE_URL: http://localhost:4545/wd/hub
50
- GITLAB_TARGET_SELENIUM_REMOTE_URL: http://localhost:4444/wd/hub
51
-
package/.travis-ci.yml DELETED
@@ -1,27 +0,0 @@
1
- dist: trusty
2
- language: java
3
-
4
- jdk:
5
- - openjdk-11-jre
6
-
7
- before_script:
8
- - docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-firefox:4.0.0-rc-1-prerelease-20210618
9
- - docker ps
10
-
11
- script:
12
- - mvn clean install -DsuiteXmlFile=testng.xml -Dbrowser=GRID_FIREFOX -DgridHubURL=http://localhost:4444/wd/hub
13
-
14
- cache:
15
- directories:
16
- - .autoconf
17
- - $HOME/.m2
18
-
19
- deploy:
20
- provider: releases
21
- api_key: ${api_key}
22
- skip_cleanup: true
23
- file: [ "target/surefire-reports/emailable-report.html",
24
- "target/surefire-reports/index.html" ]
25
- on:
26
- all_branches: true
27
- tags: false
@@ -1,145 +0,0 @@
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
- });