From d3ff9fb6e1b3f8843c96598c1be985dd4dde6809 Mon Sep 17 00:00:00 2001 From: 8eecf0d2 <8eecf0d23d248b0e6223b8a10ddbf1@gmail.com> Date: Tue, 16 Oct 2018 20:55:46 +1100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=AB=20added=20basic=20redirect=20and?= =?UTF-8?q?=20header=20tests=20#7=20#1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/assets/netlify.toml | 27 +++++++++++++++++++ test/ts/server.ts | 56 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/test/assets/netlify.toml b/test/assets/netlify.toml index 76b30ae..9867212 100644 --- a/test/assets/netlify.toml +++ b/test/assets/netlify.toml @@ -9,3 +9,30 @@ publish = "default-publish" functions = "default-functions" command = "default-command" + +[[redirects]] + from = "/redirect-from-a" + to = "/redirect-to-a" + status = 200 + +[[redirects]] + from = "/redirect-from-b" + to = "/redirect-to-b" + status = 200 + +[[redirects]] + from = "/redirect-from-header" + to = "/redirect-to-header" + status = 200 + [redirects.headers] + Redirect-Header = "" + +[[headers]] + for = "/headers-for-a" + [headers.values] + Header-A = "" + +[[headers]] + for = "/headers-for-b" + [headers.values] + Header-B = "" diff --git a/test/ts/server.ts b/test/ts/server.ts index 20d6ac4..0ec9ec7 100644 --- a/test/ts/server.ts +++ b/test/ts/server.ts @@ -7,7 +7,7 @@ process.env.SILENT = "true"; mocha.describe('Server', () => { mocha.describe('lifecycle', () => { - mocha.it('should listen and close correctly', async () => { + mocha.it('should listen and close', async () => { const netlifyConfig = parseNetlifyConfig("test/assets/netlify.toml"); const server = new Server(netlifyConfig, 9000); @@ -21,5 +21,59 @@ mocha.describe('Server', () => { //@ts-ignore assert.equal(server.server.address(), null); }); + + mocha.it('should add redirect routes', async () => { + const netlifyConfig = parseNetlifyConfig("test/assets/netlify.toml"); + + const server = new Server(netlifyConfig, 9000); + await server.listen(); + + const [redirectRouteA, redirectRouteB] = [ + //@ts-ignore + server.express._router.stack.find(route => route.route && route.route.path === "/redirect-from-a"), + //@ts-ignore + server.express._router.stack.find(route => route.route && route.route.path === "/redirect-from-b") + ]; + + assert.notEqual(redirectRouteA, undefined); + + assert.notEqual(redirectRouteB, undefined); + + server.close(); + }); + + mocha.it('should add redirect header routes', async () => { + const netlifyConfig = parseNetlifyConfig("test/assets/netlify.toml"); + + const server = new Server(netlifyConfig, 9000); + await server.listen(); + + //@ts-ignore + const redirectRouteHeader = server.express._router.stack.find(route => route.route && route.route.path === "/redirect-from-header"); + + assert.notEqual(redirectRouteHeader, undefined); + + server.close(); + }); + + mocha.it('should add header routes', async () => { + const netlifyConfig = parseNetlifyConfig("test/assets/netlify.toml"); + + const server = new Server(netlifyConfig, 9000); + await server.listen(); + + const [headerRouteA, headerRouteB] = [ + //@ts-ignore + server.express._router.stack.find(route => route.route && route.route.path === "/headers-for-a"), + //@ts-ignore + server.express._router.stack.find(route => route.route && route.route.path === "/headers-for-b") + ]; + + assert.notEqual(headerRouteA, undefined); + + assert.notEqual(headerRouteB, undefined); + + server.close(); + }); }); });