Skip to content

Commit

Permalink
Merge pull request ember-fastboot#194 from dnalagatla/dnalagatla/upda…
Browse files Browse the repository at this point in the history
…te_body_in_domContents

Moved the script tag fastboot-body-start boundary in _finalizeHTML method
  • Loading branch information
kratiahuja committed Sep 11, 2018
2 parents e8e570d + 3a5042d commit f61ab1b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ class Result {
body = HTMLSerializer.serializeChildren(body);

this._head = head;
this._body = body;

// Adding script boundary around the body
this._body = `<script type="x/boundary" id="fastboot-body-start"></script>${body}<script type="x/boundary" id="fastboot-body-end"></script>`;
}
}

Expand All @@ -190,7 +192,7 @@ function insertIntoIndexHTML(html, htmlAttributes, head, body, bodyAttributes) {
return head;
} else if (tag === 'BODY' && body && !isBodyReplaced) {
isBodyReplaced = true;
return '<script type="x/boundary" id="fastboot-body-start"></script>' + body + '<script type="x/boundary" id="fastboot-body-end"></script>';
return body;
}
return '';
});
Expand Down
23 changes: 23 additions & 0 deletions test/result-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,27 @@ describe('Result', function() {
});
});
});

describe('domContents()', function() {
var HEAD = '<meta name="foo" content="bar">';
var BODY = '<h1>A normal response document</h1>';
var boundaryStartTag = '<script type="x/boundary" id="fastboot-body-start"></script>';
var boundaryEndTag = '<script type="x/boundary" id="fastboot-body-end"></script>';

beforeEach(function () {
doc.head.appendChild(doc.createRawHTMLSection(HEAD));
doc.body.appendChild(doc.createRawHTMLSection(BODY));

result._finalize();
});

it('should return the FastBoot-rendered document body', function () {
var domContents = result.domContents();
expect(domContents.head).to.include(HEAD);
expect(domContents.body).to.include(BODY);
expect(domContents.body).to.include(boundaryStartTag);
expect(domContents.body).to.include(boundaryEndTag);
expect(domContents.body).to.equal(boundaryStartTag+BODY+boundaryEndTag);
});
});
});

0 comments on commit f61ab1b

Please sign in to comment.