From 1b5842365278b47fb13b6a6f5b48f7968e5ff64c Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 9 Mar 2022 09:16:30 +0000 Subject: [PATCH] fix: Ensure empty file prerender state works no matter how meta tag looks It seems in newer versions of puppeteer, it can be serialized as `` without closing tag, which breaks with the current setup. Now, we handle open, open+close, and self-closing tags. --- .../lib/utils/fix-prerender-in-empty-file.js | 6 +++ .../lib/utils/merge-prerender.js | 7 ++- .../unit/fix-prerender-in-empty-file-test.js | 48 +++++++++++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 packages/ember-build-prerender/lib/utils/fix-prerender-in-empty-file.js create mode 100644 packages/test-app/node-tests/unit/fix-prerender-in-empty-file-test.js diff --git a/packages/ember-build-prerender/lib/utils/fix-prerender-in-empty-file.js b/packages/ember-build-prerender/lib/utils/fix-prerender-in-empty-file.js new file mode 100644 index 0000000..fd05b8e --- /dev/null +++ b/packages/ember-build-prerender/lib/utils/fix-prerender-in-empty-file.js @@ -0,0 +1,6 @@ +module.exports = function fixPrerenderInEmptyFile(emptyFileContent) { + return emptyFileContent.replace( + '', - '' - ); + emptyFileContent = fixPrerenderInEmptyFile(emptyFileContent); + await fs.writeFile(emptyFilePath, emptyFileContent, 'utf-8'); await fs.remove(buildDir); diff --git a/packages/test-app/node-tests/unit/fix-prerender-in-empty-file-test.js b/packages/test-app/node-tests/unit/fix-prerender-in-empty-file-test.js new file mode 100644 index 0000000..59c378b --- /dev/null +++ b/packages/test-app/node-tests/unit/fix-prerender-in-empty-file-test.js @@ -0,0 +1,48 @@ +const { expect } = require('chai'); +const fixPrerenderInEmptyFile = require('ember-build-prerender/lib/utils/fix-prerender-in-empty-file'); + +describe('fix-prerender-in-empty-file', function () { + it('it works with empty string', async function () { + let source = ``; + let expected = ``; + let result = fixPrerenderInEmptyFile(source); + + expect(result).to.equal(expected); + }); + + it('it works with self-closing tag', async function () { + let source = ` + +`; + let expected = ` + +`; + let result = fixPrerenderInEmptyFile(source); + + expect(result).to.equal(expected); + }); + + it('it works with closing tag', async function () { + let source = ` + +`; + let expected = ` + +`; + let result = fixPrerenderInEmptyFile(source); + + expect(result).to.equal(expected); + }); + + it('it works with only open tag', async function () { + let source = ` + +`; + let expected = ` + +`; + let result = fixPrerenderInEmptyFile(source); + + expect(result).to.equal(expected); + }); +});