Skip to content

Fix Tests #893

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

Merged
merged 3 commits into from
Sep 20, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions test/304.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test('304_not_modified_strong', (t) => {
t.equal(res2.statusCode, 304, 'second request should be a 304');
t.equal(res2.headers.etag.indexOf('"'), 0, 'should return a strong etag');
server.close();
t.end();
setTimeout(() => { t.end(); }, 0);
});
});
});
Expand Down Expand Up @@ -97,7 +97,7 @@ test('304_not_modified_weak', (t) => {
t.equal(res2.statusCode, 304, 'second request should be a 304');
t.equal(res2.headers.etag.indexOf('W/'), 0, 'should return a weak etag');
server.close();
t.end();
setTimeout(() => { t.end(); }, 0);
});
});
});
Expand Down Expand Up @@ -164,7 +164,7 @@ test('304_not_modified_strong_compare', (t) => {
// https://www.ietf.org/rfc/rfc2616.txt
t.equal(res3.statusCode, 200, 'third request with a weak etag should be 200');
server.close();
t.end();
setTimeout(() => { t.end(); }, 0);
});
});
});
Expand Down Expand Up @@ -227,7 +227,7 @@ test('304_not_modified_weak_compare', (t) => {

t.equal(res3.statusCode, 304, 'third request with a weak etag should be 304');
server.close();
t.end();
setTimeout(() => { t.end(); }, 0);
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/accept-encoding.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test('properly handles whitespace in accept-encoding', (t) => {
};

request.get(options, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200);
t.equal(res.headers['content-encoding'], 'gzip');
});
Expand Down Expand Up @@ -55,7 +55,7 @@ test('properly handles single accept-encoding entry', (t) => {
};

request.get(options, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200);
t.equal(res.headers['content-encoding'], 'gzip');
});
Expand Down
12 changes: 6 additions & 6 deletions test/cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test('custom cache option number', (t) => {
server.listen(0, () => {
const port = server.address().port;
request.get(`http://localhost:${port}/a.txt`, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200, 'a.txt should be found');
t.equal(res.headers['cache-control'], 'max-age=3600');
server.close(() => { t.end(); });
Expand All @@ -47,7 +47,7 @@ test('custom cache option string', (t) => {
server.listen(0, () => {
const port = server.address().port;
request.get(`http://localhost:${port}/a.txt`, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200, 'a.txt should be found');
t.equal(res.headers['cache-control'], 'max-whatever=3600');
server.close(() => { t.end(); });
Expand Down Expand Up @@ -76,12 +76,12 @@ test('custom cache option function returning a number', (t) => {
server.listen(0, () => {
const port = server.address().port;
request.get(`http://localhost:${port}/a.txt`, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200, 'a.txt should be found');
t.equal(res.headers['cache-control'], 'max-age=1');

request.get(`http://localhost:${port}/a.txt`, (err2, res2) => {
t.ifError(err2);
t.error(err2);
t.equal(res2.statusCode, 200, 'a.txt should be found');
t.equal(res2.headers['cache-control'], 'max-age=2');
server.close(() => { t.end(); });
Expand Down Expand Up @@ -111,12 +111,12 @@ test('custom cache option function returning a string', (t) => {
server.listen(0, () => {
const port = server.address().port;
request.get(`http://localhost:${port}/a.txt`, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200, 'a.txt should be found');
t.equal(res.headers['cache-control'], 'max-meh=1');

request.get(`http://localhost:${port}/a.txt`, (err2, res2) => {
t.ifError(err2);
t.error(err2);
t.equal(res2.statusCode, 200, 'a.txt should be found');
t.equal(res2.headers['cache-control'], 'max-meh=2');
server.close(() => { t.end(); });
Expand Down
2 changes: 1 addition & 1 deletion test/check-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = (t, server, path, check) => {
const uri = `http://localhost:${port}/${path}`;

request.get({ uri }, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200);
check(t, res.headers);
});
Expand Down
2 changes: 1 addition & 1 deletion test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function checkServerIsRunning(url, msg, t, _cb) {
}

function tearDown(ps, t) {
t.tearDown(() => {
t.teardown(() => {
ps.kill('SIGTERM');
});
}
Expand Down
12 changes: 6 additions & 6 deletions test/compression.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test('serves brotli-encoded file when available', (t) => {
};

request.get(options, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200);
t.equal(res.headers['content-encoding'], 'br');
});
Expand Down Expand Up @@ -56,7 +56,7 @@ test('serves gzip-encoded file when brotli not available', (t) => {
};

request.get(options, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200);
t.equal(res.headers['content-encoding'], 'gzip');
});
Expand Down Expand Up @@ -86,7 +86,7 @@ test('serves gzip-encoded file when brotli not accepted', (t) => {
};

request.get(options, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200);
t.equal(res.headers['content-encoding'], 'gzip');
});
Expand Down Expand Up @@ -116,7 +116,7 @@ test('serves gzip-encoded file when brotli not enabled', (t) => {
};

request.get(options, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200);
t.equal(res.headers['content-encoding'], 'gzip');
});
Expand Down Expand Up @@ -146,7 +146,7 @@ test('serves unencoded file when compression not accepted', (t) => {
};

request.get(options, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200);
t.equal(res.headers['content-encoding'], undefined);
});
Expand Down Expand Up @@ -176,7 +176,7 @@ test('serves unencoded file when compression not enabled', (t) => {
};

request.get(options, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200);
t.equal(res.headers['content-encoding'], undefined);
});
Expand Down
8 changes: 4 additions & 4 deletions test/cors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('cors defaults to false', (t) => {
const uri = `http://localhost:${port}/subdir/index.html`;

request.get({ uri }, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200);
t.type(res.headers['access-control-allow-origin'], 'undefined');
t.type(res.headers['access-control-allow-headers'], 'undefined');
Expand Down Expand Up @@ -52,7 +52,7 @@ test('cors set to false', (t) => {
const uri = `http://localhost:${port}/subdir/index.html`;

request.get({ uri }, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200);
t.type(res.headers['access-control-allow-origin'], 'undefined');
t.type(res.headers['access-control-allow-headers'], 'undefined');
Expand All @@ -79,7 +79,7 @@ test('cors set to true', (t) => {
const port = httpServer.address().port;
const uri = `http://localhost:${port}/subdir/index.html`;
request.get({ uri }, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200);
t.equal(res.headers['access-control-allow-origin'], '*');
t.equal(res.headers['access-control-allow-headers'], 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since');
Expand All @@ -106,7 +106,7 @@ test('CORS set to true', (t) => {
const port = httpServer.address().port;
const uri = `http://localhost:${port}/subdir/index.html`;
request.get({ uri }, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200);
t.equal(res.headers['access-control-allow-origin'], '*');
t.equal(res.headers['access-control-allow-headers'], 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since');
Expand Down
2 changes: 1 addition & 1 deletion test/custom-content-type-file-secret.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test('custom contentType via .types file', (t) => {
server.listen(0, () => {
const port = server.address().port;
request.get(`http://localhost:${port}/custom_mime_type.opml`, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200, 'custom_mime_type.opml should be found');
t.equal(res.headers['content-type'], 'application/secret');
server.close(() => { t.end(); });
Expand Down
2 changes: 1 addition & 1 deletion test/custom-content-type-file.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test('custom contentType via .types file', (t) => {
const port = server.address().port;

request.get(`http://localhost:${port}/custom_mime_type.opml`, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200, 'custom_mime_type.opml should be found');
t.equal(res.headers['content-type'], 'application/foo');
server.close(() => { t.end(); });
Expand Down
2 changes: 1 addition & 1 deletion test/custom-content-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('custom contentType', (t) => {
server.listen(0, () => {
const port = server.address().port;
request.get(`http://localhost:${port}/custom_mime_type.opml`, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200, 'custom_mime_type.opml should be found');
t.equal(res.headers['content-type'], 'application/jon');
server.close(() => { t.end(); });
Expand Down
2 changes: 1 addition & 1 deletion test/default-default-ext.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('default defaultExt', (t) => {
server.listen(0, () => {
const port = server.address().port;
request.get(`http://localhost:${port}`, (err, res, body) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200);
t.equal(eol.lf(body), 'index!!!\n');
server.close(() => { t.end(); });
Expand Down
2 changes: 1 addition & 1 deletion test/enotdir.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('should handle ENOTDIR as 404', (t) => {
server.listen(0, () => {
const port = server.address().port;
request.get(`http://localhost:${port}/index.html/hello`, (err, res, body) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 404);
t.equal(body, 'File not found. :(');
});
Expand Down
2 changes: 1 addition & 1 deletion test/escaping.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('escaping special characters', (t) => {
server.listen(0, () => {
const port = server.address().port;
request.get(`http://localhost:${port}/curimit%40gmail.com%20(40%25)`, (err, res, body) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200);
t.equal(eol.lf(body), 'index!!!\n');
server.close(() => { t.end(); });
Expand Down
2 changes: 1 addition & 1 deletion test/illegal-access-date.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('if-modified-since illegal access date', (t) => {
headers: { 'if-modified-since': '275760-09-24' },
};
request.get(opts, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 200);
server.close(() => { t.end(); });
});
Expand Down
4 changes: 2 additions & 2 deletions test/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ test('http-server main', (t) => {
requestAsync("http://localhost:8080/").then(res => {
t.ok(res);
t.equal(res.statusCode, 200);
t.includes(res.body, './file');
t.includes(res.body, './canYouSeeMe');
t.match(res.body, './file');
t.match(res.body, './canYouSeeMe');

// Custom headers
t.equal(res.headers['access-control-allow-origin'], '*');
Expand Down
2 changes: 1 addition & 1 deletion test/malformed-dir.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('malformed showdir uri', (t) => {

server.listen(0, () => {
request.get(`http://localhost:${server.address().port}/?%`, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 400);
server.close(() => { t.end(); });
});
Expand Down
2 changes: 1 addition & 1 deletion test/malformed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('malformed uri', (t) => {

server.listen(0, () => {
request.get(`http://localhost:${server.address().port}/%`, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 400);
server.close(() => { t.end(); });
});
Expand Down
2 changes: 1 addition & 1 deletion test/process-env-port.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function startServer(url, port, t) {
});
} else {
ecstatic.on('exit', (evt) => {
t.notEqual(evt.code, 0, 'err:Running on invalid port not allowed');
t.not(evt.code, 0, 'err:Running on invalid port not allowed');
});
}
}
Expand Down
12 changes: 6 additions & 6 deletions test/range.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('range', (t) => {
headers: { range: '3-5' },
};
request.get(opts, (err, res, body) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 206, 'partial content status code');
t.equal(body, 'e!!');
t.equal(parseInt(res.headers['content-length'], 10), body.length);
Expand All @@ -38,7 +38,7 @@ test('range past the end', (t) => {
headers: { range: '3-500' },
};
request.get(opts, (err, res, body) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 206, 'partial content status code');
t.equal(eol.lf(body), 'e!!</b>\n');
t.equal(parseInt(res.headers['content-length'], 10), body.length);
Expand All @@ -58,7 +58,7 @@ test('NaN range', (t) => {
headers: { range: 'abc-def' },
};
request.get(opts, (err, res, body) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 416, 'range error status code');
t.equal(body, 'Requested range not satisfiable');
});
Expand All @@ -77,7 +77,7 @@ test('flipped range', (t) => {
headers: { range: '333-222' },
};
request.get(opts, (err, res, body) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 416, 'range error status code');
t.equal(body, 'Requested range not satisfiable');
});
Expand All @@ -97,7 +97,7 @@ test('partial range', (t) => {
headers: { range: '3-' },
};
request.get(opts, (err, res, body) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 206, 'partial content status code');
t.equal(eol.lf(body), 'e!!</b>\n');
t.equal(parseInt(res.headers['content-length'], 10), body.length);
Expand All @@ -122,7 +122,7 @@ test('include last-modified, etag and cache-control headers', (t) => {
headers: { range: '3-5' },
};
request.get(opts, (err, res) => {
t.ifError(err);
t.error(err);
t.ok(res.headers['cache-control']);
t.ok(res.headers['last-modified']);
t.ok(res.headers.etag);
Expand Down
2 changes: 1 addition & 1 deletion test/trailing-slash.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('should not add trailing slash when showDir and autoIndex are off', (t) =>
server.listen(0, () => {
const port = server.address().port;
request.get(`http://localhost:${port}/subdir`, (err, res) => {
t.ifError(err);
t.error(err);
t.equal(res.statusCode, 404);
t.equal(res.body, 'File not found. :(');
});
Expand Down
Loading