Cleanup tests

This commit is contained in:
Jake Howard 2017-02-19 21:53:06 +00:00
parent 8fa136379f
commit 53df4c6e3f
7 changed files with 15 additions and 10 deletions

View file

@ -11,7 +11,7 @@
"postinstall": "typings install", "postinstall": "typings install",
"build": "tsc", "build": "tsc",
"test": "npm run build && npm run mocha && nsp check", "test": "npm run build && npm run mocha && nsp check",
"mocha": "NODE_ENV=test mocha --compilers ts:ts-node/register --require scripts/test-helper.js src/__tests__/**.test.ts", "mocha": "mocha --compilers ts:ts-node/register --require scripts/test-helper.js src/__tests__/**.test.ts",
"lint": "tslint src/**/*.ts" "lint": "tslint src/**/*.ts"
}, },
"engines": { "engines": {
@ -43,6 +43,7 @@
}, },
"devDependencies": { "devDependencies": {
"chai": "=3.5.0", "chai": "=3.5.0",
"chai-as-promised": "=6.0.0",
"mocha": "=3.2.0", "mocha": "=3.2.0",
"node-fetch": "=1.6.3", "node-fetch": "=1.6.3",
"nsp": "=2.6.2", "nsp": "=2.6.2",

View file

@ -1,3 +1,7 @@
const chai = require('chai'); const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.expect(); chai.expect();
chai.use(chaiAsPromised);
process.env.NODE_ENV = 'test';

View file

@ -33,7 +33,8 @@ describe('Server', function () {
open: false open: false
}, '/foo/bar', function (response : any) { }, '/foo/bar', function (response : any) {
expect(response.ok).to.be.false; expect(response.ok).to.be.false;
done(); expect(response.status).to.equal(404);
expect(response.text()).to.eventually.include('Cannot GET').notify(done);
}); });
}); });
@ -51,10 +52,7 @@ describe('Server', function () {
open: false open: false
}, path, function (response : any) { }, path, function (response : any) {
expect(response.status).to.equal(200); expect(response.status).to.equal(200);
response.text().then(function (text : any) { expect(response.text()).to.eventually.equal(body).notify(done);
expect(text).to.equal(body);
done();
});
}); });
}); });
}); });

View file

@ -1,6 +1,6 @@
import { Request, Response } from 'express'; import { Request, Response } from 'express';
import staticFile from 'connect-static-file' import * as staticFile from 'connect-static-file'
import path from 'path'; import * as path from 'path';
export default function handle404(serveDir : string) { export default function handle404(serveDir : string) {
const handle404Middleware = staticFile(path.join(serveDir, '.404.html')); const handle404Middleware = staticFile(path.join(serveDir, '.404.html'));

View file

@ -39,7 +39,7 @@ export default function createServer(opts : Options) : express.Application {
} }
app.use(staticFileHandle(opts.serveDir)); app.use(staticFileHandle(opts.serveDir));
app.use(handle404); app.use(handle404(opts.serveDir));
app.use(compression({ level: 9 })); app.use(compression({ level: 9 }));
app.use(helmet()); app.use(helmet());

View file

@ -9,3 +9,4 @@ declare module 'opbeat';
declare module 'docopt'; declare module 'docopt';
declare module 'open'; declare module 'open';
declare module 'node-fetch'; declare module 'node-fetch';
declare module 'chai';

View file

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