Skip to content

Commit

Permalink
add range header test to help investigate hexojs#186
Browse files Browse the repository at this point in the history
  • Loading branch information
kfatehi committed Dec 4, 2021
1 parent a253e04 commit 4ae0642
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,25 @@ describe('server', () => {
res.headers.should.not.have.property('Content-Encoding');
})));

it('static asset', () => {
describe('static asset', () => {
const path = join(hexo.public_dir, 'test.html');
const content = 'test html';

return fs.writeFile(path, content).then(() => Promise.using(prepareServer(), app => request(app).get('/test.html')
it("serves full", ()=>{
return fs.writeFile(path, content).then(() => Promise.using(prepareServer(), app => request(app).get('/test.html')
.expect('Content-Type', 'text/html; charset=UTF-8')
.expect(200, content))).finally(() => fs.unlink(path));
})

it('serves ranges', () => {
return fs.writeFile(path, content).then(() => Promise.using(prepareServer(), app => request(app).get('/test.html')
.set('Range', 'bytes=0-1')
.expect('Content-Length', '2')
.expect(206, "te"))).finally(() => fs.unlink(path));
});
});


it('invalid port', () => server({port: -100}).should.to.rejectedWith(RangeError, 'Port number -100 is invalid. Try a number between 1 and 65535.'));

it('invalid port > 65535', () => server({port: 65536}).should.to.rejectedWith(RangeError, 'Port number 65536 is invalid. Try a number between 1 and 65535.'));
Expand Down

0 comments on commit 4ae0642

Please sign in to comment.