From ac29b7f93223b2167a47928d62f7fa377842d6d2 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 28 Jan 2018 11:49:08 +0000 Subject: [PATCH] Test static file middleware --- tests/middleware/static-files.test.ts | 77 +++++++++++++++++++++++++++ tests/server.test.ts | 20 ------- 2 files changed, 77 insertions(+), 20 deletions(-) create mode 100644 tests/middleware/static-files.test.ts diff --git a/tests/middleware/static-files.test.ts b/tests/middleware/static-files.test.ts new file mode 100644 index 0000000..e204fd2 --- /dev/null +++ b/tests/middleware/static-files.test.ts @@ -0,0 +1,77 @@ +import { expect } from 'chai'; +import { runServer } from '../helpers'; +import * as fs from 'fs'; +import * as path from 'path'; +import { Options } from '../../src/types'; + + +describe('Static Files', function () { + const body = fs.readFileSync(path.join(__dirname, '../..', 'site', 'index.html')).toString(); + const cssBody = fs.readFileSync(path.join(__dirname, '../..', 'site', 'style.css')).toString(); + + describe('index route', function () { + + ['', '/', '/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); + expect(response.text()).to.eventually.equal(body).notify(done); + }); + }); + }); + }); + + it('Should return static files', function (done) { + runServer({ + allowed_ips: [], + basicAuth: [], + dirList: false, + serveDir: 'site/', + opbeat: false, + open: false + }, '/style.css', function (response : any) { + expect(response.status).to.equal(200); + expect(response.text()).to.eventually.equal(cssBody).notify(done); + }); + }); + + describe('Directory listing', function () { + const SERVER_CONFIG = { + allowed_ips: [], + basicAuth: [], + dirList: true, + serveDir: 'site/', + opbeat: false, + open: false + } as Options; + + it('Should allow directory listing', function (done) { + runServer(SERVER_CONFIG, '/', function (response : any) { + expect(response.status).to.equal(200); + expect(response.text()).to.eventually.not.equal(body).notify(done); + }); + }); + + it('Should show index file in directory listing', function (done) { + runServer(SERVER_CONFIG, '/', function (response : any) { + expect(response.status).to.equal(200); + expect(response.text()).to.eventually.contain('style.css').notify(done); + }); + }); + it('Should show css file in directory listing', function (done) { + runServer(SERVER_CONFIG, '/', function (response : any) { + expect(response.status).to.equal(200); + expect(response.text()).to.eventually.contain('index.html').notify(done); + }); + }); + + }); + +}); diff --git a/tests/server.test.ts b/tests/server.test.ts index 1f63cc6..f20c083 100644 --- a/tests/server.test.ts +++ b/tests/server.test.ts @@ -22,26 +22,6 @@ describe('Server', function () { }); }); - describe('index route', function () { - const body = fs.readFileSync(path.join(__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); - expect(response.text()).to.eventually.equal(body).notify(done); - }); - }); - }); - }); - describe('secure headers', function () { const SERVER_SETTINGS = { allowed_ips: [],