Skip to content

Commit

Permalink
process manually attached data in Playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
olexandr13 committed Jan 18, 2025
1 parent abe9fcb commit f110d24
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/adapter/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,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 @@ -218,9 +222,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 f110d24

Please sign in to comment.