Skip to content

Commit

Permalink
Don't use the root property to determine suite root.
Browse files Browse the repository at this point in the history
The root property is problematic because Mocha sets it true if the
description of a suite is the empty string. However, Mocha runs
perfectly well with suites that have empty names. See:

mochajs/mocha#2755

Instead of relying on the root property, rely on whether the parent
property is set. If not, then we are at the root.
  • Loading branch information
lddubeau committed Oct 5, 2017
1 parent 6c63662 commit f7b66ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ var createMochaReporterConstructor = function (tc, pathname) {
}

var pointer = test.parent
while (!pointer.root) {
while (pointer.parent) {
result.suite.unshift(pointer.title)
pointer = pointer.parent
}
Expand Down
18 changes: 18 additions & 0 deletions test/src/adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@ describe('adapter mocha', function () {
expect(tc.result.called).to.eq(true)
})

it('should not rely on the root property to determine root', function () {
sandbox.stub(tc, 'result', function (result) {
expect(result.suite).to.deep.eq([''])
})

var mockMochaResult = {
duration: 0,
parent: {title: '', parent: {title: 'desc1', root: true}, root: true},
state: 'passed',
title: 'should do something'
}

runner.emit('test', mockMochaResult)
runner.emit('test end', mockMochaResult)

expect(tc.result.called).to.eq(true)
})

it('should report skipped result', function () {
sandbox.stub(tc, 'result', function (result) {
expect(result.skipped).to.eq(true)
Expand Down

0 comments on commit f7b66ee

Please sign in to comment.