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
+34
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('/[email protected]/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('/[email protected]/not-here/')
.end((err, res) => {
expect(res.statusCode).toBe(404);
expect(res.headers['content-type']).toMatch(/\btext\/plain\b/);
done();
});
});
});
});
@@ -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('/[email protected]/devtools')
.end((err, res) => {
expect(res.statusCode).toBe(302);
expect(res.headers.location).toEqual('/[email protected]/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('/[email protected]/src/dom')
.end((err, res) => {
expect(res.statusCode).toBe(302);
expect(res.headers.location).toEqual(
'/[email protected]/src/dom/index.js'
);
done();
});
});
});
});
+20
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('/[email protected]/not-here.js')
.end((err, res) => {
expect(res.statusCode).toBe(404);
expect(res.headers['content-type']).toMatch(/\btext\/plain\b/);
done();
});
});
});