From ddc57aa56dc0f1da07ad847b37f56502296f4eaf Mon Sep 17 00:00:00 2001 From: Tian Feng Date: Tue, 12 Sep 2023 15:48:18 -0700 Subject: [PATCH 1/3] chore: Rename screenshot file when collecting attachment --- src/reporter.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/reporter.ts b/src/reporter.ts index 3daf9cf..aeec0ba 100644 --- a/src/reporter.ts +++ b/src/reporter.ts @@ -306,6 +306,11 @@ export default class SauceReporter implements Reporter { } const filename = `${path.basename(path.dirname(attachment.path || ''))}-${path.basename(attachment.path || '')}`; + // Rename the screenshot using the generated filename. + const ouputDir = rootSuite.project()?.outputDir || '__assets__'; + const newAttachmentPath = path.join(ouputDir, filename) + fs.renameSync(attachment.path || '', newAttachmentPath); + test.attach({ name: attachment.name, path: filename, @@ -315,7 +320,7 @@ export default class SauceReporter implements Reporter { if (attachment.path) { assets.push({ filename, - data: fs.createReadStream(attachment.path), + data: fs.createReadStream(newAttachmentPath), }); } else if (attachment.body) { assets.push({ From 598bc94612cd5889e72b0d2716c6a2df84615cbb Mon Sep 17 00:00:00 2001 From: Tian Feng Date: Tue, 12 Sep 2023 17:18:16 -0700 Subject: [PATCH 2/3] Use screenshot name as is --- src/reporter.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/reporter.ts b/src/reporter.ts index aeec0ba..e3977eb 100644 --- a/src/reporter.ts +++ b/src/reporter.ts @@ -305,12 +305,7 @@ export default class SauceReporter implements Reporter { break; } - const filename = `${path.basename(path.dirname(attachment.path || ''))}-${path.basename(attachment.path || '')}`; - // Rename the screenshot using the generated filename. - const ouputDir = rootSuite.project()?.outputDir || '__assets__'; - const newAttachmentPath = path.join(ouputDir, filename) - fs.renameSync(attachment.path || '', newAttachmentPath); - + const filename = path.basename(attachment.path || ''); test.attach({ name: attachment.name, path: filename, @@ -320,7 +315,7 @@ export default class SauceReporter implements Reporter { if (attachment.path) { assets.push({ filename, - data: fs.createReadStream(newAttachmentPath), + data: fs.createReadStream(attachment.path), }); } else if (attachment.body) { assets.push({ From 67d9af81aa70ccc99cbe9aa21de8d7c9361e4ca8 Mon Sep 17 00:00:00 2001 From: Tian Feng Date: Wed, 13 Sep 2023 09:36:03 -0700 Subject: [PATCH 3/3] fix logical issue --- src/reporter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reporter.ts b/src/reporter.ts index e3977eb..b29e00c 100644 --- a/src/reporter.ts +++ b/src/reporter.ts @@ -319,7 +319,7 @@ export default class SauceReporter implements Reporter { }); } else if (attachment.body) { assets.push({ - filename, + filename: attachment.name, data: stream.Readable.from(attachment.body), }); }