rprieto / mocha-steps

Sequential scenarios for mocha
73 stars 17 forks source link

restore the runnable.body to the test-steps function #25

Closed eonuk closed 5 years ago

eonuk commented 5 years ago

Hi, Within Mocha, the test.body contains the test-step's JS code as a string. The purpose of this is to allow reporters such as Mochawesome to display the test-steps' JS code within the report.

Since mocha-steps is using 2 intermediary functions (sync & async), Mocha is now setting the .body to the JS code within these functions. For example, the report should display the test step's code such as this:

function() {
  expect(1).to.equal(1);
}

But, instead it always appears like this, because Mocha thinks this function is the test-step function:

function sync() {
  var context = this;
  context.test.body = fn.toString();
  try {
    var promise = fn.call(context);
    if (promise != null && promise.then != null && promise.catch != null) {
      return promise.catch(function(err) {
        markRemainingTestsAndSubSuitesAsPending(context.test);
        throw err;
      });
    } else {
      return promise;
    }
  } catch (ex) {
    markRemainingTestsAndSubSuitesAsPending(context.test);
    throw ex;
  }
}

This has easily been resolved by setting the context.body to the actual test-step's fn.string(). This is confirmed working with a test. I'd really appreciate it if you could release a new version with this fix in. Many thanks, Ian

ShahidPLT commented 1 year ago

@eonuk @rprieto

it appears this issue came back with the latest version of mocha.