Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
fix: suite clone does not clone fullUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy-kiselyov committed Mar 13, 2018
1 parent d1fda4a commit 4d9bc62
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/runner/browser-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
}
Expand Down
3 changes: 2 additions & 1 deletion lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
19 changes: 18 additions & 1 deletion test/unit/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 4d9bc62

Please sign in to comment.