Skip to content

Commit 6e51f42

Browse files
authored
Add validate feature files JS to master
1 parent c3dc94c commit 6e51f42

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

validate_feature_files.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// validate-feature-files.js
2+
const fs = require('fs');
3+
const path = require('path');
4+
const parser = require("gherkin-parse");
5+
const Glob = require('glob-fs');
6+
7+
// Create a glob-fs instance
8+
const glob = Glob({ cwd: __dirname }); // Set the current working directory
9+
10+
// Define your base directory for globbing
11+
const BASE_DIR = path.join(__dirname, 'redcap_rsvc'); // Base directory path
12+
const GLOB_PATTERN = '**/*.feature'; // Glob pattern for .feature files
13+
14+
// Function to validate a single feature file
15+
function validateFeatureFile(filePath) {
16+
try {
17+
parser.convertFeatureFileToJSON(filePath)
18+
} catch (error) {
19+
console.error(`${filePath} is invalid - contains PARSE ERRORS.`);
20+
}
21+
}
22+
23+
// Debugging: Log the start of glob search
24+
//console.log('Starting glob search with pattern:', GLOB_PATTERN);
25+
26+
// Find all feature files matching the glob pattern
27+
const files = glob.readdirSync(`${GLOB_PATTERN}`, { cwd: BASE_DIR });
28+
29+
// Debugging: Log the files found
30+
//console.log('Found feature files:', files);
31+
32+
// Check if any files were found
33+
if (files.length === 0) {
34+
console.log('No .feature files found matching the pattern.');
35+
} else {
36+
// Validate each found feature file
37+
files.forEach(file => {
38+
const filePath = path.join(BASE_DIR, file); // Get full file path
39+
validateFeatureFile(filePath);
40+
});
41+
}

0 commit comments

Comments
 (0)