Add some actual tests
This commit is contained in:
parent
9968e1b9ac
commit
8fa136379f
3 changed files with 45 additions and 3 deletions
|
@ -5,7 +5,11 @@ import fetch from 'node-fetch';
|
||||||
|
|
||||||
|
|
||||||
export function runServer(opts: Object, url : string, callback: Function) {
|
export function runServer(opts: Object, url : string, callback: Function) {
|
||||||
return createServer(opts as Options).listen(1234, function () {
|
const app = createServer(opts as Options);
|
||||||
return fetch('http://0.0.0.0:1234' + url).then(callback);
|
const server = app.listen(1234, function () {
|
||||||
|
return fetch('http://0.0.0.0:1234' + url).then(function (response : any) {
|
||||||
|
server.close();
|
||||||
|
callback(response);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { runServer } from './helpers';
|
import { runServer } from './helpers';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
|
|
||||||
describe('Server', function () {
|
describe('Server', function () {
|
||||||
|
@ -21,4 +22,41 @@ describe('Server', function () {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should respond with 404 on bad path', function (done) {
|
||||||
|
runServer({
|
||||||
|
allowed_ips: [],
|
||||||
|
basicAuth: [],
|
||||||
|
dirList: false,
|
||||||
|
serveDir: 'site/',
|
||||||
|
opbeat: false,
|
||||||
|
open: false
|
||||||
|
}, '/foo/bar', function (response : any) {
|
||||||
|
expect(response.ok).to.be.false;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('index route', function () {
|
||||||
|
const body = fs.readFileSync(__dirname + '/../../site/index.html').toString();
|
||||||
|
|
||||||
|
['', '/', '/index.html'].forEach(function (path : string) {
|
||||||
|
it('should render ' + path, function (done) {
|
||||||
|
runServer({
|
||||||
|
allowed_ips: [],
|
||||||
|
basicAuth: [],
|
||||||
|
dirList: false,
|
||||||
|
serveDir: 'site/',
|
||||||
|
opbeat: false,
|
||||||
|
open: false
|
||||||
|
}, path, function (response : any) {
|
||||||
|
expect(response.status).to.equal(200);
|
||||||
|
response.text().then(function (text : any) {
|
||||||
|
expect(text).to.equal(body);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import * as express from 'express';
|
import * as express from 'express';
|
||||||
import * as serveIndex from 'serve-index';
|
import * as serveIndex from 'serve-index';
|
||||||
import path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
function isDirectory(url : string) : boolean {
|
function isDirectory(url : string) : boolean {
|
||||||
return /\/$/.test(url);
|
return /\/$/.test(url);
|
||||||
|
|
Reference in a new issue