@zohodesk/testinglibrary 0.0.5-exp.28 → 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.
- package/build/parser/parser.js +49 -4
- package/changelog.md +4 -0
- package/package.json +1 -1
package/build/parser/parser.js
CHANGED
|
@@ -96,7 +96,45 @@ function generateSpecFileContent({
|
|
|
96
96
|
}
|
|
97
97
|
return specContent;
|
|
98
98
|
}
|
|
99
|
-
function
|
|
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 {
|
|
@@ -116,7 +154,11 @@ function specFileGenerator(filePath) {
|
|
|
116
154
|
specFilePath = specFilePath.replace('./', `${stepDefinitionsFolder}`);
|
|
117
155
|
}
|
|
118
156
|
if ((0, _fileUtils.checkIfFileExists)(specFilePath)) {
|
|
119
|
-
|
|
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
|
|
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
|
}
|
package/changelog.md
CHANGED