Skip to content

Commit

Permalink
chore: Rename screenshot file when collecting attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
tianfeng92 committed Sep 12, 2023
1 parent f63f11a commit ddc57aa
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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({
Expand Down

0 comments on commit ddc57aa

Please sign in to comment.