@zohodesk/testinglibrary 0.0.5-exp.19 → 0.0.5-exp.20
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 +7 -8
- package/build/parser/verifier.js +9 -19
- package/build/utils/fileUtils.js +30 -2
- package/build/utils/logger.js +3 -1
- package/changelog.md +5 -0
- package/package.json +1 -1
package/build/parser/parser.js
CHANGED
|
@@ -54,7 +54,7 @@ function parseFeature(featureContent) {
|
|
|
54
54
|
});
|
|
55
55
|
} else if (insideExampleTable && trimmedLine.startsWith('|')) {
|
|
56
56
|
if (!isHeaderRow) {
|
|
57
|
-
const exampleRow = trimmedLine.split('|').map(cell => cell.trim());
|
|
57
|
+
const exampleRow = trimmedLine.split('|').filter(cell => cell !== "").map(cell => cell.trim());
|
|
58
58
|
if (exampleRow.length === currentScenario.examples[0].tableHeader.length) {
|
|
59
59
|
currentScenario.examples[0].tableRows.push(exampleRow);
|
|
60
60
|
}
|
|
@@ -121,13 +121,12 @@ function specFileGenerator(filePath) {
|
|
|
121
121
|
const specFileContent = generateSpecFileContent(parsedFeature);
|
|
122
122
|
|
|
123
123
|
// Write the spec file content to a new file
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
});
|
|
124
|
+
try {
|
|
125
|
+
(0, _fileUtils.writeFileContents)(specFilePath, specFileContent);
|
|
126
|
+
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Spec file generated successfully.');
|
|
127
|
+
} catch (writeErr) {
|
|
128
|
+
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Error writing the spec file: ${writeErr}`);
|
|
129
|
+
}
|
|
131
130
|
}
|
|
132
131
|
});
|
|
133
132
|
}
|
package/build/parser/verifier.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
var _path = _interopRequireDefault(require("path"));
|
|
5
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
6
5
|
var _fastGlob = _interopRequireDefault(require("fast-glob"));
|
|
7
6
|
var _parser = require("./parser");
|
|
8
7
|
var _logger = require("../utils/logger");
|
|
@@ -18,7 +17,7 @@ const featurePattern = _path.default.join(process.cwd(), directoryPath, '**/*.fe
|
|
|
18
17
|
function verifyIfMultipleStepsExists(steps) {
|
|
19
18
|
let isMultipleStepsFound = false;
|
|
20
19
|
Object.keys(steps).map(step => {
|
|
21
|
-
if (steps[step].length >
|
|
20
|
+
if (steps[step].length > 1) {
|
|
22
21
|
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Multiple Steps Found for ${step} \n`);
|
|
23
22
|
steps[step].forEach(fileName => {
|
|
24
23
|
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Files: \n ${fileName} \n`);
|
|
@@ -31,22 +30,13 @@ function verifyIfMultipleStepsExists(steps) {
|
|
|
31
30
|
}
|
|
32
31
|
function extractExamplesToSeperateFile(examples, scenarioIndex, filePath) {
|
|
33
32
|
let exampleFileContent = `export const scenario${scenarioIndex} = ${JSON.stringify(examples, null, 2)}`;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (err) {
|
|
38
|
-
throw new Error(`Error appending or creating the test data file: ${filePath}`);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function deleteExamplesFile(filePath) {
|
|
43
|
-
// Check if the file exists
|
|
44
|
-
if ((0, _fileUtils.checkIfFileExists)(filePath)) {
|
|
45
|
-
_fs.default.unlink(filePath, err => {
|
|
46
|
-
if (err) {
|
|
47
|
-
throw new Error(`Error while deleting the test data file: ${filePath}`);
|
|
48
|
-
}
|
|
33
|
+
try {
|
|
34
|
+
(0, _fileUtils.writeFileContents)(filePath, exampleFileContent, {
|
|
35
|
+
flag: 'a'
|
|
49
36
|
});
|
|
37
|
+
} catch (err) {
|
|
38
|
+
_logger.Logger.error(err);
|
|
39
|
+
throw new Error(`Error appending or creating the test data file: ${filePath}`);
|
|
50
40
|
}
|
|
51
41
|
}
|
|
52
42
|
function verifyFeatureFileWithSpecFile() {
|
|
@@ -81,8 +71,8 @@ function verifyFeatureFileWithSpecFile() {
|
|
|
81
71
|
const scenarioName = scenario.name;
|
|
82
72
|
const scenarioExamples = scenario.examples;
|
|
83
73
|
|
|
84
|
-
// Examples to test data conversion
|
|
85
|
-
|
|
74
|
+
// Examples to test data conversion. we are deleting the existing test data file and create a new file.
|
|
75
|
+
(0, _fileUtils.deleteFile)(testDataFilePath);
|
|
86
76
|
extractExamplesToSeperateFile(scenarioExamples, i, testDataFilePath);
|
|
87
77
|
|
|
88
78
|
// spec file check
|
package/build/utils/fileUtils.js
CHANGED
|
@@ -5,7 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.checkIfFileExists = checkIfFileExists;
|
|
8
|
+
exports.deleteFile = deleteFile;
|
|
8
9
|
exports.readFileContents = readFileContents;
|
|
10
|
+
exports.writeFileContents = writeFileContents;
|
|
9
11
|
var _fs = _interopRequireDefault(require("fs"));
|
|
10
12
|
function checkIfFileExists(file) {
|
|
11
13
|
try {
|
|
@@ -15,11 +17,37 @@ function checkIfFileExists(file) {
|
|
|
15
17
|
return false;
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
|
-
function readFileContents(
|
|
20
|
+
function readFileContents(filePath) {
|
|
19
21
|
try {
|
|
20
|
-
let fileContents = _fs.default.readFileSync(
|
|
22
|
+
let fileContents = _fs.default.readFileSync(filePath, 'utf-8');
|
|
21
23
|
return fileContents;
|
|
22
24
|
} catch (err) {
|
|
23
25
|
return null;
|
|
24
26
|
}
|
|
27
|
+
}
|
|
28
|
+
function writeFileContents(filePath, content, writeOptions = {}) {
|
|
29
|
+
let filePaths = filePath.split('/');
|
|
30
|
+
let fileName = filePaths.pop();
|
|
31
|
+
let directoryPath = filePaths.join('/');
|
|
32
|
+
|
|
33
|
+
// Check if the directory exists
|
|
34
|
+
if (!_fs.default.existsSync(directoryPath)) {
|
|
35
|
+
_fs.default.mkdirSync(directoryPath, {
|
|
36
|
+
recursive: true
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
_fs.default.writeFileSync(`${directoryPath}/${fileName}`, content, writeOptions);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
throw new Error(err);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function deleteFile(filePath) {
|
|
46
|
+
if (checkIfFileExists(filePath)) {
|
|
47
|
+
_fs.default.unlink(filePath, err => {
|
|
48
|
+
if (err) {
|
|
49
|
+
throw new Error(`Error while deleting the test data file: ${filePath}`);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
25
53
|
}
|
package/build/utils/logger.js
CHANGED
package/changelog.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## Framework that abstracts the configuration for playwright and Jest
|
|
4
4
|
|
|
5
|
+
# 0.0.5-exp.20
|
|
6
|
+
|
|
7
|
+
- Fix error if directory does not exist while writing file
|
|
8
|
+
- Fixed Multiple steps found error
|
|
9
|
+
|
|
5
10
|
# 0.0.5-exp.19
|
|
6
11
|
|
|
7
12
|
- Added Feature to throw error if Multiple steps found
|