diff --git a/lib/handlers.js b/lib/handlers.js index fadf3f1..da2b7a0 100644 --- a/lib/handlers.js +++ b/lib/handlers.js @@ -2,12 +2,19 @@ const tsm = require('teamcity-service-messages'); -const formatTestName = (test) => { - const fullTitle = test.fullTitle().trim(); - - return `${fullTitle} [${test.browserId}]`; +const titlePath = testOrSuite => { + let result = []; + if (testOrSuite.parent) { + result = result.concat(titlePath(testOrSuite.parent)); + } + if (!testOrSuite.root) { + result.push(testOrSuite.title.trim()); + } + return result; }; +const formatTestName = (test) => `${titlePath(test).join(': ')} [${test.browserId}]`; + module.exports = { onTestPending: (test) => tsm.testIgnored({name: formatTestName(test)}), diff --git a/test/lib/handlers.js b/test/lib/handlers.js index da29cfe..e62c09f 100644 --- a/test/lib/handlers.js +++ b/test/lib/handlers.js @@ -18,7 +18,7 @@ describe('handlers', () => { const stubTest = (test) => { test = test || {}; - test.fullTitle = test.fullTitle || sinon.stub().returns(test.title || 'default-title'); + test.title = test.title || 'default-title'; return test; }; @@ -56,9 +56,9 @@ describe('handlers', () => { assert.callOrder(tsm.testStarted, tsm.testFinished); }); - it('should trim full test title', () => { + it('should trim test title', () => { const test = stubTest({ - fullTitle: sinon.stub().returns(' test '), + title: ' test ', browserId: 'bro' }); @@ -67,6 +67,27 @@ describe('handlers', () => { assert.calledWith(tsm.testStarted, {name: 'test [bro]'}); assert.calledWithMatch(tsm.testFinished, {name: 'test [bro]'}); }); + + it('should include suite titles', () => { + const test = stubTest({ + title: 'test', + browserId: 'bro', + parent: { + title: 'bar', + parent: { + title: 'foo', + parent: { + root: true + } + } + } + }); + + handlers.onTestPass(test); + + assert.calledWith(tsm.testStarted, {name: 'foo: bar: test [bro]'}); + assert.calledWithMatch(tsm.testFinished, {name: 'foo: bar: test [bro]'}); + }); }); describe('.onTestFail', () => { @@ -142,9 +163,9 @@ describe('handlers', () => { assert.callOrder(tsm.testStarted, tsm.testFailed, tsm.testFinished); }); - it('should trim full test title', () => { + it('should trim test title', () => { const test = stubTest({ - fullTitle: sinon.stub().returns(' test '), + title: ' test ', browserId: 'bro' }); @@ -154,5 +175,27 @@ describe('handlers', () => { assert.calledWithMatch(tsm.testFailed, {name: 'test [bro]'}); assert.calledWithMatch(tsm.testFinished, {name: 'test [bro]'}); }); + + it('should include suite titles', () => { + const test = stubTest({ + title: 'test', + browserId: 'bro', + parent: { + title: 'bar', + parent: { + title: 'foo', + parent: { + root: true + } + } + } + }); + + handlers.onTestFail(test); + + assert.calledWith(tsm.testStarted, {name: 'foo: bar: test [bro]'}); + assert.calledWithMatch(tsm.testFailed, {name: 'foo: bar: test [bro]'}); + assert.calledWithMatch(tsm.testFinished, {name: 'foo: bar: test [bro]'}); + }); }); });