add some tests - closes #10

This commit is contained in:
Rich Harris
2017-12-18 21:39:17 -05:00
committed by GitHub
parent cd8b9ddb14
commit c1b1b3ed63
44 changed files with 11008 additions and 16 deletions

View File

@@ -1,14 +1,14 @@
const path = require('path');
const assert = require('assert');
const create_matchers = require('../../lib/utils/create_routes.js');
const create_routes = require('../../lib/utils/create_routes.js');
describe('create_matchers', () => {
describe('create_routes', () => {
it('sorts routes correctly', () => {
const matchers = create_matchers(['index.html', 'about.html', '[wildcard].html', 'post/[id].html']);
const routes = create_routes(['index.html', 'about.html', '[wildcard].html', 'post/[id].html']);
assert.deepEqual(
matchers.map(m => m.file),
routes.map(r => r.file),
[
'about.html',
'index.html',
@@ -19,14 +19,14 @@ describe('create_matchers', () => {
});
it('generates params', () => {
const matchers = create_matchers(['index.html', 'about.html', '[wildcard].html', 'post/[id].html']);
const routes = create_routes(['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;
for (let i = 0; i < routes.length; i += 1) {
const route = routes[i];
if (params = route.exec('/post/123')) {
file = route.file;
break;
}
}
@@ -38,10 +38,10 @@ describe('create_matchers', () => {
});
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']);
const routes = create_routes(['index.html', '_foo.html', 'a/_b/c/d.html', 'e/f/g/h.html', 'i/_j.html']);
assert.deepEqual(
matches.map(m => m.file),
routes.map(r => r.file),
[
'e/f/g/h.html',
'index.html'