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

Add input capture for allure reporting #135

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion tests/TestEndpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
createRequestBody,
createVerifyRequestBody
} from './mock.data.js';
import {addJsonAttachment} from './helpers.js';
import http from 'http';
import receiveJson from './receive-json.js';

Expand All @@ -26,7 +27,10 @@ export class TestEndpoints {
async issue(credential) {
const {issuer} = this;
const issueBody = createRequestBody({issuer, vc: credential});
return post(issuer, issueBody);
await addJsonAttachment('Request', issueBody);
const response = post(issuer, issueBody);
await addJsonAttachment('Response', response);
return response;
}
// FIXME implement createVp for implementation endpoints in the future
// @see https://w3c-ccg.github.io/vc-api/#create-presentation
Expand All @@ -35,10 +39,12 @@ export class TestEndpoints {
}
async verify(vc) {
const verifyBody = createVerifyRequestBody({vc});
await addJsonAttachment('Request', verifyBody);
const result = await post(this.verifier, verifyBody);
if(result?.errors?.length) {
throw result.errors[0];
}
await addJsonAttachment('Response', result);
return result;
}
async verifyVp(vp, options = {}) {
Expand Down
17 changes: 17 additions & 0 deletions tests/helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import * as allure from 'allure-js-commons';
import {ContentType} from 'allure-js-commons';

export function setupMatrix(match) {
// this will tell the report
// to make an interop matrix with this suite
Expand Down Expand Up @@ -36,3 +39,17 @@ export function extractIfEnveloped(input) {
return input;
}
}

export async function addJsonAttachment(fileName, content) {
try {
// Temporarily disable the console log to avoid unnecessary info logs.
const consoleLog = console.log;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PatStLouis so not sure if we're all 100% agreeing on how to solve this, but do you think this will work:

  1. create a separate command for allure reports
  2. that separate command can turn off the consoleLog if needed

LMK if that will work.

console.log = function() {};
await allure.attachment(
fileName,
JSON.stringify(content, null, 2),
ContentType.JSON
);
console.log = consoleLog;
} catch(err) {}
}