Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Commit

Permalink
support nested directory routes
Browse files Browse the repository at this point in the history
  • Loading branch information
nahtnam committed Nov 19, 2019
1 parent 943186d commit 59549ad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils/add-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default (router: any, route: Route, opts?: any): void => {
}

endpoint.path = endpoint.path.map((p: string): string => {
const { name } = parse(p);
return join('/', name);
const { name, dir } = parse(p);
return join('/', dir, name);
});

// if the path is /index, map it to the root route as well
Expand Down
19 changes: 19 additions & 0 deletions tests/utils/add-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,24 @@ describe('utils', () => {
expect(router.on).toHaveBeenCalledWith(['GET'], '/', expect.any(Function));
});
});

describe('with nested route', () => {
const router = {
on: jest.fn(),
};

const route = {
path: '/multi/level',
method: 'GET',
handler: jest.fn(),
};

it('adds the nested route', async () => {
expect.assertions(2);
addRoute(router, route);
expect(router.on.mock.calls.length).toBe(1);
expect(router.on).toHaveBeenCalledWith(['GET'], '/multi/level', expect.any(Function));
});
});
});
});

0 comments on commit 59549ad

Please sign in to comment.