@@ -14,7 +14,7 @@ export function generateTestData(testDataList: Array<TestData>) {
14
14
}
15
15
} , [ ] as Array < TestData > ) ;
16
16
const projectDir = process . cwd ( ) ;
17
- const reportDir = path . join ( projectDir , 'midscene-report' ) ;
17
+ const reportDir = path . join ( projectDir , 'midscene_run' , ' midscene-report') ;
18
18
19
19
// Create a report folder
20
20
if ( ! fs . existsSync ( reportDir ) ) {
@@ -87,4 +87,36 @@ export function generateTestData(testDataList: Array<TestData>) {
87
87
} catch ( err ) {
88
88
console . error ( 'An error occurred:' , err ) ;
89
89
}
90
+
91
+ // add static data
92
+ modifyRoutesJson ( reportDir , testDataList ) ;
93
+ }
94
+
95
+ function modifyRoutesJson ( reportDir : string , testDataList : Array < TestData > ) {
96
+ const filePath = path . join ( reportDir , 'route.json' ) ;
97
+ try {
98
+ const data = fs . readFileSync ( filePath , 'utf8' ) ;
99
+
100
+ const newPaths = testDataList . map ( ( testData ) => {
101
+ const fileName = testData . dumpPath ?. split ( '/' ) . pop ( ) ;
102
+ return {
103
+ urlPath : `/${ fileName } ` ,
104
+ isSPA : true ,
105
+ isSSR : false ,
106
+ entryPath : `public/${ fileName } ` ,
107
+ } ;
108
+ } ) ;
109
+
110
+ const jsonData = JSON . parse ( data ) ;
111
+
112
+ // Insert the new path data into the js, OS and n structure
113
+ jsonData . routes . push ( ...newPaths ) ;
114
+
115
+ // Write the updated js on data back to the file
116
+ fs . writeFileSync ( filePath , JSON . stringify ( jsonData , null , 2 ) , 'utf8' ) ;
117
+
118
+ console . log ( '文件更新成功' ) ;
119
+ } catch ( err ) {
120
+ console . error ( '操作失败:' , err ) ;
121
+ }
90
122
}
0 commit comments