@@ -12,15 +12,15 @@ import { cheatsheetBodyClasses } from "@cursorless/cheatsheet";
12
12
13
13
const fixturesDir = path . join ( "../" , "../" , "data" , "example-files" ) ;
14
14
15
- async function loadYamlFiles ( dir : string , selectedFiles ?: string [ ] ) {
15
+ async function loadYamlFiles ( dir : string , allowList ?: string [ ] ) {
16
16
const directoryPath = path . join ( process . cwd ( ) , dir ) ;
17
17
const files = fs . readdirSync ( directoryPath ) ;
18
18
const data : any [ ] = [ ] ;
19
19
20
20
files . forEach ( ( file ) => {
21
21
if (
22
22
path . extname ( file ) === ".yml" &&
23
- ( ! selectedFiles || selectedFiles . includes ( file ) )
23
+ ( ! allowList || allowList . includes ( file ) )
24
24
) {
25
25
try {
26
26
const filePath = path . join ( directoryPath , file ) ;
@@ -37,15 +37,31 @@ async function loadYamlFiles(dir: string, selectedFiles?: string[]) {
37
37
return data ;
38
38
}
39
39
40
- // See https://github.com/vercel/next.js/discussions/12325#discussioncomment-1116108
41
- export async function getStaticProps ( ) {
42
- const dataActions = await loadYamlFiles ( fixturesDir , testSelectedFiles ) ;
40
+ // Change argument to a single object for loadAndProcessFixtures
41
+ interface LoadAndProcessFixturesOptions {
42
+ fixturesDir : string ;
43
+ allowList ?: string [ ] ;
44
+ }
43
45
46
+ /**
47
+ * Loads YAML test case files from a directory, processes them into fixtures, and returns an array of processed test case data.
48
+ * Optionally filters which files to load using an allow list.
49
+ *
50
+ * @param {Object } options - Options for loading and processing fixtures.
51
+ * @param {string } options.fixturesDir - Directory containing YAML fixture files.
52
+ * @param {string[]= } options.allowList - Optional list of filenames to include.
53
+ * @returns {Promise<any[]> } Array of processed test case data, each with a `raw` property containing the original YAML object.
54
+ */
55
+ async function loadAndProcessFixtures ( {
56
+ fixturesDir,
57
+ allowList,
58
+ } : LoadAndProcessFixturesOptions ) {
59
+ const dataActions = await loadYamlFiles ( fixturesDir , allowList ) ;
44
60
const data_errors : any [ ] = [ ] ;
45
61
46
62
const data = (
47
63
await Promise . all (
48
- [ ... dataActions ] . map ( async ( val ) => {
64
+ dataActions . map ( async ( val ) => {
49
65
try {
50
66
const fixture = await loadTestCaseFixture ( val ) ;
51
67
return { ...fixture , raw : val } ;
@@ -56,12 +72,21 @@ export async function getStaticProps() {
56
72
}
57
73
} ) ,
58
74
)
59
- ) . filter ( ( test ) => test !== undefined ) ;
75
+ ) . filter ( ( test ) => test != null ) ;
60
76
61
77
if ( data_errors . length > 0 ) {
62
78
console . error ( "data errors:" , data_errors ) ;
63
79
}
64
80
81
+ return data ;
82
+ }
83
+
84
+ // See https://github.com/vercel/next.js/discussions/12325#discussioncomment-1116108
85
+ export async function getStaticProps ( ) {
86
+ const data = await loadAndProcessFixtures ( {
87
+ fixturesDir,
88
+ allowList : testSelectedFiles ,
89
+ } ) ;
65
90
return { props : { data, bodyClasses : cheatsheetBodyClasses } } ;
66
91
}
67
92
0 commit comments