adamgruber / mochawesome

A Gorgeous HTML/CSS Reporter for Mocha.js

Home Page:https://gitter.im/mochawesome/general

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

addContext to selected context in the suite

joo920131 opened this issue · comments

Would we be able to use addContext() so we can add to previously executed contexts?

This will be useful for cases where you would resolve async processes all in parallel, while adding the contexts to the relevant hooks/tests for better viewing of mochawesome reports.

I've tried with the following code:

/* eslint-disable @typescript-eslint/no-this-alias */
import addContext from 'mochawesome/addContext';

describe(`Test`, function () {
  let this1: Mocha.Context, this2: Mocha.Context;
  before(`before block1`, async function () {
    this1 = this;
  })
  before(`before block2`, async function () {
    this2 = this;
  })
  before(`resolve befores`, async function () {
    addContext(this1, `hello`);
    addContext(this2, `world`);
  })
  it(`test`, async function () {
    addContext(this, `my test`);
  })
})

Result was like this:

SCR-20230307-k8t

This isn't so useful when you imagine if you have lots of context in one hook block in the report to figure out which one's which. I'm suggesting if we could add the contexts so it's added to the context we have saved previously (this1, #this2).

So the report would show something like this below:

image