From 4d9bc62911cff037d7a1bfac1617f2c127aa9012 Mon Sep 17 00:00:00 2001 From: dmitriy96 Date: Mon, 26 Feb 2018 23:53:49 +0300 Subject: [PATCH] fix: suite clone does not clone fullUrl --- lib/runner/browser-runner/index.js | 1 + lib/suite.js | 3 ++- test/unit/suite.js | 19 ++++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/runner/browser-runner/index.js b/lib/runner/browser-runner/index.js index 357e7c750..c04cca44d 100644 --- a/lib/runner/browser-runner/index.js +++ b/lib/runner/browser-runner/index.js @@ -30,6 +30,7 @@ module.exports = class BrowserRunner extends Runner { .map((suite) => { if (suite.hasOwnProperty('url')) { Object.defineProperty(suite, 'fullUrl', { + enumerable: true, get: () => this._mkFullUrl(suite.url) }); } diff --git a/lib/suite.js b/lib/suite.js index d7ce13cd3..32b3f96aa 100644 --- a/lib/suite.js +++ b/lib/suite.js @@ -84,7 +84,8 @@ module.exports = class Suite { const clonedSuite = Suite.create(this.name, this.parent); _.forOwn(this, (value, key) => { - clonedSuite[key] = _.clone(value); + let desc = Object.getOwnPropertyDescriptor(this, key); + Object.defineProperty(clonedSuite, key, _.cloneDeep(desc)); }); this.children.forEach((child) => clonedSuite.addChild(child.clone())); diff --git a/test/unit/suite.js b/test/unit/suite.js index b0a969833..5d9d8a4bf 100644 --- a/test/unit/suite.js +++ b/test/unit/suite.js @@ -342,9 +342,26 @@ describe('suite', () => { it('should return cloned suite', () => { const suite = createSuite('origin'); + suite.browsers = ['bro1', 'bro2']; const clonedSuite = suite.clone(); - assert.notEqual(clonedSuite, suite); + assert.deepEqual(clonedSuite, suite); + assert.notEqual(clonedSuite, suite); //not equal by link + assert.notEqual(clonedSuite.browsers, suite.browsers); //not equal by link + }); + + it('should clone all enumerable properties', () => { + const suite = createSuite('origin'); + let value = 'some/path'; + Object.defineProperty(suite, 'fullUrl', { + enumerable: true, + get: () => value + }); + const clonedSuite = suite.clone(); + + assert.equal(clonedSuite.fullUrl, 'some/path'); + value = 'another/path'; + assert.equal(clonedSuite.fullUrl, 'another/path'); }); it('should clone nested suites', () => {