Skip to content

Commit dbde615

Browse files
committed
test: add basic unit tests for relativizeURL
1 parent 9267bc8 commit dbde615

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

edge-runtime/lib/util.test.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { assertEquals } from 'https://deno.land/std@0.175.0/testing/asserts.ts'
2-
import { rewriteDataPath } from './util.ts'
2+
import { relativizeURL, rewriteDataPath } from './util.ts'
33

44
Deno.test('rewriteDataPath', async (t) => {
55
await t.step('should rewrite a data url', async () => {
@@ -37,3 +37,26 @@ Deno.test('rewriteDataPath', async (t) => {
3737
assertEquals(result, '/_next/data/build-id/target.json')
3838
})
3939
})
40+
41+
Deno.test('relativizeURL', async (t) => {
42+
await t.step('should relativize a URL when origin matches', async () => {
43+
const url = 'https://example.com/pathname'
44+
const base = 'https://example.com/'
45+
const result = relativizeURL(url, base)
46+
assertEquals(result, '/pathname')
47+
})
48+
49+
await t.step('should NOT relativize a URL when origin does not match', async () => {
50+
const url = 'https://example.com/pathname'
51+
const base = 'https://not-example.com/'
52+
const result = relativizeURL(url, base)
53+
assertEquals(result, 'https://example.com/pathname')
54+
})
55+
56+
await t.step('accepts relative URL strings and produce relative URL as output', async () => {
57+
const url = '/pathname'
58+
const base = 'https://example.com/'
59+
const result = relativizeURL(url, base)
60+
assertEquals(result, '/pathname')
61+
})
62+
})

0 commit comments

Comments
 (0)