Skip to content

Commit 71f3ca4

Browse files
committed
Fix failing tests
1 parent 6f3f756 commit 71f3ca4

4 files changed

Lines changed: 49 additions & 12 deletions

File tree

lib/fastboot-app-server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class FastBootAppServer {
3232

3333
this.worker.start();
3434
} else {
35-
this.workerCount = options.workerCount || os.cpus().length;
35+
this.workerCount = options.workerCount ||
36+
(process.env.NODE_ENV === 'test' ? 1 : null) ||
37+
os.cpus().length;
3638

3739
assert(this.distPath || this.downloader, "FastBootAppServer must be provided with either a distPath or a downloader option.");
3840
assert(!(this.distPath && this.downloader), "FastBootAppServer must be provided with either a distPath or a downloader option, but not both.");

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "A production-ready app server for running Ember FastBoot apps",
55
"main": "lib/fastboot-app-server.js",
66
"scripts": {
7-
"test": "mocha"
7+
"test": "NODE_ENV=test mocha"
88
},
99
"repository": {
1010
"type": "git",

test/app-server-test.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
"use strict";
22

3+
const path = require('path');
4+
const fork = require('child_process').fork;
35
const expect = require('chai').expect;
46
const FastBootAppServer = require('../lib/fastboot-app-server');
57
const request = require('request-promise').defaults({ simple: false, resolveWithFullResponse: true });
68

9+
let server;
10+
711
describe("FastBootAppServer", function() {
812
this.timeout(3000);
913

14+
afterEach(function() {
15+
if (server) {
16+
server.kill();
17+
}
18+
});
19+
1020
it("throws if no distPath or downloader is provided", function() {
1121
expect(() => {
1222
new FastBootAppServer();
@@ -23,16 +33,7 @@ describe("FastBootAppServer", function() {
2333
});
2434

2535
it("serves an HTTP 500 response if the app can't be found", function() {
26-
let server = new FastBootAppServer({
27-
workerCount: 1,
28-
downloader: {
29-
download() {
30-
return Promise.resolve();
31-
}
32-
}
33-
});
34-
35-
return server.start()
36+
return runServer('not-found-server')
3637
.then(() => request('http://localhost:3000'))
3738
.then(response => {
3839
expect(response.statusCode).to.equal(500);
@@ -41,3 +42,24 @@ describe("FastBootAppServer", function() {
4142
});
4243

4344
});
45+
46+
function runServer(name) {
47+
return new Promise((res, rej) => {
48+
let serverPath = path.join(__dirname, 'fixtures', `${name}.js`);
49+
server = fork(serverPath, {
50+
silent: true
51+
});
52+
53+
server.on('error', rej);
54+
55+
server.stdout.on('data', data => {
56+
if (data.toString().match(/HTTP server started/)) {
57+
res();
58+
}
59+
});
60+
61+
server.stderr.on('data', data => {
62+
console.log(data.toString());
63+
});
64+
});
65+
}

test/fixtures/not-found-server.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
const FastBootAppServer = require('../../lib/fastboot-app-server.js');
4+
5+
let server = new FastBootAppServer({
6+
downloader: {
7+
download() {
8+
return Promise.resolve();
9+
}
10+
}
11+
});
12+
13+
server.start();

0 commit comments

Comments
 (0)