Skip to content

Commit d2c5491

Browse files
authored
fix(report): fixed report path issues and static resource failure to load (#16)
* chore: optimize test case * chore: optimize test case * chore: optimize report path * chore: optimize report path * chore: delete unless log
1 parent 855f740 commit d2c5491

File tree

5 files changed

+119
-86
lines changed

5 files changed

+119
-86
lines changed

packages/visualizer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@modern-js/plugin-module-doc": "^2.33.1",
3434
"@types/react": "18.3.3",
3535
"@types/react-dom": "18.3.0",
36+
"@types/node": "^18.0.0",
3637
"react": "~18.2.0",
3738
"react-dom": "~18.2.0",
3839
"rimraf": "~3.0.2",

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

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ const groupAndCaseForTest = (testInfo: TestInfo) => {
1313

1414
if (titlePath.length > 1) {
1515
caseName = titlePath.pop()!;
16-
groupName = titlePath.join(' > ');
16+
groupName = `${titlePath.join(' > ')}:${testInfo.line}`;
1717
} else if (titlePath.length === 1) {
1818
caseName = titlePath[0];
19-
groupName = caseName;
19+
groupName = `${caseName}:${testInfo.line}`;
2020
} else {
2121
caseName = 'unnamed';
2222
groupName = 'unnamed';
@@ -32,63 +32,62 @@ export const PlaywrightAiFixture = () => {
3232
if (!idForPage) {
3333
idForPage = randomUUID();
3434
(page as any)[midSceneAgentKeyId] = idForPage;
35-
pageAgentMap[idForPage] = new PageAgent(page, testId);
35+
pageAgentMap[idForPage] = new PageAgent(page, `${testId}-${idForPage}`);
3636
}
3737
return pageAgentMap[idForPage];
3838
};
3939

4040
return {
4141
ai: async ({ page }: any, use: any, testInfo: TestInfo) => {
42+
const agent = agentForPage(page, testInfo.testId);
4243
await use(async (taskPrompt: string, opts?: { type?: 'action' | 'query' }) => {
4344
const { groupName, caseName } = groupAndCaseForTest(testInfo);
44-
const agent = agentForPage(page, testInfo.testId);
4545
const actionType = opts?.type || 'action';
4646
const result = await agent.ai(taskPrompt, actionType, caseName, groupName);
47-
if (agent.dumpFile) {
48-
testInfo.annotations.push({
49-
type: 'PLAYWRIGHT_AI_ACTION',
50-
description: JSON.stringify({
51-
testId: testInfo.testId,
52-
dumpPath: agent.dumpFile,
53-
}),
54-
});
55-
}
5647
return result;
5748
});
49+
if (agent.dumpFile) {
50+
testInfo.annotations.push({
51+
type: 'MIDSCENE_AI_ACTION',
52+
description: JSON.stringify({
53+
testId: testInfo.testId,
54+
dumpPath: agent.dumpFile,
55+
}),
56+
});
57+
}
5858
},
5959
aiAction: async ({ page }: any, use: any, testInfo: TestInfo) => {
60+
const agent = agentForPage(page, testInfo.testId);
6061
await use(async (taskPrompt: string) => {
61-
const agent = agentForPage(page, testInfo.testId);
62-
6362
const { groupName, caseName } = groupAndCaseForTest(testInfo);
6463
await agent.aiAction(taskPrompt, caseName, groupName);
65-
if (agent.dumpFile) {
66-
testInfo.annotations.push({
67-
type: 'PLAYWRIGHT_AI_ACTION',
68-
description: JSON.stringify({
69-
testId: testInfo.testId,
70-
dumpPath: agent.dumpFile,
71-
}),
72-
});
73-
}
7464
});
65+
if (agent.dumpFile) {
66+
testInfo.annotations.push({
67+
type: 'MIDSCENE_AI_ACTION',
68+
description: JSON.stringify({
69+
testId: testInfo.testId,
70+
dumpPath: agent.dumpFile,
71+
}),
72+
});
73+
}
7574
},
7675
aiQuery: async ({ page }: any, use: any, testInfo: TestInfo) => {
76+
const agent = agentForPage(page, testInfo.testId);
7777
await use(async function (demand: any) {
78-
const agent = agentForPage(page, testInfo.testId);
7978
const { groupName, caseName } = groupAndCaseForTest(testInfo);
8079
const result = await agent.aiQuery(demand, caseName, groupName);
81-
if (agent.dumpFile) {
82-
testInfo.annotations.push({
83-
type: 'PLAYWRIGHT_AI_ACTION',
84-
description: JSON.stringify({
85-
testId: testInfo.testId,
86-
dumpPath: agent.dumpFile,
87-
}),
88-
});
89-
}
9080
return result;
9181
});
82+
if (agent.dumpFile) {
83+
testInfo.annotations.push({
84+
type: 'MIDSCENE_AI_ACTION',
85+
description: JSON.stringify({
86+
testId: testInfo.testId,
87+
dumpPath: agent.dumpFile,
88+
}),
89+
});
90+
}
9291
},
9392
};
9493
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class MidSceneReporter implements Reporter {
2929

3030
onTestEnd(test: TestCase, result: TestResult) {
3131
const aiActionTestData = test.annotations.filter((annotation) => {
32-
if (annotation.type === 'PLAYWRIGHT_AI_ACTION') {
32+
if (annotation.type === 'MIDSCENE_AI_ACTION') {
3333
return true;
3434
}
3535
return false;
@@ -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: 31 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,34 @@ 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+
} catch (err) {
118+
console.error('modifyRoutesJson fail:', err);
119+
}
90120
}

0 commit comments

Comments
 (0)