From 97e04017de99f3e1720f06ada1accd29f84a3c30 Mon Sep 17 00:00:00 2001 From: Ovidiu Chereches Date: Sun, 7 Jun 2015 23:34:44 +0300 Subject: [PATCH] No longer deep clone fixture in every test #15 Was destroying unserializable members --- tests/components/component-playground/default/events/dom.js | 4 ++-- .../component-playground/default/events/handlers.js | 4 ++-- .../component-playground/default/render/children.js | 4 ++-- tests/components/component-playground/default/render/dom.js | 4 ++-- .../components/component-playground/default/render/urls.js | 4 ++-- .../component-playground/default/transitions/mount.js | 4 ++-- .../component-playground/full-screen/render/dom.js | 4 ++-- .../selected-fixture-and-editor-focused/events/handlers.js | 4 ++-- .../selected-fixture-and-editor/events/dom.js | 4 ++-- .../selected-fixture-and-editor/events/handlers.js | 4 ++-- .../selected-fixture-and-editor/render/dom.js | 4 ++-- .../selected-fixture-and-editor/render/urls.js | 4 ++-- .../component-playground/selected-fixture/events/dom.js | 6 +++--- .../selected-fixture/render/children.js | 4 ++-- .../component-playground/selected-fixture/render/dom.js | 4 ++-- .../component-playground/selected-fixture/render/urls.js | 4 ++-- .../selected-fixture/transitions/mount.js | 6 +++--- .../selected-fixture/transitions/props.js | 4 ++-- .../selected-fixture/transitions/state.js | 4 ++-- tests/lib/render-component.js | 6 ++---- 20 files changed, 42 insertions(+), 44 deletions(-) diff --git a/tests/components/component-playground/default/events/dom.js b/tests/components/component-playground/default/events/dom.js index e9c7bdd..12fff92 100644 --- a/tests/components/component-playground/default/events/dom.js +++ b/tests/components/component-playground/default/events/dom.js @@ -4,7 +4,7 @@ describe(`ComponentPlayground (${FIXTURE}) Events DOM`, function() { var React = require('react/addons'), utils = React.addons.TestUtils, render = require('tests/lib/render-component.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -12,7 +12,7 @@ describe(`ComponentPlayground (${FIXTURE}) Events DOM`, function() { fixture; beforeEach(function() { - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); }); it('should mark expanded component on click', function() { diff --git a/tests/components/component-playground/default/events/handlers.js b/tests/components/component-playground/default/events/handlers.js index 0299ab8..d8bcb1c 100644 --- a/tests/components/component-playground/default/events/handlers.js +++ b/tests/components/component-playground/default/events/handlers.js @@ -3,7 +3,7 @@ var FIXTURE = 'default'; describe(`ComponentPlayground (${FIXTURE}) Events Handlers`, function() { var ComponentTree = require('react-component-tree'), render = require('tests/lib/render-component.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -11,7 +11,7 @@ describe(`ComponentPlayground (${FIXTURE}) Events Handlers`, function() { fixture; beforeEach(function() { - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); sinon.spy(component, 'setState'); }); diff --git a/tests/components/component-playground/default/render/children.js b/tests/components/component-playground/default/render/children.js index 01e7452..2c8af7a 100644 --- a/tests/components/component-playground/default/render/children.js +++ b/tests/components/component-playground/default/render/children.js @@ -4,7 +4,7 @@ describe(`ComponentPlayground (${FIXTURE}) Render Children`, function() { var loadChild = require('react-component-tree').loadChild, render = require('tests/lib/render-component.js'), stubLoadChild = require('tests/setup/stub-load-child.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -14,7 +14,7 @@ describe(`ComponentPlayground (${FIXTURE}) Render Children`, function() { stubLoadChild(); beforeEach(function() { - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); }); it('should not load preview component', function() { diff --git a/tests/components/component-playground/default/render/dom.js b/tests/components/component-playground/default/render/dom.js index f5907f8..76e6058 100644 --- a/tests/components/component-playground/default/render/dom.js +++ b/tests/components/component-playground/default/render/dom.js @@ -3,7 +3,7 @@ var FIXTURE = 'default'; describe(`ComponentPlayground (${FIXTURE}) Render DOM`, function() { var $ = require('jquery'), render = require('tests/lib/render-component.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -11,7 +11,7 @@ describe(`ComponentPlayground (${FIXTURE}) Render DOM`, function() { fixture; beforeEach(function() { - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); }); it('should render cosmos plug', function() { diff --git a/tests/components/component-playground/default/render/urls.js b/tests/components/component-playground/default/render/urls.js index cefacaa..3aa3370 100644 --- a/tests/components/component-playground/default/render/urls.js +++ b/tests/components/component-playground/default/render/urls.js @@ -3,7 +3,7 @@ var FIXTURE = 'default'; describe(`ComponentPlayground (${FIXTURE}) Render URLs`, function() { var render = require('tests/lib/render-component.js'), getUrlProps = require('tests/lib/get-url-props.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -11,7 +11,7 @@ describe(`ComponentPlayground (${FIXTURE}) Render URLs`, function() { fixture; beforeEach(function() { - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); }); it('should generate urls with component and fixture names', function() { diff --git a/tests/components/component-playground/default/transitions/mount.js b/tests/components/component-playground/default/transitions/mount.js index 0ee28ef..4266750 100644 --- a/tests/components/component-playground/default/transitions/mount.js +++ b/tests/components/component-playground/default/transitions/mount.js @@ -3,7 +3,7 @@ var FIXTURE = 'default'; describe(`ComponentPlayground (${FIXTURE}) Transitions Mount`, function() { var React = require('react'), render = require('tests/lib/render-component.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -16,7 +16,7 @@ describe(`ComponentPlayground (${FIXTURE}) Transitions Mount`, function() { sinon.stub(window, 'setInterval').returns(timeoutId); sinon.stub(window, 'clearInterval'); - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); }); afterEach(function() { diff --git a/tests/components/component-playground/full-screen/render/dom.js b/tests/components/component-playground/full-screen/render/dom.js index bd42b9a..c1c3897 100644 --- a/tests/components/component-playground/full-screen/render/dom.js +++ b/tests/components/component-playground/full-screen/render/dom.js @@ -2,7 +2,7 @@ var FIXTURE = 'full-screen'; describe(`ComponentPlayground (${FIXTURE}) Render DOM`, function() { var render = require('tests/lib/render-component.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -10,7 +10,7 @@ describe(`ComponentPlayground (${FIXTURE}) Render DOM`, function() { fixture; beforeEach(function() { - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); }); it('should add full-screen class', function() { diff --git a/tests/components/component-playground/selected-fixture-and-editor-focused/events/handlers.js b/tests/components/component-playground/selected-fixture-and-editor-focused/events/handlers.js index 4439b8b..aa055cd 100644 --- a/tests/components/component-playground/selected-fixture-and-editor-focused/events/handlers.js +++ b/tests/components/component-playground/selected-fixture-and-editor-focused/events/handlers.js @@ -3,7 +3,7 @@ var FIXTURE = 'selected-fixture-and-editor-focused'; describe(`ComponentPlayground (${FIXTURE}) Events Handlers`, function() { var ComponentTree = require('react-component-tree'), render = require('tests/lib/render-component.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -11,7 +11,7 @@ describe(`ComponentPlayground (${FIXTURE}) Events Handlers`, function() { fixture; beforeEach(function() { - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); sinon.spy(component, 'setState'); }); diff --git a/tests/components/component-playground/selected-fixture-and-editor/events/dom.js b/tests/components/component-playground/selected-fixture-and-editor/events/dom.js index 617e81d..518593f 100644 --- a/tests/components/component-playground/selected-fixture-and-editor/events/dom.js +++ b/tests/components/component-playground/selected-fixture-and-editor/events/dom.js @@ -4,7 +4,7 @@ describe(`ComponentPlayground (${FIXTURE}) Events DOM`, function() { var React = require('react/addons'), utils = React.addons.TestUtils, render = require('tests/lib/render-component.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -12,7 +12,7 @@ describe(`ComponentPlayground (${FIXTURE}) Events DOM`, function() { fixture; beforeEach(function() { - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); }); it('should focus on editor on fixture click', function() { diff --git a/tests/components/component-playground/selected-fixture-and-editor/events/handlers.js b/tests/components/component-playground/selected-fixture-and-editor/events/handlers.js index 33a7ae0..06001e7 100644 --- a/tests/components/component-playground/selected-fixture-and-editor/events/handlers.js +++ b/tests/components/component-playground/selected-fixture-and-editor/events/handlers.js @@ -3,7 +3,7 @@ var FIXTURE = 'selected-fixture-and-editor'; describe(`ComponentPlayground (${FIXTURE}) Events Handlers`, function() { var ComponentTree = require('react-component-tree'), render = require('tests/lib/render-component.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -11,7 +11,7 @@ describe(`ComponentPlayground (${FIXTURE}) Events Handlers`, function() { fixture; beforeEach(function() { - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); }); define('on fixture update', function() { diff --git a/tests/components/component-playground/selected-fixture-and-editor/render/dom.js b/tests/components/component-playground/selected-fixture-and-editor/render/dom.js index 218f1c4..c294c67 100644 --- a/tests/components/component-playground/selected-fixture-and-editor/render/dom.js +++ b/tests/components/component-playground/selected-fixture-and-editor/render/dom.js @@ -3,7 +3,7 @@ var FIXTURE = 'selected-fixture-and-editor'; describe(`ComponentPlayground (${FIXTURE}) Render DOM`, function() { var $ = require('jquery'), render = require('tests/lib/render-component.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -11,7 +11,7 @@ describe(`ComponentPlayground (${FIXTURE}) Render DOM`, function() { fixture; beforeEach(function() { - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); }); it('should render fixture editor', function() { diff --git a/tests/components/component-playground/selected-fixture-and-editor/render/urls.js b/tests/components/component-playground/selected-fixture-and-editor/render/urls.js index 79eaec8..506aa5f 100644 --- a/tests/components/component-playground/selected-fixture-and-editor/render/urls.js +++ b/tests/components/component-playground/selected-fixture-and-editor/render/urls.js @@ -3,7 +3,7 @@ var FIXTURE = 'selected-fixture-and-editor'; describe(`ComponentPlayground (${FIXTURE}) Render URLs`, function() { var render = require('tests/lib/render-component.js'), getUrlProps = require('tests/lib/get-url-props.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -11,7 +11,7 @@ describe(`ComponentPlayground (${FIXTURE}) Render URLs`, function() { fixture; beforeEach(function() { - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); }); it('should generate close fixture editor url', function() { diff --git a/tests/components/component-playground/selected-fixture/events/dom.js b/tests/components/component-playground/selected-fixture/events/dom.js index 643d34d..7ca37b6 100644 --- a/tests/components/component-playground/selected-fixture/events/dom.js +++ b/tests/components/component-playground/selected-fixture/events/dom.js @@ -5,14 +5,14 @@ describe(`ComponentPlayground (${FIXTURE}) Events DOM`, function() { utils = React.addons.TestUtils, _ = require('lodash'), render = require('tests/lib/render-component.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, container, fixture; - var stubbedFixture = _.assign({}, originalFixture, { + var stubbedFixture = _.assign({}, fixture, { router: { goTo: sinon.spy(), routeLink: sinon.spy() @@ -20,7 +20,7 @@ describe(`ComponentPlayground (${FIXTURE}) Events DOM`, function() { }); beforeEach(function() { - ({fixture, container, component, $component} = render(stubbedFixture)); + ({container, component, $component} = render(stubbedFixture)); }); afterEach(function() { diff --git a/tests/components/component-playground/selected-fixture/render/children.js b/tests/components/component-playground/selected-fixture/render/children.js index 833d2bb..4fdb7d6 100644 --- a/tests/components/component-playground/selected-fixture/render/children.js +++ b/tests/components/component-playground/selected-fixture/render/children.js @@ -4,7 +4,7 @@ describe(`ComponentPlayground (${FIXTURE}) Render Children`, function() { var loadChild = require('react-component-tree').loadChild, render = require('tests/lib/render-component.js'), stubLoadChild = require('tests/setup/stub-load-child.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -15,7 +15,7 @@ describe(`ComponentPlayground (${FIXTURE}) Render Children`, function() { stubLoadChild(); beforeEach(function() { - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); childParams = component.children.preview.call(component); }); diff --git a/tests/components/component-playground/selected-fixture/render/dom.js b/tests/components/component-playground/selected-fixture/render/dom.js index f1be315..81111c9 100644 --- a/tests/components/component-playground/selected-fixture/render/dom.js +++ b/tests/components/component-playground/selected-fixture/render/dom.js @@ -3,7 +3,7 @@ var FIXTURE = 'selected-fixture'; describe(`ComponentPlayground (${FIXTURE}) Render DOM`, function() { var $ = require('jquery'), render = require('tests/lib/render-component.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -11,7 +11,7 @@ describe(`ComponentPlayground (${FIXTURE}) Render DOM`, function() { fixture; beforeEach(function() { - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); }); it('should not render cosmos plug', function() { diff --git a/tests/components/component-playground/selected-fixture/render/urls.js b/tests/components/component-playground/selected-fixture/render/urls.js index ed02149..694ac7c 100644 --- a/tests/components/component-playground/selected-fixture/render/urls.js +++ b/tests/components/component-playground/selected-fixture/render/urls.js @@ -3,7 +3,7 @@ var FIXTURE = 'selected-fixture'; describe(`ComponentPlayground (${FIXTURE}) Render URLs`, function() { var render = require('tests/lib/render-component.js'), getUrlProps = require('tests/lib/get-url-props.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -11,7 +11,7 @@ describe(`ComponentPlayground (${FIXTURE}) Render URLs`, function() { fixture; beforeEach(function() { - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); }); it('should generate open full-screen url', function() { diff --git a/tests/components/component-playground/selected-fixture/transitions/mount.js b/tests/components/component-playground/selected-fixture/transitions/mount.js index 0f74fe0..0659a3d 100644 --- a/tests/components/component-playground/selected-fixture/transitions/mount.js +++ b/tests/components/component-playground/selected-fixture/transitions/mount.js @@ -3,7 +3,7 @@ var FIXTURE = 'selected-fixture'; describe(`ComponentPlayground (${FIXTURE}) Transitions Mount`, function() { var ComponentTree = require('react-component-tree'), render = require('tests/lib/render-component.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -12,12 +12,12 @@ describe(`ComponentPlayground (${FIXTURE}) Transitions Mount`, function() { // The following tests are about the initial state generation, so we don't // want it included in the fixture - var statelessFixture = _.omit(originalFixture, 'state'); + var statelessFixture = _.omit(fixture, 'state'); beforeEach(function() { sinon.stub(ComponentTree, 'injectState'); - ({fixture, container, component, $component} = render(statelessFixture)); + ({container, component, $component} = render(statelessFixture)); }); afterEach(function() { diff --git a/tests/components/component-playground/selected-fixture/transitions/props.js b/tests/components/component-playground/selected-fixture/transitions/props.js index 1ff4157..422c684 100644 --- a/tests/components/component-playground/selected-fixture/transitions/props.js +++ b/tests/components/component-playground/selected-fixture/transitions/props.js @@ -3,7 +3,7 @@ var FIXTURE = 'selected-fixture'; describe(`ComponentPlayground (${FIXTURE}) Transitions Props`, function() { var ComponentTree = require('react-component-tree'), render = require('tests/lib/render-component.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -13,7 +13,7 @@ describe(`ComponentPlayground (${FIXTURE}) Transitions Props`, function() { stateInjected; beforeEach(function() { - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); sinon.stub(ComponentTree, 'injectState'); sinon.spy(component, 'setState'); diff --git a/tests/components/component-playground/selected-fixture/transitions/state.js b/tests/components/component-playground/selected-fixture/transitions/state.js index 32df57b..c08d0dc 100644 --- a/tests/components/component-playground/selected-fixture/transitions/state.js +++ b/tests/components/component-playground/selected-fixture/transitions/state.js @@ -5,7 +5,7 @@ describe(`ComponentPlayground (${FIXTURE}) Transitions State`, function() { _ = require('lodash'), ComponentTree = require('react-component-tree'), render = require('tests/lib/render-component.js'), - originalFixture = require(`fixtures/component-playground/${FIXTURE}.js`); + fixture = require(`fixtures/component-playground/${FIXTURE}.js`); var component, $component, @@ -14,7 +14,7 @@ describe(`ComponentPlayground (${FIXTURE}) Transitions State`, function() { stateInjected; beforeEach(function() { - ({fixture, container, component, $component} = render(originalFixture)); + ({container, component, $component} = render(fixture)); }); it('should inject preview state when fixture changes', function() { diff --git a/tests/lib/render-component.js b/tests/lib/render-component.js index 7c36325..784b7a7 100644 --- a/tests/lib/render-component.js +++ b/tests/lib/render-component.js @@ -2,9 +2,8 @@ var $ = require('jquery'), ComponentTree = require('react-component-tree'), ComponentPlayground = require('components/component-playground.jsx'); -module.exports = function(originalFixture) { - var fixture = _.cloneDeep(originalFixture), - container = document.createElement('div'), +module.exports = function(fixture) { + var container = document.createElement('div'), component, $component; @@ -17,7 +16,6 @@ module.exports = function(originalFixture) { $component = $(component.getDOMNode()); return { - fixture: fixture, container: container, component: component, $component: $component