From 8181a4221d8421ff2a37c2b4cce30e8c9f9cc832 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 27 Feb 2017 10:18:45 +0000 Subject: [PATCH] Test custom 404 page --- tests/middleware/404.test.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/middleware/404.test.ts b/tests/middleware/404.test.ts index 83708d4..dcba6c1 100644 --- a/tests/middleware/404.test.ts +++ b/tests/middleware/404.test.ts @@ -1,6 +1,7 @@ import { expect } from 'chai'; import { runServer } from '../helpers'; - +import * as fs from 'fs'; +import * as path from 'path'; describe('404 Middleware', function () { it('Should respond with 404 on bad path', function (done) { @@ -17,4 +18,30 @@ describe('404 Middleware', function () { expect(response.text()).to.eventually.include('Cannot GET').notify(done); }); }); + + describe('Custom 404 Page', function () { + const CUSTOM_PAGE = path.join(__dirname, '..', '..', 'site', '.404.html') + beforeEach(function () { + fs.writeFileSync(CUSTOM_PAGE, 'Custom 404 Page'); + }); + + afterEach(function () { + fs.unlinkSync(CUSTOM_PAGE); + }); + + it('should have custom page', 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; + expect(response.status).to.equal(404); + expect(response.text()).to.eventually.include('Custom 404 Page').notify(done); + }); + }); + }); });