Skip to content

Commit

Permalink
process manually attached data in Playwright #478
Browse files Browse the repository at this point in the history
  • Loading branch information
olexandr13 committed Jan 19, 2025
1 parent 0ee8a6a commit fae488a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/adapter/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,13 @@ class PlaywrightReporter {
}

if (artifact.body) {
const fileName = tmpFile();
fs.writeFileSync(fileName, artifact.body);
return fileName;
let filePath = generateTmpFilepath(artifact.name);

const extension = artifact.contentType?.split('/')[1]?.replace('jpeg', 'jpg');
if (extension) filePath += `.${extension}`;

fs.writeFileSync(filePath, artifact.body);
return filePath;
}

return null;
Expand Down Expand Up @@ -219,9 +223,10 @@ function appendStep(step, shift = 0) {
return resultStep;
}

function tmpFile(prefix = 'tmp.') {
function generateTmpFilepath(filename = '') {
filename = filename || `tmp.${crypto.randomBytes(16).toString('hex')}`;
const tmpdir = os.tmpdir();
return path.join(tmpdir, prefix + crypto.randomBytes(16).toString('hex'));
return path.join(tmpdir, filename);
}

/**
Expand Down

0 comments on commit fae488a

Please sign in to comment.