Skip to content

Commit

Permalink
fix: reverted to just-clone for renderBody
Browse files Browse the repository at this point in the history
  • Loading branch information
oxala committed Oct 17, 2018
1 parent 801a192 commit 9832386
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"license": "MIT",
"dependencies": {
"glob": "^7.1.3",
"just-clone": "^3.1.0",
"stack-trace": "0.0.9"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
} = require('path');
const { existsSync } = require('fs');
const stackTrace = require('stack-trace');
const clone = require('just-clone');
const browserMap = require('./browser-map');
const render = require('./render');

Expand Down Expand Up @@ -50,7 +51,7 @@ const runFixtures = (fixtures, fullPath, withAwait) => (fixtureName) => {
fixturesEntries
.filter(([name]) => (!fixtureName || fixtureName === name))
.forEach(([name, fixture]) => it(`should render component with ${name} fixture`, async () => {
const comp = await render(fullPath, withAwait)(JSON.parse(JSON.stringify(fixture)));
const comp = await render(fullPath, withAwait)(clone(fixture));

expect(Array.from(document.body.childNodes)).toMatchSnapshot();
comp.destroy();
Expand Down
9 changes: 5 additions & 4 deletions src/render.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
const clone = require('just-clone');
const { markoVersion } = require('./versions');

const mount = comp => comp.appendTo(document.body);
const getWidgetInstance = (renderer, input) => {
if (/\.marko$/.test(renderer.path)) {
document.body.insertAdjacentHTML('afterbegin', renderer.renderToString(JSON.parse(JSON.stringify(input))));
document.body.insertAdjacentHTML('afterbegin', renderer.renderToString(clone(input)));

return {
destroy: () => document.body.childNodes.forEach(node => document.body.removeChild(node)),
};
}

return mount(renderer.renderSync(JSON.parse(JSON.stringify(input)))).getWidget();
return mount(renderer.renderSync(clone(input))).getWidget();
};
const getComponentInstance = (renderer, input, withAwait) => {
const mountComponent = comp => mount(comp).getComponent();
Expand All @@ -19,8 +20,8 @@ const getComponentInstance = (renderer, input, withAwait) => {
require('marko/components').init();

return withAwait
? renderer.render(JSON.parse(JSON.stringify(input))).then(mountComponent)
: mountComponent(renderer.renderSync(JSON.parse(JSON.stringify(input))));
? renderer.render(clone(input)).then(mountComponent)
: mountComponent(renderer.renderSync(clone(input)));
};

module.exports = (fullPath, withAwait) => (input = {}) => {
Expand Down
3 changes: 3 additions & 0 deletions tests/marko4/components/include/index.marko
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
<include(data.body)/>
</div>
3 changes: 3 additions & 0 deletions tests/marko4/components/include/test/__snapshots__/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
body: { renderBody: out => out.w('body') },
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should render component with default fixture 1`] = `
Array [
,
<div>
body
</div>,
,
]
`;

exports[`should render component with hidden fixture 1`] = `
Array [
,
<div />,
,
]
`;
1 change: 1 addition & 0 deletions tests/marko4/components/include/test/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('marko-tester')('../index.marko');
15 changes: 10 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ caseless@~0.12.0:

chai@^3.5.0:
version "3.5.0"
resolved "https://registry.npmjs.org/chai/-/chai-3.5.0.tgz#4d02637b067fe958bdbfdd3a40ec56fef7373247"
resolved "http://registry.npmjs.org/chai/-/chai-3.5.0.tgz#4d02637b067fe958bdbfdd3a40ec56fef7373247"
integrity sha1-TQJjewZ/6Vi9v906QOxW/vc3Mkc=
dependencies:
assertion-error "^1.0.1"
Expand Down Expand Up @@ -1662,7 +1662,7 @@ decode-uri-component@^0.2.0:

deep-eql@^0.1.3:
version "0.1.3"
resolved "https://registry.npmjs.org/deep-eql/-/deep-eql-0.1.3.tgz#ef558acab8de25206cd713906d74e56930eb69f2"
resolved "http://registry.npmjs.org/deep-eql/-/deep-eql-0.1.3.tgz#ef558acab8de25206cd713906d74e56930eb69f2"
integrity sha1-71WKyrjeJSBs1xOQbXTlaTDrafI=
dependencies:
type-detect "0.1.1"
Expand Down Expand Up @@ -4046,6 +4046,11 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.10.0"

just-clone@^3.1.0:
version "3.1.0"
resolved "https://registry.npmjs.org/just-clone/-/just-clone-3.1.0.tgz#10efc422e9b041355c43b8076d7b768b7a09fbbd"
integrity sha512-sROn15yHaeNYSTG49HmfbQLtsZvMBb2COvVofNXbeUXx6GkERkdjG3dfejD0fe78gdHJLyS+fOz897H73S8LqA==

kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0:
version "3.2.2"
resolved "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64"
Expand Down Expand Up @@ -4548,9 +4553,9 @@ marko-widgets@^7:
raptor-renderer "^1.4.4"

marko@^4.13.5:
version "4.13.5"
resolved "https://registry.npmjs.org/marko/-/marko-4.13.5.tgz#674e2f51d952b173d40a331e29b7f5d260025104"
integrity sha512-gXKiLLQTGGaF2+zaepRwYqHqeMT1xrJoY8QqSkx2qDyPc0FQaJBQGalia9rxZtdtNiaFAyy8lejbNs7bVyloxg==
version "4.13.8"
resolved "https://registry.npmjs.org/marko/-/marko-4.13.8.tgz#2756e8f471951c50d9336a6ea8d5b91a0262dd4c"
integrity sha512-APfb/5KgDswm2fdxZBknxubEgNmXchmGZ1aCV1Brb8eGqHzd8I1xZzykvj1/mDU/bzhsAIYDV2yyC9Os7Ue9AQ==
dependencies:
app-module-path "^2.2.0"
argly "^1.0.0"
Expand Down

0 comments on commit 9832386

Please sign in to comment.