-
Notifications
You must be signed in to change notification settings - Fork 87
/
util.test.ts
39 lines (34 loc) · 1.59 KB
/
util.test.ts
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
import { assertEquals } from 'https://deno.land/[email protected]/testing/asserts.ts'
import { rewriteDataPath } from './util.ts'
Deno.test('rewriteDataPath', async (t) => {
await t.step('should rewrite a data url', async () => {
const dataUrl = '/_next/data/build-id/rewrite-me.json'
const newRoute = '/target'
const result = rewriteDataPath({ dataUrl, newRoute })
assertEquals(result, '/_next/data/build-id/target.json')
})
await t.step('should rewrite a data url with a base path', async () => {
const dataUrl = '/baseDir/_next/data/build-id/rewrite-me.json'
const newRoute = '/target'
const result = rewriteDataPath({ dataUrl, newRoute, basePath: '/baseDir' })
assertEquals(result, '/baseDir/_next/data/build-id/target.json')
})
await t.step('should rewrite from an index data url', async () => {
const dataUrl = '/_next/data/build-id/index.json'
const newRoute = '/target'
const result = rewriteDataPath({ dataUrl, newRoute })
assertEquals(result, '/_next/data/build-id/target.json')
})
await t.step('should rewrite to an index data url', async () => {
const dataUrl = '/_next/data/build-id/rewrite-me.json'
const newRoute = '/'
const result = rewriteDataPath({ dataUrl, newRoute })
assertEquals(result, '/_next/data/build-id/index.json')
})
await t.step('should rewrite to a route with a trailing slash', async () => {
const dataUrl = '/_next/data/build-id/rewrite-me.json'
const newRoute = '/target/'
const result = rewriteDataPath({ dataUrl, newRoute })
assertEquals(result, '/_next/data/build-id/target.json')
})
})