|
1 |
| -import { getExtensionRegexString } from './is-metadata-route' |
| 1 | +import { |
| 2 | + getExtensionRegexString, |
| 3 | + isMetadataRouteFile, |
| 4 | + isMetadataRoute, |
| 5 | + isMetadataPage, |
| 6 | +} from './is-metadata-route' |
2 | 7 |
|
3 | 8 | describe('getExtensionRegexString', () => {
|
4 | 9 | function createExtensionMatchRegex(
|
@@ -54,3 +59,99 @@ describe('getExtensionRegexString', () => {
|
54 | 59 | })
|
55 | 60 | })
|
56 | 61 | })
|
| 62 | + |
| 63 | +describe('isMetadataRouteFile', () => { |
| 64 | + describe('match route - without extension', () => { |
| 65 | + it('should match metadata route page paths', () => { |
| 66 | + expect(isMetadataRouteFile('/icons/descriptor/page', [], false)).toBe( |
| 67 | + false |
| 68 | + ) |
| 69 | + expect(isMetadataRouteFile('/foo/icon', [], false)).toBe(true) |
| 70 | + expect(isMetadataRouteFile('/foo/opengraph-image', [], false)).toBe(true) |
| 71 | + expect(isMetadataRouteFile('/foo/sitemap.xml', [], false)).toBe(true) |
| 72 | + // group routes |
| 73 | + expect( |
| 74 | + isMetadataRouteFile('/foo/opengraph-image-abc123', [], false) |
| 75 | + ).toBe(true) |
| 76 | + // These pages are not normalized from actual entry files |
| 77 | + expect(isMetadataRouteFile('/foo/sitemap/0.xml', [], false)).toBe(false) |
| 78 | + expect( |
| 79 | + isMetadataRouteFile('/foo/opengraph-image-abc12313333', [], false) |
| 80 | + ).toBe(false) |
| 81 | + }) |
| 82 | + }) |
| 83 | + |
| 84 | + describe('match file - with extension', () => { |
| 85 | + it('should match static metadata route files', () => { |
| 86 | + expect(isMetadataRouteFile('/icons/descriptor/page', [], true)).toBe( |
| 87 | + false |
| 88 | + ) |
| 89 | + expect(isMetadataRouteFile('/foo/icon.png', [], true)).toBe(true) |
| 90 | + expect(isMetadataRouteFile('/bar/opengraph-image.jpg', [], true)).toBe( |
| 91 | + true |
| 92 | + ) |
| 93 | + expect(isMetadataRouteFile('/favicon.ico', [], true)).toBe(true) |
| 94 | + expect(isMetadataRouteFile('/robots.txt', [], true)).toBe(true) |
| 95 | + expect(isMetadataRouteFile('/manifest.json', [], true)).toBe(true) |
| 96 | + expect(isMetadataRouteFile('/sitemap.xml', [], true)).toBe(true) |
| 97 | + }) |
| 98 | + |
| 99 | + it('should match dynamic metadata routes', () => { |
| 100 | + // with dynamic extensions, passing the 2nd arg: such as ['tsx', 'ts'] |
| 101 | + expect(isMetadataRouteFile('/foo/icon.js', ['tsx', 'ts'], true)).toBe( |
| 102 | + false |
| 103 | + ) |
| 104 | + expect(isMetadataRouteFile('/foo/icon.ts', ['tsx', 'ts'], true)).toBe( |
| 105 | + true |
| 106 | + ) |
| 107 | + expect( |
| 108 | + isMetadataRouteFile('/foo/icon.tsx', ['js', 'jsx', 'tsx', 'ts'], true) |
| 109 | + ).toBe(true) |
| 110 | + }) |
| 111 | + }) |
| 112 | +}) |
| 113 | + |
| 114 | +describe('isMetadataRoute', () => { |
| 115 | + it('should require suffix for metadata routes', () => { |
| 116 | + expect(isMetadataRoute('/icon')).toBe(false) |
| 117 | + expect(isMetadataRoute('/icon/route')).toBe(true) |
| 118 | + expect(isMetadataRoute('/opengraph-image')).toBe(false) |
| 119 | + expect(isMetadataRoute('/opengraph-image/route')).toBe(true) |
| 120 | + }) |
| 121 | + |
| 122 | + it('should match metadata routes', () => { |
| 123 | + expect(isMetadataRoute('/app/robots/route')).toBe(true) |
| 124 | + expect(isMetadataRoute('/robots/route')).toBe(true) |
| 125 | + expect(isMetadataRoute('/sitemap/[__metadata_id__]/route')).toBe(true) |
| 126 | + expect(isMetadataRoute('/app/sitemap/page')).toBe(false) |
| 127 | + expect(isMetadataRoute('/icon-a102f4/route')).toBe(true) |
| 128 | + }) |
| 129 | + |
| 130 | + it('should match grouped metadata routes', () => { |
| 131 | + expect(isMetadataRoute('/opengraph-image-1ow20b/route')).toBe(true) |
| 132 | + expect(isMetadataRoute('/foo/icon2-1ow20b/route')).toBe(true) |
| 133 | + }) |
| 134 | + |
| 135 | + it('should support metadata variant numeric suffix', () => { |
| 136 | + expect(isMetadataRoute('/icon0/route')).toBe(true) |
| 137 | + expect(isMetadataRoute('/opengraph-image1/route')).toBe(true) |
| 138 | + expect(isMetadataRoute('/foo/icon0-a120ff/route')).toBe(true) |
| 139 | + expect(isMetadataRoute('/foo/icon0-a120ff3/route')).toBe(false) |
| 140 | + }) |
| 141 | +}) |
| 142 | + |
| 143 | +describe('isMetadataPage', () => { |
| 144 | + it('should match metadata page path', () => { |
| 145 | + expect(isMetadataPage('/sitemap.xml')).toBe(true) |
| 146 | + expect(isMetadataPage('/favicon.ico')).toBe(true) |
| 147 | + expect(isMetadataPage('/manifest.json')).toBe(true) |
| 148 | + expect(isMetadataPage('/robots.txt')).toBe(true) |
| 149 | + }) |
| 150 | + |
| 151 | + it('should not match app router page path or error boundary path', () => { |
| 152 | + expect(isMetadataPage('/icon/page')).toBe(false) |
| 153 | + expect(isMetadataPage('/icon/route')).toBe(false) |
| 154 | + expect(isMetadataPage('/icon/error')).toBe(false) |
| 155 | + expect(isMetadataPage('/icon/not-found')).toBe(false) |
| 156 | + }) |
| 157 | +}) |
0 commit comments