File size: 1,565 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import { getMiddlewareMatchers } from './get-page-static-info'
describe('get-page-static-infos', () => {
describe('getMiddlewareMatchers', () => {
it('sets originalSource with one matcher', () => {
const matchers = '/middleware/path'
const expected = [
{
originalSource: '/middleware/path',
regexp:
'^(?:\\/(_next\\/data\\/[^/]{1,}))?\\/middleware\\/path(\\.json)?[\\/#\\?]?$',
},
]
const result = getMiddlewareMatchers(matchers, { i18n: undefined })
expect(result).toStrictEqual(expected)
})
it('sets originalSource with multiple matchers', () => {
const matchers = ['/middleware/path', '/middleware/another-path']
const expected = [
{
originalSource: '/middleware/path',
regexp:
'^(?:\\/(_next\\/data\\/[^/]{1,}))?\\/middleware\\/path(\\.json)?[\\/#\\?]?$',
},
{
originalSource: '/middleware/another-path',
regexp:
'^(?:\\/(_next\\/data\\/[^/]{1,}))?\\/middleware\\/another-path(\\.json)?[\\/#\\?]?$',
},
]
const result = getMiddlewareMatchers(matchers, { i18n: undefined })
expect(result).toStrictEqual(expected)
})
it('matches /:id and /:id.json', () => {
const matchers = ['/:id']
const result = getMiddlewareMatchers(matchers, { i18n: undefined })[0]
.regexp
const regex = new RegExp(result)
expect(regex.test('/apple')).toBe(true)
expect(regex.test('/apple.json')).toBe(true)
})
})
})
|