@zohodesk/testinglibrary 0.0.5-exp.27 → 0.0.5-exp.29

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.
@@ -61,7 +61,7 @@ function getAuthFilePath(filePath) {
61
61
  if ((0, _fs.existsSync)(filePath)) {
62
62
  return filePath;
63
63
  } else {
64
- _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Ensure cookies present in ${filePath}. Authetication file not Exist ...`);
64
+ return {};
65
65
  }
66
66
  } catch (err) {
67
67
  _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Founded Path - ${filePath} Authetication file not Exist ...`);
@@ -96,7 +96,45 @@ function generateSpecFileContent({
96
96
  }
97
97
  return specContent;
98
98
  }
99
- function specFileGenerator(filePath) {
99
+ function updateExistingSpecFile({
100
+ feature
101
+ }, specFile) {
102
+ if (feature && feature.scenarios && feature.scenarios.length > 0) {
103
+ let specFileCode = _fs.default.readFileSync(specFile, 'utf8');
104
+ feature.scenarios.forEach(({
105
+ name,
106
+ steps
107
+ }) => {
108
+ const scenarioComment = `/*\n${steps.map(step => ` ** ${step}`).join('\n')}\n */`;
109
+ const testNamePattern = new RegExp(`test\\('${name}',`, 'g');
110
+ const testNameMatches = specFileCode.match(testNamePattern);
111
+ if (testNameMatches) {
112
+ testNameMatches.forEach(match => {
113
+ const startIdx = specFileCode.indexOf(match);
114
+
115
+ // Find the index of the comment above the test block
116
+ const commentStartIdx = specFileCode.lastIndexOf('/*', startIdx);
117
+ const commentEndIdx = specFileCode.lastIndexOf('*/', startIdx);
118
+ if (commentStartIdx >= 0 && commentEndIdx > commentStartIdx) {
119
+ // Remove the old comment above the test block
120
+ specFileCode = specFileCode.slice(0, commentStartIdx) + scenarioComment + specFileCode.slice(commentEndIdx + 2);
121
+ }
122
+ });
123
+ } else {
124
+ // Create a new test block if the test name is not found
125
+ const newTestBlock = ` ${scenarioComment}\n test('${name}', () => {\n // Your implementation here\n });\n\n\n`;
126
+ // Locate the closest describe block for the new test
127
+ const lastDescribeEndIdx = specFileCode.lastIndexOf('});');
128
+ specFileCode = specFileCode.slice(0, lastDescribeEndIdx) + newTestBlock + specFileCode.slice(lastDescribeEndIdx);
129
+ }
130
+ });
131
+
132
+ // Save the updated code back to the spec file
133
+ _fs.default.writeFileSync(specFile, specFileCode, 'utf8');
134
+ _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Spec file updated successfully');
135
+ }
136
+ }
137
+ function specFileGenerator(filePath, isUpdate) {
100
138
  _logger.Logger.log(_logger.Logger.INFO_TYPE, `Generating spec file using file ${filePath}`);
101
139
  // Read the Gherkin feature file
102
140
  let {
@@ -111,12 +149,16 @@ function specFileGenerator(filePath) {
111
149
  const parsedFeature = parseFeature(data);
112
150
  let specFilePath = filePath.replace(/\.feature$/, '.spec.js');
113
151
  if (filePath.includes(`${featureFilesFolder}`)) {
114
- specFilePath = specFilePath.replace(`/${featureFilesFolder}/`, `${stepDefinitionsFolder}`);
152
+ specFilePath = specFilePath.replace(`/${featureFilesFolder}/`, `/${stepDefinitionsFolder}/`);
115
153
  } else {
116
154
  specFilePath = specFilePath.replace('./', `${stepDefinitionsFolder}`);
117
155
  }
118
156
  if ((0, _fileUtils.checkIfFileExists)(specFilePath)) {
119
- _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'File Already exists. Make sure to either delete or pass --update option true');
157
+ if (isUpdate) {
158
+ updateExistingSpecFile(parsedFeature, specFilePath);
159
+ } else {
160
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'File Already exists. Make sure to either delete or pass --update option true');
161
+ }
120
162
  return;
121
163
  }
122
164
 
@@ -137,9 +179,12 @@ function specFileGenerator(filePath) {
137
179
  }
138
180
  function generateSpecCodeForFeatureFile(options) {
139
181
  let cliObj = (0, _cliArgsToObject.cliArgsToObject)(options);
140
- let featureFilePath = cliObj.featureFile;
182
+ let {
183
+ featureFile: featureFilePath = null,
184
+ update = false
185
+ } = cliObj;
141
186
  if (featureFilePath) {
142
- specFileGenerator(_path.default.join(process.cwd(), './', featureFilePath));
187
+ specFileGenerator(_path.default.join(process.cwd(), './', featureFilePath), update);
143
188
  } else {
144
189
  _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Need option --featureFile to run this command');
145
190
  }
@@ -1,17 +1,21 @@
1
1
  {
2
2
  "dev": {
3
3
  "domain": "https://desk.localzoho.com/agent",
4
- "username": "your-username",
5
- "password": "your-password"
4
+ "orgName": "org-name",
5
+ "deptName": "dept-name",
6
+ "moduleName": "module-name",
7
+ "devURL": "Provide your devURL here"
6
8
  },
7
9
  "prod": {
8
10
  "domain": "https://desk.localzoho.com/agent",
9
- "username": "your-username",
10
- "password": "your-password"
11
+ "orgName": "org-name",
12
+ "deptName": "dept-name",
13
+ "moduleName": "module-name"
11
14
  },
12
15
  "k8test": {
13
16
  "domain": "https://desk.localzoho.com/agent",
14
- "username": "your-username",
15
- "password": "your-password"
17
+ "orgName": "org-name",
18
+ "deptName": "dept-name",
19
+ "moduleName": "module-name"
16
20
  }
17
21
  }
package/changelog.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Framework that abstracts the configuration for playwright and Jest
4
4
 
5
+ # 0.0.5-exp.28
6
+
7
+ - Bug fix while creating spec file
8
+
9
+ # 0.0.5-exp.29
10
+
11
+ - Added --update option to the generateSpecFile command to update the spec file
12
+
5
13
  # 0.0.5-exp.27
6
14
 
7
15
  - Added config for feature files and step definitions folder name
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/testinglibrary",
3
- "version": "0.0.5-exp.27",
3
+ "version": "0.0.5-exp.29",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {