Skip to content

Commit

Permalink
Fix incorrect tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xg-wang committed Apr 8, 2021
1 parent c4d2dbc commit 00dc159
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 50 deletions.
8 changes: 7 additions & 1 deletion packages/ember-cli-fastboot/lib/broccoli/html-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)) {
Expand Down
46 changes: 2 additions & 44 deletions test-packages/basic-app/test/package-json-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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");

Expand All @@ -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 () {
Expand Down Expand Up @@ -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();
});
});
});
});
4 changes: 2 additions & 2 deletions test-packages/custom-fastboot-app/public/custom-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
<!-- EMBER_CLI_FASTBOOT_HEAD -->

<link rel="stylesheet" href="assets/vendor.css">
<link rel="stylesheet" href="assets/custom-html-file.css">
<link rel="stylesheet" href="assets/custom-fastboot-app.css">
</head>
<body>
<!-- EMBER_CLI_FASTBOOT_BODY -->

<script src="assets/vendor.js"></script>
<script src="assets/custom-html-file.js"></script>
<script src="assets/custom-fastboot-app.js"></script>
</body>
</html>
6 changes: 3 additions & 3 deletions test-packages/custom-fastboot-app/test/package-json-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
Expand Down

0 comments on commit 00dc159

Please sign in to comment.