Skip to content

Commit fe9d653

Browse files
committed
change teardown order
1 parent dba30be commit fe9d653

File tree

1 file changed

+25
-37
lines changed

1 file changed

+25
-37
lines changed

test/cli.test.js

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

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

56+
server.stdout.on('data', (msg) => {
57+
checkServerIsRunning(`http://localhost:${port}`, msg, t);
5758
tearDown(server, t);
58-
59-
server.stdout.on('data', (msg) => {
60-
checkServerIsRunning(`http://localhost:${port}`, msg, t);
61-
resolve();
62-
});
6359
});
6460
});
6561
});
@@ -68,20 +64,17 @@ test('setting mimeTypes via cli - .types file', (t) => {
6864
t.plan(4);
6965

7066
getPort().then((port) => {
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);
67+
const root = path.resolve(__dirname, 'public/');
68+
const pathMimetypeFile = path.resolve(__dirname, 'fixtures/custom_mime_type.types');
69+
const options = [root, '--port', port, '--mimetypes', pathMimetypeFile];
70+
const server = startServer(options);
7671

77-
tearDown(server, t);
7872

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-
});
73+
server.stdout.on('data', (msg) => {
74+
checkServerIsRunning(`http://localhost:${port}/custom_mime_type.opml`, msg, t, (err, res) => {
75+
t.error(err);
76+
t.equal(res.headers['content-type'], 'application/secret');
77+
tearDown(server, t);
8578
});
8679
});
8780
});
@@ -91,21 +84,16 @@ test('setting mimeTypes via cli - directly', (t) => {
9184
t.plan(4);
9285

9386
getPort().then((port) => {
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-
});
87+
const root = path.resolve(__dirname, 'public/');
88+
const mimeType = ['--mimetypes', '{ "application/x-my-type": ["opml"] }'];
89+
const options = [root, '--port', port].concat(mimeType);
90+
const server = startServer(options);
91+
92+
server.stdout.on('data', (msg) => {
93+
checkServerIsRunning(`http://localhost:${port}/custom_mime_type.opml`, msg, t, (err, res) => {
94+
t.error(err);
95+
t.equal(res.headers['content-type'], 'application/x-my-type');
96+
tearDown(server, t);
10997
});
11098
});
11199
});
@@ -117,9 +105,9 @@ test('--proxy requires you to specify a protocol', (t) => {
117105
const options = ['.', '--proxy', 'google.com'];
118106
const server = startServer(options);
119107

120-
tearDown(server, t);
121-
122108
server.on('exit', (code) => {
123109
t.equal(code, 1);
124110
});
111+
112+
tearDown(server, t);
125113
});

0 commit comments

Comments
 (0)