@buzola/router 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation-adapter.d.ts","sourceRoot":"","sources":["../../src/engine/navigation-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwC,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAIzF;;GAEG;AACH,wBAAgB,8BAA8B,IAAI,iBAAiB,
|
|
1
|
+
{"version":3,"file":"navigation-adapter.d.ts","sourceRoot":"","sources":["../../src/engine/navigation-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwC,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAIzF;;GAEG;AACH,wBAAgB,8BAA8B,IAAI,iBAAiB,CA8ElE;AAID,MAAM,WAAW,8BAA8B;IAC9C,UAAU,CAAC,EAAE,MAAM,CAAA;CACnB;AAOD;;GAEG;AACH,wBAAgB,6BAA6B,CAC5C,OAAO,GAAE,8BAAmC,GAC1C,iBAAiB,CA6FnB"}
|
|
@@ -32,7 +32,12 @@ export function createBrowserNavigationAdapter() {
|
|
|
32
32
|
};
|
|
33
33
|
return {
|
|
34
34
|
getCurrentURL() {
|
|
35
|
-
|
|
35
|
+
// `currentEntry` is null on a document that is not fully active or still on
|
|
36
|
+
// the initial about:blank; Safari reports an empty `url` in that situation
|
|
37
|
+
// instead. `||` catches both, and `location.href` is the URL the entry would
|
|
38
|
+
// have reported. This runs in the Router constructor, so a throw is a blank
|
|
39
|
+
// page rather than a degraded route.
|
|
40
|
+
return new URL(nav.currentEntry?.url || window.location.href);
|
|
36
41
|
},
|
|
37
42
|
navigate(url, options) {
|
|
38
43
|
if (options?.viewTransition) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation-adapter.js","sourceRoot":"","sources":["../../src/engine/navigation-adapter.ts"],"names":[],"mappings":"AAEA,+EAA+E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;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import './setup-dom.js'
|
|
2
|
+
|
|
3
|
+
import { afterEach, describe, expect, it } from 'bun:test'
|
|
4
|
+
import { createBrowserNavigationAdapter } from '../engine/navigation-adapter.js'
|
|
5
|
+
|
|
6
|
+
/* The Navigation API is not implemented by happy-dom, and the parts of it this
|
|
7
|
+
adapter touches are small enough to stand in for directly. What matters here
|
|
8
|
+
is the shape of `currentEntry`, which is the whole subject of these tests. */
|
|
9
|
+
type EntryStub = { url: string | null } | null
|
|
10
|
+
|
|
11
|
+
function withNavigation(currentEntry: EntryStub) {
|
|
12
|
+
Object.defineProperty(window, 'navigation', {
|
|
13
|
+
value: {
|
|
14
|
+
currentEntry,
|
|
15
|
+
addEventListener() {},
|
|
16
|
+
removeEventListener() {},
|
|
17
|
+
navigate() {},
|
|
18
|
+
back() {},
|
|
19
|
+
forward() {},
|
|
20
|
+
},
|
|
21
|
+
writable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
return createBrowserNavigationAdapter()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
Reflect.deleteProperty(window, 'navigation')
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
describe('createBrowserNavigationAdapter', () => {
|
|
33
|
+
it('reports the current entry URL', () => {
|
|
34
|
+
const adapter = withNavigation({ url: 'https://example.test/projects/7?tab=logs' })
|
|
35
|
+
|
|
36
|
+
expect(adapter.getCurrentURL().href).toBe('https://example.test/projects/7?tab=logs')
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
/* The case actually seen in the wild: the getter returns the empty string on a
|
|
40
|
+
document that is not fully active, which is what Safari handed us. `new
|
|
41
|
+
URL('')` throws just as `new URL(null)` does, and it throws out of the
|
|
42
|
+
`Router` constructor during render — a blank page, not a degraded route. An
|
|
43
|
+
empty string is falsy but not nullish, so this is the case `??` would miss. */
|
|
44
|
+
it('falls back to the document URL when the entry reports an empty URL', () => {
|
|
45
|
+
const adapter = withNavigation({ url: '' })
|
|
46
|
+
|
|
47
|
+
expect(adapter.getCurrentURL().href).toBe(window.location.href)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
/* `url` is also typed nullable: the getter returns null for entries whose
|
|
51
|
+
document is not the current one and was fetched under a `no-referrer` or
|
|
52
|
+
`origin` referrer policy. That branch needs `sameDocument` to be false, which
|
|
53
|
+
`currentEntry` never is, so it should not be reachable through this call —
|
|
54
|
+
but the type permits it and the fallback costs nothing. */
|
|
55
|
+
it('falls back to the document URL when the entry reports no URL', () => {
|
|
56
|
+
const adapter = withNavigation({ url: null })
|
|
57
|
+
|
|
58
|
+
expect(adapter.getCurrentURL().href).toBe(window.location.href)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
/* `currentEntry` itself is null while the document is not fully active or is
|
|
62
|
+
still on the initial about:blank, which is what an iframe reports before its
|
|
63
|
+
first real navigation. */
|
|
64
|
+
it('falls back to the document URL when there is no current entry', () => {
|
|
65
|
+
const adapter = withNavigation(null)
|
|
66
|
+
|
|
67
|
+
expect(adapter.getCurrentURL().href).toBe(window.location.href)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
@@ -42,7 +42,12 @@ export function createBrowserNavigationAdapter(): NavigationAdapter {
|
|
|
42
42
|
|
|
43
43
|
return {
|
|
44
44
|
getCurrentURL() {
|
|
45
|
-
|
|
45
|
+
// `currentEntry` is null on a document that is not fully active or still on
|
|
46
|
+
// the initial about:blank; Safari reports an empty `url` in that situation
|
|
47
|
+
// instead. `||` catches both, and `location.href` is the URL the entry would
|
|
48
|
+
// have reported. This runs in the Router constructor, so a throw is a blank
|
|
49
|
+
// page rather than a degraded route.
|
|
50
|
+
return new URL(nav.currentEntry?.url || window.location.href)
|
|
46
51
|
},
|
|
47
52
|
navigate(url, options) {
|
|
48
53
|
if (options?.viewTransition) {
|