archive
/
tstatic
Archived
1
Fork 0

Start adding tests

This commit is contained in:
Jake Howard 2017-02-19 18:19:45 +00:00
parent 829bcd6c3b
commit 511d60925a
8 changed files with 52 additions and 2 deletions

View File

@ -11,6 +11,7 @@
"postinstall": "typings install",
"build": "tsc",
"test": "npm run build && nsp check",
"mocha": "NODE_ENV=test mocha --compilers ts:ts-node/register --require scripts/test-helper.js src/__tests__/**.test.ts",
"lint": "tslint src/**/*.ts"
},
"engines": {
@ -41,9 +42,12 @@
"winston": "=2.3.1"
},
"devDependencies": {
"chai": "=3.5.0",
"mocha": "=3.2.0",
"node-fetch": "=1.6.3",
"nsp": "=2.6.2",
"supertest": "=3.0.0",
"ts-node": "=2.1.0",
"tslint": "=4.4.2",
"typescript": "=2.1.6",
"typings": "=2.1.0"

3
scripts/test-helper.js Normal file
View File

@ -0,0 +1,3 @@
const chai = require('chai');
chai.expect();

11
src/__tests__/helpers.ts Normal file
View File

@ -0,0 +1,11 @@
import createServer from '../server';
import { Options } from '../types';
import fetch from 'node-fetch';
export function runServer(opts: Object, url : string, callback: Function) {
return createServer(opts as Options).listen(1234, function () {
return fetch('http://0.0.0.0:1234' + url).then(callback);
});
}

View File

@ -0,0 +1,24 @@
import { expect } from 'chai';
import { runServer } from './helpers';
describe('Server', function () {
it('should test', function () {
expect(2 + 2).to.equal(4);
});
it('Should be usable', function (done) {
runServer({
allowed_ips: [],
basicAuth: [],
dirList: false,
serveDir: 'site/',
opbeat: false,
open: false
}, '/index.html', function (response : any) {
expect(response.status).to.equal(200);
expect(response.url).to.include('/index.html');
done();
});
});
});

View File

@ -15,7 +15,9 @@ import { Options } from './types';
export default function createServer(opts : Options) : express.Application {
const app = express();
app.use(logging);
if (process.env.NODE_ENV !== 'test') {
app.use(logging);
}
if (opts.allowed_ips.length) {
app.set('trust proxy', true);

View File

@ -8,3 +8,4 @@ declare module 'express-winston';
declare module 'opbeat';
declare module 'docopt';
declare module 'open';
declare module 'node-fetch';

View File

@ -16,7 +16,8 @@
],
"exclude": [
"dist",
"node_modules"
"node_modules",
"scripts/"
],
"typeRoots": [
"node_modules",

View File

@ -8,5 +8,9 @@
},
"globalDependencies": {
"node": "registry:dt/node#7.0.0+20170204020307"
},
"globalDevDependencies": {
"chai": "registry:dt/chai#3.4.0+20170217154556",
"mocha": "registry:dt/mocha#2.2.5+20170204022515"
}
}