From 6bd1e500b541d91049fad4d0d227fa77f34fc80c Mon Sep 17 00:00:00 2001 From: Nathan Hammond Date: Fri, 22 Feb 2019 12:27:05 -0800 Subject: [PATCH 1/2] Failing test for changing distPath. --- test/app-server-test.js | 9 +++++ test/fixtures/basic-app/index.html | 2 +- test/fixtures/broken-app/index.html | 2 +- test/fixtures/dist-path-change-server.js | 48 ++++++++++++++++++++++++ test/fixtures/global-app/index.html | 2 +- 5 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/dist-path-change-server.js diff --git a/test/app-server-test.js b/test/app-server-test.js index 2e3edc9d..6ac7b509 100644 --- a/test/app-server-test.js +++ b/test/app-server-test.js @@ -119,6 +119,15 @@ describe("FastBootAppServer", function() { expect(response.body).to.contain('Welcome to Ember from MY GLOBAL!'); }); }); + + it("allows changing of distpath", function() { + return runServer('dist-path-change-server') + .then(() => request('http://localhost:3000/')) + .then((response) => { + expect(response.statusCode).to.equal(200); + expect(response.body).to.contain('Welcome to Ember from MY GLOBAL!'); + }); + }); }); function runServer(name) { diff --git a/test/fixtures/basic-app/index.html b/test/fixtures/basic-app/index.html index c9a0d7ec..efcb8665 100644 --- a/test/fixtures/basic-app/index.html +++ b/test/fixtures/basic-app/index.html @@ -3,7 +3,7 @@ - FastbootTest + FastbootTest - basic diff --git a/test/fixtures/broken-app/index.html b/test/fixtures/broken-app/index.html index c9a0d7ec..c079d7a9 100644 --- a/test/fixtures/broken-app/index.html +++ b/test/fixtures/broken-app/index.html @@ -3,7 +3,7 @@ - FastbootTest + FastbootTest - broken diff --git a/test/fixtures/dist-path-change-server.js b/test/fixtures/dist-path-change-server.js new file mode 100644 index 00000000..02e97428 --- /dev/null +++ b/test/fixtures/dist-path-change-server.js @@ -0,0 +1,48 @@ +'use strict'; + +const path = require('path'); +const FastBootAppServer = require('../../src/fastboot-app-server'); + +const MY_GLOBAL = 'MY GLOBAL'; + +class DownloaderNotifier { + constructor(options) { + this.distPath = options.distPath; + this.subscriptions = []; + } + + subscribe(handler) { + this.subscriptions.push(handler); + return Promise.resolve(); + } + + trigger() { + this.distPath = path.resolve(__dirname, './global-app'); + this.subscriptions.forEach(handler => { + handler(); + }); + } + + download() { + return Promise.resolve(this.distPath); + } +} + +const connector = new DownloaderNotifier({ + distPath: path.resolve(__dirname, './basic-app') +}); + +var server = new FastBootAppServer({ + notifier: connector, + downloader: connector, + sandboxGlobals: { THE_GLOBAL: MY_GLOBAL } +}); + +const serverPromise = server.start(); + +// Don't run this on worker threads. +if (serverPromise) { + serverPromise.then(() => { + connector.trigger(); + }); +} diff --git a/test/fixtures/global-app/index.html b/test/fixtures/global-app/index.html index 0450b5d9..8e991d10 100644 --- a/test/fixtures/global-app/index.html +++ b/test/fixtures/global-app/index.html @@ -3,7 +3,7 @@ - FastbootTest + FastbootTest - global From ef0c5295d5e31a01ceef272d2ee8b27c5152dd25 Mon Sep 17 00:00:00 2001 From: Nathan Hammond Date: Fri, 22 Feb 2019 12:27:46 -0800 Subject: [PATCH 2/2] Support changing of distPath. --- src/fastboot-app-server.js | 2 +- src/worker.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fastboot-app-server.js b/src/fastboot-app-server.js index fa1340ed..08fe2612 100644 --- a/src/fastboot-app-server.js +++ b/src/fastboot-app-server.js @@ -146,7 +146,7 @@ class FastBootAppServer { } reload() { - this.broadcast({ event: 'reload' }); + this.broadcast({ event: 'reload', distPath: this.distPath }); } forkWorkers() { diff --git a/src/worker.js b/src/worker.js index 72f83151..f0ea3272 100644 --- a/src/worker.js +++ b/src/worker.js @@ -59,7 +59,9 @@ class Worker { handleMessage(message) { switch (message.event) { case 'reload': - this.fastboot.reload(); + this.distPath = message.distPath || this.distPath; + this.ui.writeLine('Reloading the application from distPath:', this.distPath); + this.fastboot.reload({ distPath: this.distPath }); break; case 'error': this.error = message.error;