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); + }); +});