mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 03:05:12 +00:00
51 lines
1.1 KiB
JavaScript
51 lines
1.1 KiB
JavaScript
const path = require('path');
|
|
const assert = require('assert');
|
|
|
|
const create_matchers = require('./create_matchers.js');
|
|
|
|
describe('create_matchers', () => {
|
|
it('sorts routes correctly', () => {
|
|
const matchers = create_matchers(['index.html', 'about.html', '[wildcard].html', 'post/[id].html']);
|
|
|
|
assert.deepEqual(
|
|
matchers.map(m => m.file),
|
|
[
|
|
'about.html',
|
|
'index.html',
|
|
'post/[id].html',
|
|
'[wildcard].html'
|
|
]
|
|
);
|
|
});
|
|
|
|
it('generates params', () => {
|
|
const matchers = create_matchers(['index.html', 'about.html', '[wildcard].html', 'post/[id].html']);
|
|
|
|
let file;
|
|
let params;
|
|
for (let i = 0; i < matchers.length; i += 1) {
|
|
const matcher = matchers[i];
|
|
if (params = matcher.exec('/post/123')) {
|
|
file = matcher.file;
|
|
break;
|
|
}
|
|
}
|
|
|
|
assert.equal(file, 'post/[id].html');
|
|
assert.deepEqual(params, {
|
|
id: '123'
|
|
});
|
|
});
|
|
|
|
it('ignores files and directories with leading underscores', () => {
|
|
const matches = create_matchers(['index.html', '_foo.html', 'a/_b/c/d.html', 'e/f/g/h.html', 'i/_j.html']);
|
|
|
|
assert.deepEqual(
|
|
matches.map(m => m.file),
|
|
[
|
|
'e/f/g/h.html',
|
|
'index.html'
|
|
]
|
|
);
|
|
});
|
|
}); |