Add more tests

This commit is contained in:
Michael Jackson
2019-07-09 23:50:00 -07:00
parent d84a0296b2
commit 681fc99a68
9 changed files with 169 additions and 56 deletions

View File

@ -0,0 +1,34 @@
import request from 'supertest';
import createServer from '../createServer.js';
describe('A request that targets a directory with a trailing slash', () => {
let server;
beforeEach(() => {
server = createServer();
});
describe('when the directory exists', () => {
it('returns an HTML page', done => {
request(server)
.get('/react@16.8.0/umd/')
.end((err, res) => {
expect(res.statusCode).toBe(200);
expect(res.headers['content-type']).toMatch(/\btext\/html\b/);
done();
});
});
});
describe('when the directory does not exist', () => {
it('returns a 404 text error', done => {
request(server)
.get('/react@16.8.0/not-here/')
.end((err, res) => {
expect(res.statusCode).toBe(404);
expect(res.headers['content-type']).toMatch(/\btext\/plain\b/);
done();
});
});
});
});

View File

@ -0,0 +1,40 @@
import request from 'supertest';
import createServer from '../createServer.js';
describe('A request for a directory', () => {
let server;
beforeEach(() => {
server = createServer();
});
describe('when a .js file exists with the same name', () => {
it('is redirected to the .js file', done => {
request(server)
.get('/preact@8.4.2/devtools')
.end((err, res) => {
expect(res.statusCode).toBe(302);
expect(res.headers.location).toEqual('/preact@8.4.2/devtools.js');
done();
});
});
});
describe('when a .json file exists with the same name', () => {
it('is redirected to the .json file');
});
describe('when it contains an index.js file', () => {
it('is redirected to the index.js file', done => {
request(server)
.get('/preact@8.4.2/src/dom')
.end((err, res) => {
expect(res.statusCode).toBe(302);
expect(res.headers.location).toEqual(
'/preact@8.4.2/src/dom/index.js'
);
done();
});
});
});
});

View File

@ -0,0 +1,20 @@
import request from 'supertest';
import createServer from '../createServer.js';
describe('A request for a non-existent file', () => {
let server;
beforeEach(() => {
server = createServer();
});
it('returns a 404 text error', done => {
request(server)
.get('/preact@8.4.2/not-here.js')
.end((err, res) => {
expect(res.statusCode).toBe(404);
expect(res.headers['content-type']).toMatch(/\btext\/plain\b/);
done();
});
});
});