Skip to content

Commit

Permalink
chore: optimize report path
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw committed Jul 29, 2024
1 parent 9088196 commit bb0cc0a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/web-integration/src/playwright/reporter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class MidSceneReporter implements Reporter {
generateTestData(testDataList);
console.log(
'\x1b[32m%s\x1b[0m',
`The report is generated successfully. Run the "node ./midscene-report/index.js" command to start the report`,
`The report is generated successfully. Run the "node ./midscene_run/midscene-report/index.js" command to start the report`,
);
}
}
Expand Down
34 changes: 33 additions & 1 deletion packages/web-integration/src/playwright/reporter/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function generateTestData(testDataList: Array<TestData>) {
}
}, [] as Array<TestData>);
const projectDir = process.cwd();
const reportDir = path.join(projectDir, 'midscene-report');
const reportDir = path.join(projectDir, 'midscene_run', 'midscene-report');

// Create a report folder
if (!fs.existsSync(reportDir)) {
Expand Down Expand Up @@ -87,4 +87,36 @@ export function generateTestData(testDataList: Array<TestData>) {
} catch (err) {
console.error('An error occurred:', err);
}

// add static data
modifyRoutesJson(reportDir, testDataList);
}

function modifyRoutesJson(reportDir: string, testDataList: Array<TestData>) {
const filePath = path.join(reportDir, 'route.json');
try {
const data = fs.readFileSync(filePath, 'utf8');

const newPaths = testDataList.map((testData) => {
const fileName = testData.dumpPath?.split('/').pop();
return {
urlPath: `/${fileName}`,
isSPA: true,
isSSR: false,
entryPath: `public/${fileName}`,
};
});

const jsonData = JSON.parse(data);

// Insert the new path data into the js, OS and n structure
jsonData.routes.push(...newPaths);

// Write the updated js on data back to the file
fs.writeFileSync(filePath, JSON.stringify(jsonData, null, 2), 'utf8');

console.log('文件更新成功');
} catch (err) {
console.error('操作失败:', err);
}
}

0 comments on commit bb0cc0a

Please sign in to comment.