Skip to content

Commit dba30be

Browse files
committed
hold promise until server responds
1 parent a3ceac9 commit dba30be

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

test/cli.test.js

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@ test('setting port via cli - custom port', (t) => {
5050
t.plan(2);
5151

5252
getPort().then((port) => {
53-
const options = ['.', '--port', port];
54-
const server = startServer(options);
53+
return new Promise((resolve) => {
54+
const options = ['.', '--port', port];
55+
const server = startServer(options);
5556

56-
tearDown(server, t);
57+
tearDown(server, t);
5758

58-
server.stdout.on('data', (msg) => {
59-
checkServerIsRunning(`http://localhost:${port}`, msg, t);
59+
server.stdout.on('data', (msg) => {
60+
checkServerIsRunning(`http://localhost:${port}`, msg, t);
61+
resolve();
62+
});
6063
});
6164
});
6265
});
@@ -65,17 +68,20 @@ test('setting mimeTypes via cli - .types file', (t) => {
6568
t.plan(4);
6669

6770
getPort().then((port) => {
68-
const root = path.resolve(__dirname, 'public/');
69-
const pathMimetypeFile = path.resolve(__dirname, 'fixtures/custom_mime_type.types');
70-
const options = [root, '--port', port, '--mimetypes', pathMimetypeFile];
71-
const server = startServer(options);
72-
73-
tearDown(server, t);
74-
75-
server.stdout.on('data', (msg) => {
76-
checkServerIsRunning(`http://localhost:${port}/custom_mime_type.opml`, msg, t, (err, res) => {
77-
t.error(err);
78-
t.equal(res.headers['content-type'], 'application/secret');
71+
return new Promise((resolve) => {
72+
const root = path.resolve(__dirname, 'public/');
73+
const pathMimetypeFile = path.resolve(__dirname, 'fixtures/custom_mime_type.types');
74+
const options = [root, '--port', port, '--mimetypes', pathMimetypeFile];
75+
const server = startServer(options);
76+
77+
tearDown(server, t);
78+
79+
server.stdout.on('data', (msg) => {
80+
checkServerIsRunning(`http://localhost:${port}/custom_mime_type.opml`, msg, t, (err, res) => {
81+
t.error(err);
82+
t.equal(res.headers['content-type'], 'application/secret');
83+
resolve();
84+
});
7985
});
8086
});
8187
});
@@ -85,18 +91,21 @@ test('setting mimeTypes via cli - directly', (t) => {
8591
t.plan(4);
8692

8793
getPort().then((port) => {
88-
const root = path.resolve(__dirname, 'public/');
89-
const mimeType = ['--mimetypes', '{ "application/x-my-type": ["opml"] }'];
90-
const options = [root, '--port', port].concat(mimeType);
91-
const server = startServer(options);
92-
93-
// TODO: remove error handler
94-
tearDown(server, t);
95-
96-
server.stdout.on('data', (msg) => {
97-
checkServerIsRunning(`http://localhost:${port}/custom_mime_type.opml`, msg, t, (err, res) => {
98-
t.error(err);
99-
t.equal(res.headers['content-type'], 'application/x-my-type');
94+
return new Promise((resolve) => {
95+
const root = path.resolve(__dirname, 'public/');
96+
const mimeType = ['--mimetypes', '{ "application/x-my-type": ["opml"] }'];
97+
const options = [root, '--port', port].concat(mimeType);
98+
const server = startServer(options);
99+
100+
// TODO: remove error handler
101+
tearDown(server, t);
102+
103+
server.stdout.on('data', (msg) => {
104+
checkServerIsRunning(`http://localhost:${port}/custom_mime_type.opml`, msg, t, (err, res) => {
105+
t.error(err);
106+
t.equal(res.headers['content-type'], 'application/x-my-type');
107+
resolve();
108+
});
100109
});
101110
});
102111
});

0 commit comments

Comments
 (0)