|
| 1 | +import { writeFile } from 'fs/promises' |
| 2 | +import { tmpdir } from 'os' |
1 | 3 | import { UnsupportedPathError } from '../../router' |
2 | 4 | import { PreparedRegExpRouter, buildInitParams, serializeInitParams } from './prepared-router' |
3 | 5 | import { RegExpRouter } from './router' |
@@ -658,26 +660,29 @@ describe('Capture Group', () => { |
658 | 660 | }) |
659 | 661 | }) |
660 | 662 |
|
661 | | -describe('PreparedRegExpRouter', () => { |
662 | | - const serialized = serializeInitParams(buildInitParams({ |
663 | | - routes: [ |
664 | | - {method: 'ALL', path: '*'}, |
665 | | - {method: 'ALL', path: '/posts/:id/*'}, |
666 | | - {method: 'GET', path: '*'}, |
667 | | - {method: 'GET', path: '/'}, |
668 | | - {method: 'GET', path: '/static'}, |
669 | | - {method: 'GET', path: '/posts/:id/*'}, |
670 | | - {method: 'GET', path: '/posts/:id'}, |
671 | | - {method: 'GET', path: '/posts/:id/comments'}, |
672 | | - {method: 'POST', path: '/posts'}, |
673 | | - {method: 'PUT', path: '/posts/:id'}, |
674 | | - ], |
675 | | - })) |
676 | | - |
677 | | - let params: ConstructorParameters<typeof PreparedRegExpRouter<string>> |
678 | | - // eslint-disable-next-line prefer-const |
679 | | - params = [{}, {}] |
680 | | - eval(`params = ${serialized}`) |
| 663 | +describe('PreparedRegExpRouter', async () => { |
| 664 | + const serialized = serializeInitParams( |
| 665 | + buildInitParams({ |
| 666 | + routes: [ |
| 667 | + { method: 'ALL', path: '*' }, |
| 668 | + { method: 'ALL', path: '/posts/:id/*' }, |
| 669 | + { method: 'GET', path: '*' }, |
| 670 | + { method: 'GET', path: '/' }, |
| 671 | + { method: 'GET', path: '/static' }, |
| 672 | + { method: 'GET', path: '/posts/:id/*' }, |
| 673 | + { method: 'GET', path: '/posts/:id' }, |
| 674 | + { method: 'GET', path: '/posts/:id/comments' }, |
| 675 | + { method: 'POST', path: '/posts' }, |
| 676 | + { method: 'PUT', path: '/posts/:id' }, |
| 677 | + ], |
| 678 | + }) |
| 679 | + ) |
| 680 | + |
| 681 | + const path = `${tmpdir()}/params.ts` |
| 682 | + await writeFile(path, `const params = ${serialized}; export default params`) |
| 683 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 684 | + // @ts-ignore |
| 685 | + const params: ConstructorParameters<typeof PreparedRegExpRouter<string>> = (await import(path)).default |
681 | 686 | const router = new PreparedRegExpRouter<string>(...params) |
682 | 687 |
|
683 | 688 | router.add('ALL', '*', 'wildcard') |
|
0 commit comments