@@ -40,7 +40,10 @@ export class DynamicVitestGenerator {
4040 const testSuite = ViewDefinitionParser . parseTestSuite ( testSuiteJson ) ;
4141 const suiteName = testSuite . title ;
4242
43- this . generateTestSuite ( testSuite , suiteName ) ;
43+ // Extract filename for report (e.g., "basic.json" from "/path/to/basic.json")
44+ const fileName = filePath . split ( "/" ) . pop ( ) ?? filePath ;
45+
46+ this . generateTestSuite ( testSuite , suiteName , fileName ) ;
4447 }
4548
4649 /**
@@ -49,6 +52,7 @@ export class DynamicVitestGenerator {
4952 generateTestsFromDirectory ( directoryPath : string ) : void {
5053 const files = readdirSync ( directoryPath )
5154 . filter ( ( file ) => file . endsWith ( ".json" ) )
55+ . sort ( ) // Sort to ensure consistent ordering
5256 . map ( ( file ) => join ( directoryPath , file ) ) ;
5357
5458 for ( const filePath of files ) {
@@ -58,8 +62,16 @@ export class DynamicVitestGenerator {
5862
5963 /**
6064 * Generate a Vitest test suite for a SQL-on-FHIR test definition.
65+ *
66+ * @param testSuite The test suite definition
67+ * @param suiteName The display name for Vitest (e.g., "basic")
68+ * @param reportFileName The filename for the test report (e.g., "basic.json")
6169 */
62- private generateTestSuite ( testSuite : TestSuite , suiteName : string ) : void {
70+ private generateTestSuite (
71+ testSuite : TestSuite ,
72+ suiteName : string ,
73+ reportFileName : string ,
74+ ) : void {
6375 const suiteResults : TestReportEntry [ ] = [ ] ;
6476
6577 describe ( suiteName , ( ) => {
@@ -70,10 +82,10 @@ export class DynamicVitestGenerator {
7082 afterAll ( async ( ) => {
7183 await cleanupDatabase ( ) ;
7284
73- // Store results for report generation
85+ // Store results for report generation using the filename as the key
7486 if ( typeof global !== "undefined" ) {
7587 global . testResults = global . testResults ?? { } ;
76- global . testResults [ suiteName ] = { tests : suiteResults } ;
88+ global . testResults [ reportFileName ] = { tests : suiteResults } ;
7789 }
7890 } ) ;
7991
@@ -131,11 +143,18 @@ export class DynamicVitestGenerator {
131143 await executeViewDefinition ( testCase . view , testId ) ;
132144
133145 // If we get here, the test should have failed but didn't
134- suiteResults . push ( { name : testName , result : { passed : false } } ) ;
135- expect . fail ( "Expected an error but the test passed" ) ;
146+ const errorMessage = "Expected an error but the test passed" ;
147+ suiteResults . push ( {
148+ name : testCase . title , // Use plain title for report
149+ result : { passed : false , error : errorMessage } ,
150+ } ) ;
151+ expect . fail ( errorMessage ) ;
136152 } catch {
137153 // Test passed - we expected an error
138- suiteResults . push ( { name : testName , result : { passed : true } } ) ;
154+ suiteResults . push ( {
155+ name : testCase . title , // Use plain title for report
156+ result : { passed : true } ,
157+ } ) ;
139158 } finally {
140159 await cleanupTestData ( testId ) ;
141160 }
@@ -163,17 +182,28 @@ export class DynamicVitestGenerator {
163182 result . columns ,
164183 ) ;
165184
166- suiteResults . push ( { name : testName , result : { passed } } ) ;
167-
168185 if ( ! passed ) {
169- expect . fail (
170- `Results don't match. Expected: ${ JSON . stringify ( testCase . expect ) } , Actual: ${ JSON . stringify ( result . results ) } ` ,
171- ) ;
186+ const errorMessage = `Results don't match. Expected: ${ JSON . stringify ( testCase . expect ) } , Actual: ${ JSON . stringify ( result . results ) } ` ;
187+ suiteResults . push ( {
188+ name : testCase . title , // Use plain title for report
189+ result : { passed : false , error : errorMessage } ,
190+ } ) ;
191+ expect . fail ( errorMessage ) ;
192+ } else {
193+ suiteResults . push ( {
194+ name : testCase . title , // Use plain title for report
195+ result : { passed : true } ,
196+ } ) ;
172197 }
173198
174199 expect ( passed ) . toBe ( true ) ;
175200 } catch ( error ) {
176- suiteResults . push ( { name : testName , result : { passed : false } } ) ;
201+ const errorMessage =
202+ error instanceof Error ? error . message : String ( error ) ;
203+ suiteResults . push ( {
204+ name : testCase . title , // Use plain title for report
205+ result : { passed : false , error : errorMessage } ,
206+ } ) ;
177207 throw error ;
178208 } finally {
179209 await cleanupTestData ( testId ) ;
0 commit comments