Adding response and request to reporter
Opened this issue · 1 comments
Hi all, I am using allure-Jest, does anyone know how I can add the response and request to the reporter?
jest-allure": "^0.1.1"
for latest versions, which supports Html in description.
something like this
await nodeFetch(url, init) .then(async (result) => { const { headers, status, statusText, ok, redirected, url } = result; let data; const contentDisposition = headers.get("content-disposition"); if (contentDisposition) { const match = contentDisposition.match( /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/ ); const filename = (match ? match[1] : "").replace(/"|'/g, ""); const buffer = await result.buffer(); reporter.attachment(filename, buffer, {fileExtension: filename.split(".")[1]} as unknown as ContentType); data = buffer; } else { const responseText = await result.text(); try { data = JSON.parse(responseText); } catch (error) { data = responseText; } } const allureResponse = { headers, status, statusText, ok, redirected, data, url, }; reporter.addDescription(getRequestDescription(allureResponse, init)); return allureResponse; }) .catch((error) => { reporter.addDescription(getRequestErrorDescription(url, init)); throw error; });
where getRequestDescription returns html strings for example:
<p>
<div>${init?.method || "GET"}: ${url}</div>
</p>
<p>
<div>Headers: </div>
<div><i><pre>${JSON.stringify(init?.headers, null, 4)}</pre></i></div>
<p>
<div>Body</div>
<div><i>${init?.body}</i></div>
</p>
<strong> <div>Response</div></strong>
<hr>
<p>
<div>Status: ${status} ${statusText}</div>
</p>
<p>
<div>Headers: </div>
<div>
<i><pre>${JSON.stringify(
R.fromPairs(Array.from(headers.entries())),
null,
4
)}
</pre></i>
</div>
</p>
<p>
<div>Body</div>
<div><i><pre>${responseText}</pre></i></div>
</p>