From e1dccddb15b5af0892d017eb38fc726420935fde Mon Sep 17 00:00:00 2001 From: catwithapple Date: Tue, 16 Jul 2019 16:59:56 +0300 Subject: [PATCH] fix(merge-reports): merge suites with children and browsers --- lib/merge-reports/data-tree.js | 6 +- lib/static/modules/utils.js | 10 +- test/unit/lib/merge-reports/data-tree.js | 136 +++++++++++++++++++++++ 3 files changed, 148 insertions(+), 4 deletions(-) diff --git a/lib/merge-reports/data-tree.js b/lib/merge-reports/data-tree.js index 7f3ff7286..bfd6c8577 100644 --- a/lib/merge-reports/data-tree.js +++ b/lib/merge-reports/data-tree.js @@ -55,7 +55,9 @@ module.exports = class DataTree { if (suite.children) { await Promise.map(suite.children, (childSuite) => this._mergeSuiteResult(childSuite)); - } else { + } + + if (suite.browsers) { await this._mergeBrowserResult(suite); } } @@ -94,6 +96,8 @@ module.exports = class DataTree { existentParentSuite.browsers = existentParentSuite.browsers || []; existentParentSuite.browsers.push(bro); + setStatusForBranch(this._data.suites, suitePath); + this._mergeStatistics(bro); await this._moveImages(bro, {fromFields: ['result', 'retries']}); } diff --git a/lib/static/modules/utils.js b/lib/static/modules/utils.js index 6c3e8d0c3..4f6e94113 100644 --- a/lib/static/modules/utils.js +++ b/lib/static/modules/utils.js @@ -100,11 +100,15 @@ function setStatusForBranch(nodes, suitePath) { return; } - const statuses = node.browsers + const statusesBrowser = node.browsers ? node.browsers.map(({result: {status}}) => status) - : node.children.map(({status}) => status); + : []; - const status = determineStatus(statuses); + const statusesChildren = node.children + ? node.children.map(({status}) => status) + : []; + + const status = determineStatus([...statusesBrowser, ...statusesChildren]); // if newly determined status is the same as current status, do nothing if (node.status === status) { diff --git a/test/unit/lib/merge-reports/data-tree.js b/test/unit/lib/merge-reports/data-tree.js index 2c99f7914..59165dc89 100644 --- a/test/unit/lib/merge-reports/data-tree.js +++ b/test/unit/lib/merge-reports/data-tree.js @@ -310,6 +310,142 @@ describe('lib/merge-reports/data-tree', () => { }); }); }); + + describe('with children and browsers', () => { + it('should add data to suite from children with error status', async () => { + const srcDataSuites1 = mkSuite({ + suitePath: ['first suite'], + status: SUCCESS, + children: [ + mkSuite({ + suitePath: ['first suite', 'second suite'], + status: SUCCESS, + browsers: [mkBrowserResult({ + result: mkTestResult({status: SUCCESS}), + name: 'first-bro' + })] + }) + ] + }); + const srcDataSuites2 = mkSuite({ + suitePath: ['first suite'], + status: ERROR, + children: [ + mkSuite({ + suitePath: ['first suite', 'second suite'], + status: ERROR, + children: [ + mkState({ + suitePath: ['first suite', 'second suite', 'third suite'], + status: ERROR, + browsers: [mkBrowserResult({ + name: 'second-bro', + result: mkTestResult({status: ERROR}) + })] + }) + ] + }) + ] + }); + + const initialData = {suites: [srcDataSuites1]}; + const dataCollection = {'src-report/path': {suites: [srcDataSuites2]}}; + + const {suites} = await mkDataTree_(initialData).mergeWith(dataCollection); + + assert.deepEqual(suites[0], mkSuite({ + suitePath: ['first suite'], + status: ERROR, + children: [ + mkSuite({ + suitePath: ['first suite', 'second suite'], + status: ERROR, + browsers: [mkBrowserResult({ + name: 'first-bro', + result: mkTestResult({status: SUCCESS}) + })], + children: [ + mkState({ + suitePath: ['first suite', 'second suite', 'third suite'], + status: ERROR, + browsers: [mkBrowserResult({ + name: 'second-bro', + result: mkTestResult({status: ERROR}) + })] + }) + ] + }) + ] + })); + }); + + it('should add data to suite from browsers with error status', async () => { + const srcDataSuites1 = mkSuite({ + suitePath: ['first suite'], + status: SUCCESS, + children: [ + mkSuite({ + suitePath: ['first suite', 'second suite'], + status: SUCCESS, + children: [ + mkState({ + suitePath: ['first suite', 'second suite', 'third suite'], + status: SUCCESS, + browsers: [mkBrowserResult({ + name: 'first-bro', + result: mkTestResult({status: SUCCESS}) + })] + }) + ] + }) + ] + }); + const srcDataSuites2 = mkSuite({ + suitePath: ['first suite'], + status: ERROR, + children: [ + mkSuite({ + suitePath: ['first suite', 'second suite'], + status: ERROR, + browsers: [mkBrowserResult({ + name: 'second-bro', + result: mkTestResult({status: ERROR}) + })] + }) + ] + }); + + const initialData = {suites: [srcDataSuites1]}; + const dataCollection = {'src-report/path': {suites: [srcDataSuites2]}}; + + const {suites} = await mkDataTree_(initialData).mergeWith(dataCollection); + + assert.deepEqual(suites[0], mkSuite({ + suitePath: ['first suite'], + status: ERROR, + children: [ + mkSuite({ + suitePath: ['first suite', 'second suite'], + status: ERROR, + children: [ + mkState({ + suitePath: ['first suite', 'second suite', 'third suite'], + status: SUCCESS, + browsers: [mkBrowserResult({ + name: 'first-bro', + result: mkTestResult({status: SUCCESS}) + })] + }) + ], + browsers: [mkBrowserResult({ + name: 'second-bro', + result: mkTestResult({status: ERROR}) + })] + }) + ] + })); + }); + }); }); describe('merge statistics data', () => {