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