diff --git a/packages/ember-cli-fastboot/lib/broccoli/html-writer.js b/packages/ember-cli-fastboot/lib/broccoli/html-writer.js index 07bdff388..f928ade88 100644 --- a/packages/ember-cli-fastboot/lib/broccoli/html-writer.js +++ b/packages/ember-cli-fastboot/lib/broccoli/html-writer.js @@ -25,11 +25,13 @@ module.exports = class BasePageWriter extends Filter { processString(content) { let dom = new JSDOM(content); let scriptTags = dom.window.document.querySelectorAll('script'); - this._ignoreUnexpectedScripts(scriptTags); let fastbootScripts = this._findFastbootScriptToInsert(scriptTags); let appJsTag = findAppJsTag(scriptTags, this._appJsPath, this._rootURL); + if (!appJsTag) { + throw new Error('ember-cli-fastboot cannot find own app script tag'); + } insertFastbootScriptsBeforeAppJsTags(fastbootScripts, appJsTag); return dom.serialize(); @@ -79,6 +81,10 @@ function getRootURL(appName, config) { } function urlWithin(candidate, root) { + // this is a null or relative path + if (!candidate || !candidate.startsWith('/')) { + return candidate; + } let candidateURL = new URL(candidate, 'http://_the_current_origin_'); let rootURL = new URL(root, 'http://_the_current_origin_'); if (candidateURL.href.startsWith(rootURL.href)) { diff --git a/test-packages/basic-app/test/package-json-test.js b/test-packages/basic-app/test/package-json-test.js index 0cc69fc81..31c340f3f 100644 --- a/test-packages/basic-app/test/package-json-test.js +++ b/test-packages/basic-app/test/package-json-test.js @@ -36,7 +36,7 @@ describe("generating package.json", function () { it("contains a schema version", function () { let pkg = fs.readJSONSync("dist/package.json"); - expect(pkg.fastboot.schemaVersion).to.deep.equal(3); + expect(pkg.fastboot.schemaVersion).to.deep.equal(5); }); it("contains a whitelist of allowed module names", function () { @@ -54,25 +54,6 @@ describe("generating package.json", function () { ]); }); - it("contains a manifest of FastBoot assets", function () { - let pkg = fs.readJSONSync("dist/package.json"); - - expect(pkg.fastboot.manifest).to.deep.equal({ - appFiles: [ - "assets/basic-app.js", - "assets/basic-app-fastboot.js", - "example-addon/bar.js", - ], - htmlFile: "index.html", - vendorFiles: [ - "example-addon/foo.js", - "assets/vendor.js", - "assets/auto-import-fastboot.js", - "ember-fetch/fetch-fastboot.js", - ], - }); - }); - it("contains a list of whitelisted hosts from environment.js", function () { let pkg = fs.readJSONSync("dist/package.json"); @@ -86,7 +67,7 @@ describe("generating package.json", function () { it("contains app name", function () { let pkg = fs.readJSONSync("dist/package.json"); - expect(pkg.fastboot.appName).to.equal("basic-app"); + expect(pkg.name).to.equal("basic-app"); }); it("contains the application config", function () { @@ -132,28 +113,5 @@ describe("generating package.json", function () { expect(pkg.fastboot.config["foo"]).to.equal("bar"); }); - - }); - - describe("with production FastBoot builds", function () { - before(async function () { - await execa("yarn", ["build", "--environment=production"]); - }); - - it("contains a manifest of FastBoot assets", function () { - let pkg = fs.readJSONSync("dist/package.json"); - - let manifest = pkg.fastboot.manifest; - - manifest.appFiles.forEach((file) => { - expect(`dist/${file}`).to.be.a.file(); - }); - - expect(`dist/${manifest.htmlFile}`).to.be.a.file(); - - manifest.vendorFiles.forEach((file) => { - expect(`dist/${file}`).to.be.a.file(); - }); - }); }); }); diff --git a/test-packages/custom-fastboot-app/public/custom-index.html b/test-packages/custom-fastboot-app/public/custom-index.html index a21d3d3e3..129015759 100644 --- a/test-packages/custom-fastboot-app/public/custom-index.html +++ b/test-packages/custom-fastboot-app/public/custom-index.html @@ -10,12 +10,12 @@ - + - + diff --git a/test-packages/custom-fastboot-app/test/package-json-test.js b/test-packages/custom-fastboot-app/test/package-json-test.js index 4b0df782c..024fe4b27 100644 --- a/test-packages/custom-fastboot-app/test/package-json-test.js +++ b/test-packages/custom-fastboot-app/test/package-json-test.js @@ -52,10 +52,10 @@ describe("generating package.json", function () { describe('with custom htmlFile', function() { it('uses custom htmlFile in the manifest', function() { let pkg = fs.readJSONSync("dist/package.json"); - let manifest = pkg.fastboot.manifest; + let { htmlEntrypoint} = pkg.fastboot; - expect(manifest.htmlFile).to.equal('custom-index.html'); - expect(`dist/${manifest.htmlFile}`).to.be.a.file(); + expect(htmlEntrypoint).to.equal('custom-index.html'); + expect(`dist/${htmlEntrypoint}`).to.be.a.file(); }); }); });