From 7ff3fae31236d93dd87e9497e45ad5b0abe75071 Mon Sep 17 00:00:00 2001 From: Matt Travi Date: Fri, 14 Dec 2018 14:19:57 -0600 Subject: [PATCH] chore(rendered-content): nested html under rendered-content to make room for additional content from custom rendering functions BREAKING CHANGE: the shape of rendered content has changed from a string to an object. the previous string content is now provided as an `html` property of the object --- example/layout.mustache | 2 +- src/router-wrapper.js | 12 +++++++----- .../features/step_definitions/render-steps.js | 6 +++--- test/unit/router-wrapper-test.js | 6 +++--- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/example/layout.mustache b/example/layout.mustache index 797a1988..a6528a06 100644 --- a/example/layout.mustache +++ b/example/layout.mustache @@ -5,7 +5,7 @@ -
{{{ renderedContent }}}
+
{{{ renderedContent.html }}}
diff --git a/src/router-wrapper.js b/src/router-wrapper.js index 75302294..9762f8fe 100644 --- a/src/router-wrapper.js +++ b/src/router-wrapper.js @@ -27,11 +27,13 @@ export default async function renderThroughReactRouter(request, h, {routes, resp return respond(h, { store, status, - renderedContent: renderToString(( - - - - )) + renderedContent: { + html: renderToString(( + + + + )) + } }); } } catch (e) { diff --git a/test/integration/features/step_definitions/render-steps.js b/test/integration/features/step_definitions/render-steps.js index 5af7ac4a..d9f5b02d 100644 --- a/test/integration/features/step_definitions/render-steps.js +++ b/test/integration/features/step_definitions/render-steps.js @@ -2,18 +2,18 @@ import {OK} from 'http-status-codes'; import {assert} from 'chai'; import {When, Then} from 'cucumber'; -When('a request is made for an existing route', function () { +When(/^a request is made for an existing route$/, function () { return this.makeRequest({url: '/existing-route'}); }); -Then('the route is rendered successfully', function (callback) { +Then(/^the route is rendered successfully$/, function (callback) { assert.equal(this.serverResponse.statusCode, OK); assert.equal(this.serverResponse.headers['content-type'], 'text/html; charset=utf-8'); callback(); }); -Then('asynchronously fetched data is included in the page', function (callback) { +Then(/^asynchronously fetched data is included in the page$/, function (callback) { assert.include(this.serverResponse.payload, this.dataPoint); callback(); diff --git a/test/unit/router-wrapper-test.js b/test/unit/router-wrapper-test.js index c28fd627..08836f90 100644 --- a/test/unit/router-wrapper-test.js +++ b/test/unit/router-wrapper-test.js @@ -38,14 +38,14 @@ suite('router-wrapper', () => { const status = any.integer(); const context = any.simpleObject(); const rootComponent = any.simpleObject(); - const renderedContent = any.string(); + const html = any.string(); const response = any.string(); routeMatcher.default.withArgs(url, routes).resolves({renderProps, status}); dataFetcher.default.withArgs({renderProps, store, status}).resolves({renderProps, status}); React.createElement.withArgs(RouterContext, sinon.match(renderProps)).returns(context); React.createElement.withArgs(Root, {request, store}).returns(rootComponent); - domServer.renderToString.withArgs(rootComponent).returns(renderedContent); - respond.withArgs(reply, {renderedContent, store, status}).returns(response); + domServer.renderToString.withArgs(rootComponent).returns(html); + respond.withArgs(reply, {renderedContent: {html}, store, status}).returns(response); return assert.becomes(renderThroughReactRouter(request, reply, {routes, respond, Root, store}), response); });