-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for routing to an index file inside of a named folder
- Loading branch information
1 parent
2b6be4b
commit f22ae79
Showing
7 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = () => 'conflict' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = () => 'conflict/index' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = () => 'index' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = () => 'test/:param' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = () => 'thing' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const test = require('tape') | ||
const router = require('..') | ||
|
||
let match = router(__dirname + '/fixtures/index') | ||
|
||
test('uses index.js when the root is requested', t => { | ||
t.plan(2) | ||
let req = { url: '/', method: 'GET' } | ||
t.equal(typeof match(req), 'function', 'finds a route') | ||
t.equal(match(req)(), 'index', 'finds the index route') | ||
}) | ||
|
||
test('uses index.js of a subfolder', t => { | ||
t.plan(2) | ||
let req = { url: '/thing', method: 'GET' } | ||
t.equal(typeof match(req), 'function', 'finds a route') | ||
t.equal(match(req)(), 'thing', 'finds the right route') | ||
}) | ||
|
||
test('uses index.js of a parameter', t => { | ||
t.plan(2) | ||
let req = { url: '/test/foo', method: 'GET' } | ||
t.equal(typeof match(req), 'function', 'finds a route') | ||
t.equal(match(req)(), 'test/:param', 'finds the right route') | ||
}) | ||
|
||
test('prefers a .js file to a nested index file when there is a conflict', t => { | ||
t.plan(2) | ||
let req = { url: '/conflict', method: 'GET' } | ||
t.equal(typeof match(req), 'function', 'finds a route') | ||
t.equal(match(req)(), 'conflict', 'finds the right route') | ||
}) |