mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 12:57:46 +00:00
[remix] Add unit tests (#9469)
Moves parts of the `@vercel/remix` builder into util functions that have isolated unit tests. No functionality changes.
This commit is contained in:
124
packages/remix/test/unit.get-regexp-from-path.test.ts
vendored
Normal file
124
packages/remix/test/unit.get-regexp-from-path.test.ts
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
import { getRegExpFromPath } from '../src/utils';
|
||||
|
||||
describe('getRegExpFromPath()', () => {
|
||||
describe('paths without parameters', () => {
|
||||
it.each([{ path: 'index' }, { path: 'api/hello' }, { path: 'projects' }])(
|
||||
'should return `false` for "$path"',
|
||||
({ path }) => {
|
||||
expect(getRegExpFromPath(path)).toEqual(false);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe.each([
|
||||
{
|
||||
path: '*',
|
||||
urls: [
|
||||
{
|
||||
url: '/',
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
url: '/foo',
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
url: '/projects/foo',
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
url: '/projects/another',
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
url: '/to/infinity/and/beyond',
|
||||
expected: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: 'projects/*',
|
||||
urls: [
|
||||
{
|
||||
url: '/',
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
url: '/foo',
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
url: '/projects/foo',
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
url: '/projects/another',
|
||||
expected: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: ':foo',
|
||||
urls: [
|
||||
{
|
||||
url: '/',
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
url: '/foo',
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
url: '/projects/foo',
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
url: '/projects/another',
|
||||
expected: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: 'blog/:id/edit',
|
||||
urls: [
|
||||
{
|
||||
url: '/',
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
url: '/foo',
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
url: '/blog/123/edit',
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
url: '/blog/456/edit',
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
url: '/blog/123/456/edit',
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
url: '/blog/123/another',
|
||||
expected: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
])('with path "$path"', ({ path, urls }) => {
|
||||
const re = getRegExpFromPath(path) as RegExp;
|
||||
|
||||
it('should return RegExp', () => {
|
||||
expect(re).toBeInstanceOf(RegExp);
|
||||
});
|
||||
|
||||
it.each(urls)(
|
||||
'should match URL "$url" - $expected',
|
||||
({ url, expected }) => {
|
||||
expect(re.test(url)).toEqual(expected);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user