@@ -269,8 +269,9 @@ export const parseTestcase = (
269269
270270/// 生成运行测试用例的命令
271271export function generateCommands (
272- path : string ,
272+ casePath : string ,
273273 testCases : string [ ] ,
274+ jsonName : string ,
274275) : { command : string ; testIdentifiers : string [ ] } {
275276 const testIdentifiers : string [ ] = [ ] ;
276277
@@ -279,7 +280,7 @@ export function generateCommands(
279280
280281 // 检查 testCases 是否为空
281282 if ( testCases . length === 0 ) {
282- const defaultCommand = `npx playwright test --reporter=json ${ extraArgs } ` ;
283+ const defaultCommand = `npx playwright test --reporter=json ${ extraArgs } > ${ jsonName } ` ;
283284 log . info ( `Generated default command for test cases: ${ defaultCommand } ` ) ;
284285 return { command : defaultCommand , testIdentifiers : [ ] } ;
285286 }
@@ -288,10 +289,10 @@ export function generateCommands(
288289 if ( grepPattern ) {
289290 grepPattern = `--grep="${ grepPattern } "` ;
290291 }
291- const command = `npx playwright test ${ path } ${ grepPattern } --reporter=json ${ extraArgs } ` ;
292+ const command = `npx playwright test ${ casePath } ${ grepPattern } --reporter=json ${ extraArgs } > ${ jsonName } ` ;
292293
293294 for ( const testcase of testCases ) {
294- testIdentifiers . push ( `${ path } ?${ testcase } ` ) ;
295+ testIdentifiers . push ( `${ casePath } ?${ testcase } ` ) ;
295296 }
296297
297298 log . info ( `Generated command for test cases: ${ command } ` ) ;
@@ -416,9 +417,6 @@ export function parseJsonFile(
416417 `function parseJsonFile: ${ process . env . PLAYWRIGHT_JSON_OUTPUT_NAME } ` ,
417418 ) ;
418419 const data = JSON . parse ( fs . readFileSync ( jsonFile , "utf-8" ) ) ;
419- log . info ( "--------json data:---------" ) ;
420- log . info ( JSON . stringify ( data , null , 2 ) ) ;
421- log . info ( "---------------------------" ) ;
422420 const result = parseJsonContent ( projPath , data ) ;
423421
424422 log . info ( `Parse result from json: ${ JSON . stringify ( result , null , 2 ) } ` ) ;
@@ -453,6 +451,7 @@ export async function executeCommands(
453451 projPath : string ,
454452 command : string ,
455453 cases : string [ ] ,
454+ jsonFile : string , // 接收jsonFile作为参数
456455) : Promise < Record < string , SpecResult [ ] > > {
457456 const results : Record < string , SpecResult [ ] > = { } ;
458457
@@ -461,7 +460,6 @@ export async function executeCommands(
461460 `Run cmdline: ${ command } \n Run stdout: ${ stdout } \nRun stderr: ${ stderr } ` ,
462461 ) ;
463462 // 解析 JSON 文件并处理结果
464- const jsonFile = process . env . PLAYWRIGHT_JSON_OUTPUT_NAME || "result.json" ;
465463 const testResults = parseJsonFile ( projPath , jsonFile , cases ) ;
466464 Object . assign ( results , testResults ) ;
467465 return testResults ;
0 commit comments