Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process manually attached data in Playwright #478

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading