@@ -4,6 +4,7 @@ import * as util from "util";
44import * as fs from "fs" ;
55import * as os from "os" ;
66import * as path from "path" ;
7+ import { createHash } from 'crypto' ;
78import { parseISO , addMilliseconds } from "date-fns" ;
89import { zonedTimeToUtc } from "date-fns-tz" ;
910import { TestCase } from "testsolar-oss-sdk/src/testsolar_sdk/model/test" ;
@@ -358,8 +359,13 @@ export function generateCommands(
358359
359360 // 检查是否应该启用 trace
360361 const enableTrace = process . env . TESTSOLAR_TTP_TRACE === "1" ;
361- const traceOption = enableTrace ? "--trace on" : "" ;
362+ const traceOption = enableTrace ? "--trace on" : "--trace off " ;
362363
364+ // 创建基于测试路径和测试用例的哈希值
365+ const input = `${ casePath } -${ testCases . join ( '-' ) } -${ Date . now ( ) } -${ Math . random ( ) } ` ;
366+ const hash = createHash ( 'md5' ) . update ( input ) . digest ( 'hex' ) . substring ( 0 , 10 ) ;
367+ const outputOption = `--output=test-results-${ hash } ` ;
368+
363369 // 获取 grep 模式
364370 let grepPattern = "" ;
365371 if ( testCases . length > 0 ) {
@@ -371,16 +377,16 @@ export function generateCommands(
371377 if ( useEnvJsonFile ) {
372378 // 使用环境变量设置 JSON 输出
373379 if ( testCases . length === 0 ) {
374- command = `export PLAYWRIGHT_JSON_OUTPUT_NAME=${ jsonName } && npx playwright test --reporter=json ${ traceOption } ${ extraArgs } ` ;
380+ command = `export PLAYWRIGHT_JSON_OUTPUT_NAME=${ jsonName } && npx playwright test --reporter=json ${ traceOption } ${ outputOption } ${ extraArgs } ` ;
375381 } else {
376- command = `export PLAYWRIGHT_JSON_OUTPUT_NAME=${ jsonName } && npx playwright test ${ casePath } ${ grepPattern } --reporter=json ${ traceOption } ${ extraArgs } ` ;
382+ command = `export PLAYWRIGHT_JSON_OUTPUT_NAME=${ jsonName } && npx playwright test ${ casePath } ${ grepPattern } --reporter=json ${ traceOption } ${ outputOption } ${ extraArgs } ` ;
377383 }
378384 } else {
379385 // 使用原始的重定向方式
380386 if ( testCases . length === 0 ) {
381- command = `npx playwright test --reporter=json ${ traceOption } ${ extraArgs } > ${ jsonName } ` ;
387+ command = `npx playwright test --reporter=json ${ traceOption } ${ outputOption } ${ extraArgs } > ${ jsonName } ` ;
382388 } else {
383- command = `npx playwright test ${ casePath } ${ grepPattern } --reporter=json ${ traceOption } ${ extraArgs } > ${ jsonName } ` ;
389+ command = `npx playwright test ${ casePath } ${ grepPattern } --reporter=json ${ traceOption } ${ outputOption } ${ extraArgs } > ${ jsonName } ` ;
384390 }
385391 }
386392
@@ -629,6 +635,7 @@ export async function executeCommands(
629635 command : string ,
630636 cases : string [ ] ,
631637 jsonFile : string , // 接收jsonFile作为参数
638+ attachmentsPath : string ,
632639) : Promise < Record < string , SpecResult [ ] > > {
633640 const results : Record < string , SpecResult [ ] > = { } ;
634641
@@ -637,15 +644,13 @@ export async function executeCommands(
637644 `Run cmdline: ${ command } \n Run stdout: ${ stdout } \nRun stderr: ${ stderr } ` ,
638645 ) ;
639646
640- // 复制文件到附件目录,加载用例已创建该目录,此处不做检查
641- const attachmentPath = path . join ( projPath , 'attachments' ) ; // 附件目录
642647
643648 // 检查 JSON 文件是否存在
644649 if ( ! fs . existsSync ( jsonFile ) ) {
645650 console . error ( `用例json文件不存在: ${ jsonFile } ` ) ;
646651 } else {
647652 // 定义目标文件路径
648- const targetFilePath = path . join ( attachmentPath , path . basename ( jsonFile ) ) ;
653+ const targetFilePath = path . join ( attachmentsPath , path . basename ( jsonFile ) ) ;
649654
650655 // 复制文件
651656 fs . copyFileSync ( jsonFile , targetFilePath ) ;
0 commit comments