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

Commit

Permalink
Fix react rendering method used when clientScripts is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
MoOx committed Nov 15, 2016
1 parent 1eaf316 commit 233b0ef
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 23 deletions.
8 changes: 1 addition & 7 deletions src/static/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ test("don't break if there is nothing to transform", async (t) => {
.then((files) => {
t.is(files.length, 0)
})
.catch((error) => {
t.fail(error)
})
})

test("writeAllHTMLFiles", (t) => {
Expand All @@ -48,14 +45,11 @@ test("writeAllHTMLFiles", (t) => {
if (!expectedHTML[filename]) {
throw new Error(filename + " is missing in expectedHTML results")
}
t.deepEqual(
t.is(
beautifyHTML(html),
expectedHTML[filename](),
)
},
forgetPageData: () => {},
}, true)
.catch((error) => {
t.fail(error)
})
})
3 changes: 2 additions & 1 deletion src/static/__tests__/results/destination/index.html.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-len */
import htmlMetas from "../../../../_utils/html-metas"

export default () => (
Expand All @@ -13,7 +14,7 @@ export default () => (
<body>
<div id="phenomic">
<p>TestContainer</p>
<p data-reactroot="" data-reactid="1" data-react-checksum="305402615">TestContainer</p>
</div>
<script>
window.__COLLECTION__ = [{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-len */
import htmlMetas from "../../../../../_utils/html-metas"

export default () => (
Expand All @@ -13,7 +14,7 @@ export default () => (
<body>
<div id="phenomic">
<p>TestContainer</p>
<p data-reactroot="" data-reactid="1" data-react-checksum="305402615">TestContainer</p>
</div>
<script>
window.__COLLECTION__ = [{
Expand Down
3 changes: 2 additions & 1 deletion src/static/__tests__/results/destination/test/index.html.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-len */
import htmlMetas from "../../../../../_utils/html-metas"

export default () => (
Expand All @@ -13,7 +14,7 @@ export default () => (
<body>
<div id="phenomic">
<p>ReactTestContainer</p>
<p data-reactroot="" data-reactid="1" data-react-checksum="2007307494">ReactTestContainer</p>
</div>
<script>
window.__COLLECTION__ = [{
Expand Down
15 changes: 7 additions & 8 deletions src/static/__tests__/url-as-html.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable max-len */

import url from "url"

import test from "jest-ava-api"
Expand All @@ -23,7 +25,6 @@ test("url as html", async (t) => {
clientScripts: true,
},
undefined, // Html
true
)

const expectedHTML = (
Expand All @@ -37,7 +38,7 @@ test("url as html", async (t) => {
<body>
<div id="phenomic">
<p>TestContainer</p>
<p data-reactroot="" data-reactid="1" data-react-checksum="305402615">TestContainer</p>
</div>
<script>
window.__COLLECTION__ = [{
Expand Down Expand Up @@ -76,7 +77,6 @@ test("url as html without JS", async (t) => {
clientScripts: false,
},
undefined, // Html
true
)

const expectedHTML = (
Expand Down Expand Up @@ -117,7 +117,6 @@ test("baseUrl with offline support", async (t) => {
clientScripts: true,
},
undefined, // Html
true
)

const expectedHTML = (
Expand All @@ -131,7 +130,7 @@ test("baseUrl with offline support", async (t) => {
<body>
<div id="phenomic">
<p>TestContainer</p>
<p data-reactroot="" data-reactid="1" data-react-checksum="305402615">TestContainer</p>
</div>
<script>
window.__COLLECTION__ = [{
Expand Down Expand Up @@ -170,7 +169,6 @@ test("custom script tags", async (t) => {
clientScripts: true,
},
undefined, // Html
true
)

const expectedHTML = (
Expand All @@ -184,8 +182,9 @@ test("custom script tags", async (t) => {
<body>
<div id="phenomic">
<div>
<p>TestContainer</p>
<div data-reactroot="" data-reactid="1" data-react-checksum="1089807005">
<!-- react-empty: 2 -->
<p data-reactid="3">TestContainer</p>
</div>
</div>
<script>
Expand Down
9 changes: 4 additions & 5 deletions src/static/url-as-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import minifyCollection from "../loader/minify"
export default function(
url: string,
options: PhenomicStaticConfig,
Html: Function = DefaultHtml,
testing?: boolean
Html: Function = DefaultHtml
): Promise<string> {

const {
Expand All @@ -30,9 +29,9 @@ export default function(
} = options

const render = ReactDOMserver[
!testing
? "renderToString"
: "renderToStaticMarkup"
(!options.clientScripts)
? "renderToStaticMarkup"
: "renderToString"
]

return new Promise((resolve, reject) => {
Expand Down

0 comments on commit 233b0ef

Please sign in to comment.