|
1 | 1 | 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' |
3 | 3 |
|
4 | 4 | Deno.test('rewriteDataPath', async (t) => {
|
5 | 5 | await t.step('should rewrite a data url', async () => {
|
@@ -37,3 +37,26 @@ Deno.test('rewriteDataPath', async (t) => {
|
37 | 37 | assertEquals(result, '/_next/data/build-id/target.json')
|
38 | 38 | })
|
39 | 39 | })
|
| 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