diff --git a/packages/shared/tests/normalizeRoutePath.spec.ts b/packages/shared/tests/normalizeRoutePath.spec.ts index fc4301cc81..ecd3570bf0 100644 --- a/packages/shared/tests/normalizeRoutePath.spec.ts +++ b/packages/shared/tests/normalizeRoutePath.spec.ts @@ -3,190 +3,190 @@ import { normalizeRoutePath } from '../src/index.js' const testCases = [ // absolute index - ['/', '/'], - ['/README.md', '/'], - ['/readme.md', '/'], - ['/index.md', '/'], - ['/index.html', '/'], - ['/index', '/'], - ['/foo/', '/foo/'], - ['/foo/README.md', '/foo/'], - ['/foo/readme.md', '/foo/'], - ['/foo/index.md', '/foo/'], - ['/foo/index.html', '/foo/'], - ['/foo/index', '/foo/'], - ['README.md', 'index.html'], - ['readme.md', 'index.html'], - ['index.md', 'index.html'], - ['index.html', 'index.html'], - ['index', 'index.html'], + [['/'], '/'], + [['/README.md'], '/'], + [['/readme.md'], '/'], + [['/index.md'], '/'], + [['/index.html'], '/'], + [['/index'], '/'], + [['/foo/'], '/foo/'], + [['/foo/README.md'], '/foo/'], + [['/foo/readme.md'], '/foo/'], + [['/foo/index.md'], '/foo/'], + [['/foo/index.html'], '/foo/'], + [['/foo/index'], '/foo/'], + [['README.md'], 'index.html'], + [['readme.md'], 'index.html'], + [['index.md'], 'index.html'], + [['index.html'], 'index.html'], + [['index'], 'index.html'], // absolute non-index - ['/foo', '/foo.html'], - ['/foo.md', '/foo.html'], - ['/foo.html', '/foo.html'], - ['/foo/bar', '/foo/bar.html'], - ['/foo/bar.md', '/foo/bar.html'], - ['/foo/bar.html', '/foo/bar.html'], + [['/foo'], '/foo.html'], + [['/foo.md'], '/foo.html'], + [['/foo.html'], '/foo.html'], + [['/foo/bar'], '/foo/bar.html'], + [['/foo/bar.md'], '/foo/bar.html'], + [['/foo/bar.html'], '/foo/bar.html'], // relative index without current - ['foo/', 'foo/'], - ['foo/README.md', 'foo/'], - ['foo/readme.md', 'foo/'], - ['foo/index.md', 'foo/'], - ['foo/index.html', 'foo/'], - ['foo/index', 'foo/'], + [['foo/'], 'foo/'], + [['foo/README.md'], 'foo/'], + [['foo/readme.md'], 'foo/'], + [['foo/index.md'], 'foo/'], + [['foo/index.html'], 'foo/'], + [['foo/index'], 'foo/'], // relative non index without current - ['foo', 'foo.html'], - ['foo.md', 'foo.html'], - ['foo.html', 'foo.html'], - ['foo/bar', 'foo/bar.html'], - ['foo/bar.md', 'foo/bar.html'], - ['foo/bar.html', 'foo/bar.html'], + [['foo'], 'foo.html'], + [['foo.md'], 'foo.html'], + [['foo.html'], 'foo.html'], + [['foo/bar'], 'foo/bar.html'], + [['foo/bar.md'], 'foo/bar.html'], + [['foo/bar.html'], 'foo/bar.html'], // relative non index with current - ['foo', '/foo.html', '/'], - ['foo', '/foo.html', '/a.html'], - ['foo', '/foo.html', '/index.html'], - ['foo', '/a/foo.html', '/a/'], - ['foo', '/a/foo.html', '/a/index.html'], - ['foo', '/a/foo.html', '/a/b.html'], - ['foo.md', '/foo.html', '/'], - ['foo.md', '/foo.html', '/a.html'], - ['foo.md', '/foo.html', '/index.html'], - ['foo.md', '/a/foo.html', '/a/'], - ['foo.md', '/a/foo.html', '/a/index.html'], - ['foo.md', '/a/foo.html', '/a/b.html'], - ['foo.html', '/foo.html', '/'], - ['foo.html', '/foo.html', '/a.html'], - ['foo.html', '/foo.html', '/index.html'], - ['foo.html', '/a/foo.html', '/a/'], - ['foo.html', '/a/foo.html', '/a/index.html'], - ['foo.html', '/a/foo.html', '/a/b.html'], - ['foo/bar', '/foo/bar.html', '/'], - ['foo/bar', '/foo/bar.html', '/a.html'], - ['foo/bar', '/foo/bar.html', '/index.html'], - ['foo/bar', '/a/foo/bar.html', '/a/'], - ['foo/bar', '/a/foo/bar.html', '/a/index.html'], - ['foo/bar', '/a/foo/bar.html', '/a/b.html'], - ['foo/bar.md', '/foo/bar.html', '/'], - ['foo/bar.md', '/foo/bar.html', '/a.html'], - ['foo/bar.md', '/foo/bar.html', '/index.html'], - ['foo/bar.md', '/a/foo/bar.html', '/a/'], - ['foo/bar.md', '/a/foo/bar.html', '/a/index.html'], - ['foo/bar.md', '/a/foo/bar.html', '/a/b.html'], - ['foo/bar.html', '/foo/bar.html', '/'], - ['foo/bar.html', '/foo/bar.html', '/a.html'], - ['foo/bar.html', '/foo/bar.html', '/index.html'], - ['foo/bar.html', '/a/foo/bar.html', '/a/'], - ['foo/bar.html', '/a/foo/bar.html', '/a/index.html'], - ['foo/bar.html', '/a/foo/bar.html', '/a/b.html'], - ['./foo', '/foo.html', '/'], - ['./foo', '/foo.html', '/a.html'], - ['./foo', '/foo.html', '/index.html'], - ['./foo', '/a/foo.html', '/a/'], - ['./foo', '/a/foo.html', '/a/index.html'], - ['./foo', '/a/foo.html', '/a/b.html'], - ['./foo.md', '/foo.html', '/'], - ['./foo.md', '/foo.html', '/a.html'], - ['./foo.md', '/foo.html', '/index.html'], - ['./foo.md', '/a/foo.html', '/a/'], - ['./foo.md', '/a/foo.html', '/a/index.html'], - ['./foo.md', '/a/foo.html', '/a/b.html'], - ['./foo.html', '/foo.html', '/'], - ['./foo.html', '/foo.html', '/a.html'], - ['./foo.html', '/foo.html', '/index.html'], - ['./foo.html', '/a/foo.html', '/a/'], - ['./foo.html', '/a/foo.html', '/a/index.html'], - ['./foo.html', '/a/foo.html', '/a/b.html'], - ['./foo/bar', '/foo/bar.html', '/'], - ['./foo/bar', '/foo/bar.html', '/a.html'], - ['./foo/bar', '/foo/bar.html', '/index.html'], - ['./foo/bar', '/a/foo/bar.html', '/a/'], - ['./foo/bar', '/a/foo/bar.html', '/a/index.html'], - ['./foo/bar', '/a/foo/bar.html', '/a/b.html'], - ['./foo/bar.md', '/foo/bar.html', '/'], - ['./foo/bar.md', '/foo/bar.html', '/a.html'], - ['./foo/bar.md', '/foo/bar.html', '/index.html'], - ['./foo/bar.md', '/a/foo/bar.html', '/a/'], - ['./foo/bar.md', '/a/foo/bar.html', '/a/index.html'], - ['./foo/bar.md', '/a/foo/bar.html', '/a/b.html'], - ['./foo/bar.html', '/foo/bar.html', '/'], - ['./foo/bar.html', '/foo/bar.html', '/a.html'], - ['./foo/bar.html', '/foo/bar.html', '/index.html'], - ['./foo/bar.html', '/a/foo/bar.html', '/a/'], - ['./foo/bar.html', '/a/foo/bar.html', '/a/index.html'], - ['./foo/bar.html', '/a/foo/bar.html', '/a/b.html'], - ['../foo', '/foo.html', '/a/'], - ['../foo', '/foo.html', '/a/index.html'], - ['../foo', '/foo.html', '/a/b.html'], - ['../foo.md', '/foo.html', '/a/'], - ['../foo.md', '/foo.html', '/a/index.html'], - ['../foo.md', '/foo.html', '/a/b.html'], - ['../foo.html', '/foo.html', '/a/'], - ['../foo.html', '/foo.html', '/a/index.html'], - ['../foo.html', '/foo.html', '/a/b.html'], - ['../foo/bar', '/foo/bar.html', '/a/'], - ['../foo/bar', '/foo/bar.html', '/a/index.html'], - ['../foo/bar', '/foo/bar.html', '/a/b.html'], - ['../foo/bar.md', '/foo/bar.html', '/a/'], - ['../foo/bar.md', '/foo/bar.html', '/a/index.html'], - ['../foo/bar.md', '/foo/bar.html', '/a/b.html'], - ['../foo/bar.html', '/foo/bar.html', '/a/'], - ['../foo/bar.html', '/foo/bar.html', '/a/index.html'], - ['../foo/bar.html', '/foo/bar.html', '/a/b.html'], + [['foo', '/'], '/foo.html'], + [['foo', '/a.html'], '/foo.html'], + [['foo', '/index.html'], '/foo.html'], + [['foo', '/a/'], '/a/foo.html'], + [['foo', '/a/index.html'], '/a/foo.html'], + [['foo', '/a/b.html'], '/a/foo.html'], + [['foo.md', '/'], '/foo.html'], + [['foo.md', '/a.html'], '/foo.html'], + [['foo.md', '/index.html'], '/foo.html'], + [['foo.md', '/a/'], '/a/foo.html'], + [['foo.md', '/a/index.html'], '/a/foo.html'], + [['foo.md', '/a/b.html'], '/a/foo.html'], + [['foo.html', '/'], '/foo.html'], + [['foo.html', '/a.html'], '/foo.html'], + [['foo.html', '/index.html'], '/foo.html'], + [['foo.html', '/a/'], '/a/foo.html'], + [['foo.html', '/a/index.html'], '/a/foo.html'], + [['foo.html', '/a/b.html'], '/a/foo.html'], + [['foo/bar', '/'], '/foo/bar.html'], + [['foo/bar', '/a.html'], '/foo/bar.html'], + [['foo/bar', '/index.html'], '/foo/bar.html'], + [['foo/bar', '/a/'], '/a/foo/bar.html'], + [['foo/bar', '/a/index.html'], '/a/foo/bar.html'], + [['foo/bar', '/a/b.html'], '/a/foo/bar.html'], + [['foo/bar.md', '/'], '/foo/bar.html'], + [['foo/bar.md', '/a.html'], '/foo/bar.html'], + [['foo/bar.md', '/index.html'], '/foo/bar.html'], + [['foo/bar.md', '/a/'], '/a/foo/bar.html'], + [['foo/bar.md', '/a/index.html'], '/a/foo/bar.html'], + [['foo/bar.md', '/a/b.html'], '/a/foo/bar.html'], + [['foo/bar.html', '/'], '/foo/bar.html'], + [['foo/bar.html', '/a.html'], '/foo/bar.html'], + [['foo/bar.html', '/index.html'], '/foo/bar.html'], + [['foo/bar.html', '/a/'], '/a/foo/bar.html'], + [['foo/bar.html', '/a/index.html'], '/a/foo/bar.html'], + [['foo/bar.html', '/a/b.html'], '/a/foo/bar.html'], + [['./foo', '/'], '/foo.html'], + [['./foo', '/a.html'], '/foo.html'], + [['./foo', '/index.html'], '/foo.html'], + [['./foo', '/a/'], '/a/foo.html'], + [['./foo', '/a/index.html'], '/a/foo.html'], + [['./foo', '/a/b.html'], '/a/foo.html'], + [['./foo.md', '/'], '/foo.html'], + [['./foo.md', '/a.html'], '/foo.html'], + [['./foo.md', '/index.html'], '/foo.html'], + [['./foo.md', '/a/'], '/a/foo.html'], + [['./foo.md', '/a/index.html'], '/a/foo.html'], + [['./foo.md', '/a/b.html'], '/a/foo.html'], + [['./foo.html', '/'], '/foo.html'], + [['./foo.html', '/a.html'], '/foo.html'], + [['./foo.html', '/index.html'], '/foo.html'], + [['./foo.html', '/a/'], '/a/foo.html'], + [['./foo.html', '/a/index.html'], '/a/foo.html'], + [['./foo.html', '/a/b.html'], '/a/foo.html'], + [['./foo/bar', '/'], '/foo/bar.html'], + [['./foo/bar', '/a.html'], '/foo/bar.html'], + [['./foo/bar', '/index.html'], '/foo/bar.html'], + [['./foo/bar', '/a/'], '/a/foo/bar.html'], + [['./foo/bar', '/a/index.html'], '/a/foo/bar.html'], + [['./foo/bar', '/a/b.html'], '/a/foo/bar.html'], + [['./foo/bar.md', '/'], '/foo/bar.html'], + [['./foo/bar.md', '/a.html'], '/foo/bar.html'], + [['./foo/bar.md', '/index.html'], '/foo/bar.html'], + [['./foo/bar.md', '/a/'], '/a/foo/bar.html'], + [['./foo/bar.md', '/a/index.html'], '/a/foo/bar.html'], + [['./foo/bar.md', '/a/b.html'], '/a/foo/bar.html'], + [['./foo/bar.html', '/'], '/foo/bar.html'], + [['./foo/bar.html', '/a.html'], '/foo/bar.html'], + [['./foo/bar.html', '/index.html'], '/foo/bar.html'], + [['./foo/bar.html', '/a/'], '/a/foo/bar.html'], + [['./foo/bar.html', '/a/index.html'], '/a/foo/bar.html'], + [['./foo/bar.html', '/a/b.html'], '/a/foo/bar.html'], + [['../foo', '/a/'], '/foo.html'], + [['../foo', '/a/index.html'], '/foo.html'], + [['../foo', '/a/b.html'], '/foo.html'], + [['../foo.md', '/a/'], '/foo.html'], + [['../foo.md', '/a/index.html'], '/foo.html'], + [['../foo.md', '/a/b.html'], '/foo.html'], + [['../foo.html', '/a/'], '/foo.html'], + [['../foo.html', '/a/index.html'], '/foo.html'], + [['../foo.html', '/a/b.html'], '/foo.html'], + [['../foo/bar', '/a/'], '/foo/bar.html'], + [['../foo/bar', '/a/index.html'], '/foo/bar.html'], + [['../foo/bar', '/a/b.html'], '/foo/bar.html'], + [['../foo/bar.md', '/a/'], '/foo/bar.html'], + [['../foo/bar.md', '/a/index.html'], '/foo/bar.html'], + [['../foo/bar.md', '/a/b.html'], '/foo/bar.html'], + [['../foo/bar.html', '/a/'], '/foo/bar.html'], + [['../foo/bar.html', '/a/index.html'], '/foo/bar.html'], + [['../foo/bar.html', '/a/b.html'], '/foo/bar.html'], // absolute non index with current - ['/foo', '/foo.html', '/'], - ['/foo', '/foo.html', '/a.html'], - ['/foo', '/foo.html', '/index.html'], - ['/foo', '/foo.html', '/a/'], - ['/foo', '/foo.html', '/a/index.html'], - ['/foo', '/foo.html', '/a/b.html'], - ['/foo.md', '/foo.html', '/'], - ['/foo.md', '/foo.html', '/a.html'], - ['/foo.md', '/foo.html', '/index.html'], - ['/foo.md', '/foo.html', '/a/'], - ['/foo.md', '/foo.html', '/a/index.html'], - ['/foo.md', '/foo.html', '/a/b.html'], - ['/foo.html', '/foo.html', '/'], - ['/foo.html', '/foo.html', '/a.html'], - ['/foo.html', '/foo.html', '/index.html'], - ['/foo.html', '/foo.html', '/a/'], - ['/foo.html', '/foo.html', '/a/index.html'], - ['/foo.html', '/foo.html', '/a/b.html'], - ['/foo/bar', '/foo/bar.html', '/'], - ['/foo/bar', '/foo/bar.html', '/a.html'], - ['/foo/bar', '/foo/bar.html', '/index.html'], - ['/foo/bar', '/foo/bar.html', '/a/'], - ['/foo/bar', '/foo/bar.html', '/a/index.html'], - ['/foo/bar', '/foo/bar.html', '/a/b.html'], - ['/foo/bar.md', '/foo/bar.html', '/'], - ['/foo/bar.md', '/foo/bar.html', '/a.html'], - ['/foo/bar.md', '/foo/bar.html', '/index.html'], - ['/foo/bar.md', '/foo/bar.html', '/a/'], - ['/foo/bar.md', '/foo/bar.html', '/a/index.html'], - ['/foo/bar.md', '/foo/bar.html', '/a/b.html'], - ['/foo/bar.html', '/foo/bar.html', '/'], - ['/foo/bar.html', '/foo/bar.html', '/a.html'], - ['/foo/bar.html', '/foo/bar.html', '/index.html'], - ['/foo/bar.html', '/foo/bar.html', '/a/'], - ['/foo/bar.html', '/foo/bar.html', '/a/index.html'], - ['/foo/bar.html', '/foo/bar.html', '/a/b.html'], + [['/foo', '/'], '/foo.html'], + [['/foo', '/a.html'], '/foo.html'], + [['/foo', '/index.html'], '/foo.html'], + [['/foo', '/a/'], '/foo.html'], + [['/foo', '/a/index.html'], '/foo.html'], + [['/foo', '/a/b.html'], '/foo.html'], + [['/foo.md', '/'], '/foo.html'], + [['/foo.md', '/a.html'], '/foo.html'], + [['/foo.md', '/index.html'], '/foo.html'], + [['/foo.md', '/a/'], '/foo.html'], + [['/foo.md', '/a/index.html'], '/foo.html'], + [['/foo.md', '/a/b.html'], '/foo.html'], + [['/foo.html', '/'], '/foo.html'], + [['/foo.html', '/a.html'], '/foo.html'], + [['/foo.html', '/index.html'], '/foo.html'], + [['/foo.html', '/a/'], '/foo.html'], + [['/foo.html', '/a/index.html'], '/foo.html'], + [['/foo.html', '/a/b.html'], '/foo.html'], + [['/foo/bar', '/'], '/foo/bar.html'], + [['/foo/bar', '/a.html'], '/foo/bar.html'], + [['/foo/bar', '/index.html'], '/foo/bar.html'], + [['/foo/bar', '/a/'], '/foo/bar.html'], + [['/foo/bar', '/a/index.html'], '/foo/bar.html'], + [['/foo/bar', '/a/b.html'], '/foo/bar.html'], + [['/foo/bar.md', '/'], '/foo/bar.html'], + [['/foo/bar.md', '/a.html'], '/foo/bar.html'], + [['/foo/bar.md', '/index.html'], '/foo/bar.html'], + [['/foo/bar.md', '/a/'], '/foo/bar.html'], + [['/foo/bar.md', '/a/index.html'], '/foo/bar.html'], + [['/foo/bar.md', '/a/b.html'], '/foo/bar.html'], + [['/foo/bar.html', '/'], '/foo/bar.html'], + [['/foo/bar.html', '/a.html'], '/foo/bar.html'], + [['/foo/bar.html', '/index.html'], '/foo/bar.html'], + [['/foo/bar.html', '/a/'], '/foo/bar.html'], + [['/foo/bar.html', '/a/index.html'], '/foo/bar.html'], + [['/foo/bar.html', '/a/b.html'], '/foo/bar.html'], // only hash and query - ['', ''], + [[''], ''], // unexpected corner cases - ['.md', '.html'], - ['foo/.md', 'foo/.html'], - ['/.md', '/.html'], - ['/foo/.md', '/foo/.html'], + [['.md'], '.html'], + [['foo/.md'], 'foo/.html'], + [['/.md'], '/.html'], + [['/foo/.md'], '/foo/.html'], ] describe('should normalize clean paths correctly', () => { - testCases.forEach(([path, expected, current]) => + testCases.forEach(([[path, current], expected]) => it(`${current ? `"${current}"-` : ''}"${path}" -> "${expected}"`, () => { expect(normalizeRoutePath(path, current)).toBe(expected) }), @@ -195,12 +195,11 @@ describe('should normalize clean paths correctly', () => { describe('should normalize paths with query correctly', () => { testCases - .map(([path, expected, current]) => [ - `${path}?foo=bar`, + .map(([[path, current], expected]) => [ + [`${path}?foo=bar`, current], `${expected}?foo=bar`, - current, ]) - .forEach(([path, expected, current]) => + .forEach(([[path, current], expected]) => it(`${current ? `"${current}"-` : ''}"${path}" -> "${expected}"`, () => { expect(normalizeRoutePath(path, current)).toBe(expected) }), @@ -209,12 +208,11 @@ describe('should normalize paths with query correctly', () => { describe('should normalize paths with hash correctly', () => { testCases - .map(([path, expected, current]) => [ - `${path}#foobar`, + .map(([[path, current], expected]) => [ + [`${path}#foobar`, current], `${expected}#foobar`, - current, ]) - .forEach(([path, expected, current]) => + .map(([[path, current], expected]) => it(`${current ? `"${current}"-` : ''}"${path}" -> "${expected}"`, () => { expect(normalizeRoutePath(path, current)).toBe(expected) }), @@ -223,12 +221,11 @@ describe('should normalize paths with hash correctly', () => { describe('should normalize paths with query and hash correctly', () => { testCases - .map(([path, expected, current]) => [ - `${path}?foo=1&bar=2#foobar`, + .map(([[path, current], expected]) => [ + [`${path}?foo=1&bar=2#foobar`, current], `${expected}?foo=1&bar=2#foobar`, - current, ]) - .forEach(([path, expected, current]) => + .map(([[path, current], expected]) => it(`${current ? `"${current}"-` : ''}"${path}" -> "${expected}"`, () => { expect(normalizeRoutePath(path, current)).toBe(expected) }),