Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose distPath on reload event #96

Merged
merged 2 commits into from May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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