Skip to content

Commit

Permalink
lib/test: Add diagnostic Test.context for Mochawesome
Browse files Browse the repository at this point in the history
This is, as far as I know, Mochawesome-specific, which makes it a bit
of a hack.  The Mochawesome side of this is
adamgruber/mochawesome@65e90621 (implement addContext method for
adding report context to tests, 2016-12-20,
adamgruber/mochawesome#106).  Ideally we'd want a way to trigger this
as part of requesting Mochawesome as the reporter, but the addition
seems harmless enough so I'm just including it every time.

In the diag.source case, I'm just assuming that was already doing what
it was supposed to be doing, so this injection only affects cases
where diag is set but diag.source is not.
  • Loading branch information
wking committed Jun 7, 2018
1 parent 8db63e8 commit d76f4da
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ function Test (result, parent) {
this.title = result.name
this.state = result.ok ? 'pass' : 'failed'
this.pending = result.todo || false
if (result.diag && result.diag.source) {
var source = result.diag.source
this.fn = {
toString: function () {
return 'function(){' + source + '\n}'
if (result.diag) {
if (result.diag.source) {
var source = result.diag.source
this.fn = {
toString: function () {
return 'function(){' + source + '\n}'
}
}
} else {
this.context = {
title: 'diagnostic',
value: result.diag,
}
}
}
Expand Down

0 comments on commit d76f4da

Please sign in to comment.