Navigation Menu

Skip to content

Commit

Permalink
Expose distPath on reload event (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhammond committed May 6, 2020
1 parent bc36d74 commit 87bdbc6
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/fastboot-app-server.js
Expand Up @@ -146,7 +146,7 @@ class FastBootAppServer {
}

reload() {
this.broadcast({ event: 'reload' });
this.broadcast({ event: 'reload', distPath: this.distPath });
}

forkWorkers() {
Expand Down
4 changes: 3 additions & 1 deletion src/worker.js
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions test/app-server-test.js
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/basic-app/index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>FastbootTest</title>
<title>FastbootTest - basic</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/broken-app/index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>FastbootTest</title>
<title>FastbootTest - broken</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

Expand Down
48 changes: 48 additions & 0 deletions 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();
});
}
2 changes: 1 addition & 1 deletion test/fixtures/global-app/index.html
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>FastbootTest</title>
<title>FastbootTest - global</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

Expand Down

0 comments on commit 87bdbc6

Please sign in to comment.