Skip to content

Commit bb0cc0a

Browse files
committed
chore: optimize report path
1 parent 9088196 commit bb0cc0a

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

packages/web-integration/src/playwright/reporter/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class MidSceneReporter implements Reporter {
5555
generateTestData(testDataList);
5656
console.log(
5757
'\x1b[32m%s\x1b[0m',
58-
`The report is generated successfully. Run the "node ./midscene-report/index.js" command to start the report`,
58+
`The report is generated successfully. Run the "node ./midscene_run/midscene-report/index.js" command to start the report`,
5959
);
6060
}
6161
}

packages/web-integration/src/playwright/reporter/util.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function generateTestData(testDataList: Array<TestData>) {
1414
}
1515
}, [] as Array<TestData>);
1616
const projectDir = process.cwd();
17-
const reportDir = path.join(projectDir, 'midscene-report');
17+
const reportDir = path.join(projectDir, 'midscene_run', 'midscene-report');
1818

1919
// Create a report folder
2020
if (!fs.existsSync(reportDir)) {
@@ -87,4 +87,36 @@ export function generateTestData(testDataList: Array<TestData>) {
8787
} catch (err) {
8888
console.error('An error occurred:', err);
8989
}
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+
}
90122
}

0 commit comments

Comments
 (0)