mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-11 19:04:30 +00:00
error if routes clash - fixes #33
This commit is contained in:
@@ -5,15 +5,17 @@ const create_routes = require('../../lib/utils/create_routes.js');
|
||||
|
||||
describe('create_routes', () => {
|
||||
it('sorts routes correctly', () => {
|
||||
const routes = create_routes(['index.html', 'about.html', '[wildcard].html', 'post/[id].html']);
|
||||
const routes = create_routes(['index.html', 'about.html', '[wildcard].html', 'post/foo.html', 'post/[id].html', 'post/bar.html']);
|
||||
|
||||
assert.deepEqual(
|
||||
routes.map(r => r.file),
|
||||
[
|
||||
'about.html',
|
||||
'index.html',
|
||||
'post/foo.html',
|
||||
'post/bar.html',
|
||||
'post/[id].html',
|
||||
'[wildcard].html'
|
||||
'about.html',
|
||||
'[wildcard].html',
|
||||
'index.html'
|
||||
]
|
||||
);
|
||||
});
|
||||
@@ -48,4 +50,25 @@ describe('create_routes', () => {
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it('matches /foo/:bar before /:baz/qux', () => {
|
||||
const a = create_routes(['foo/[bar].html', '[baz]/qux.html']);
|
||||
const b = create_routes(['[baz]/qux.html', 'foo/[bar].html']);
|
||||
|
||||
assert.deepEqual(
|
||||
a.map(r => r.file),
|
||||
['foo/[bar].html', '[baz]/qux.html']
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
b.map(r => r.file),
|
||||
['foo/[bar].html', '[baz]/qux.html']
|
||||
);
|
||||
});
|
||||
|
||||
it('fails if routes are indistinguishable', () => {
|
||||
assert.throws(() => {
|
||||
create_routes(['[foo].html', '[bar]/index.html']);
|
||||
}, /The \[foo\].html and \[bar\]\/index.html routes clash/);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user