Skip to content

Commit

Permalink
💫 added basic redirect and header tests #7 #1
Browse files Browse the repository at this point in the history
  • Loading branch information
8eecf0d2 committed Oct 16, 2018
1 parent 41b6fba commit d3ff9fb
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
27 changes: 27 additions & 0 deletions test/assets/netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
56 changes: 55 additions & 1 deletion test/ts/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
});
});
});

0 comments on commit d3ff9fb

Please sign in to comment.