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

Adding response and request to reporter #41

Open
saritvakrat opened this issue Dec 15, 2019 · 1 comment
Open

Adding response and request to reporter #41

saritvakrat opened this issue Dec 15, 2019 · 1 comment

Comments

@saritvakrat
Copy link

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"

@bochenev
Copy link

bochenev commented Nov 1, 2021

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:

Request

<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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants