-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: Switch to uvu for Node/non-browser tests * test: Switch to wtr for browser tests * test: Remove leftover test file * chore: sort deps
- Loading branch information
1 parent
fa83cd8
commit 5309eb8
Showing
10 changed files
with
2,814 additions
and
2,439 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { test } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
|
||
import { locationStub } from '../../src/prerender.js'; | ||
|
||
test.before.each(() => { | ||
if (globalThis.location) { | ||
delete globalThis.location; | ||
} | ||
}); | ||
|
||
test('Contains all Location instance properties', () => { | ||
locationStub('/foo/bar?baz=qux#quux'); | ||
|
||
[ | ||
// 'ancestorOrigins', // Not supported by FireFox and sees little use, but we could add an empty val if it's needed | ||
'hash', | ||
'host', | ||
'hostname', | ||
'href', | ||
'origin', | ||
'pathname', | ||
'port', | ||
'protocol', | ||
'search', | ||
].forEach(key => { | ||
assert.ok(Object.hasOwn(globalThis.location, key), `missing: ${key}`); | ||
}); | ||
}); | ||
|
||
// Do we need to support `assign`, `reload`, and/or `replace`? | ||
test('Support bound methods', () => { | ||
locationStub('/foo/bar?baz=qux#quux'); | ||
|
||
assert.equal(globalThis.location.toString(), 'http://localhost/foo/bar?baz=qux#quux') | ||
}); | ||
|
||
test.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { test } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
import { html } from 'htm/preact'; | ||
|
||
import { default as prerender } from '../../src/prerender.js'; | ||
|
||
test('extracts links', async () => { | ||
const App = () => html` | ||
<div> | ||
<a href="/foo">foo</a> | ||
<a href="/bar" target="_blank">bar</a> | ||
<a href="/baz" target="_self">baz</a> | ||
</div> | ||
`; | ||
|
||
|
||
const { links } = await prerender(html`<${App} />`); | ||
assert.equal(links.size, 2, `incorrect number of links found: ${links.size}`); | ||
assert.ok(links.has('/foo'), `missing: /foo`); | ||
assert.ok(links.has('/baz'), `missing: /baz`); | ||
}); | ||
|
||
test('appends iso data script', async () => { | ||
const { html: h } = await prerender(html`<div />`); | ||
// Empty for now, but used for hydration vs render detection | ||
assert.match(h, /<script type="isodata"><\/script>/, 'missing iso data script tag'); | ||
}); | ||
|
||
test.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { test } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
|
||
// @ts-expect-error - no types, not meant for public use | ||
import { exec } from '../../src/router.js'; | ||
|
||
function execPath(path, pattern, opts) { | ||
return exec(path, pattern, { path, query: {}, params: {}, ...(opts || {}) }); | ||
} | ||
|
||
test('Base route', () => { | ||
const accurateResult = execPath('/', '/'); | ||
assert.equal(accurateResult, { path: '/', params: {}, query: {} }); | ||
|
||
const inaccurateResult = execPath('/user/1', '/'); | ||
assert.equal(inaccurateResult, undefined); | ||
}); | ||
|
||
test('Param route', () => { | ||
const accurateResult = execPath('/user/2', '/user/:id'); | ||
assert.equal(accurateResult, { path: '/user/2', params: { id: '2' }, id: '2', query: {} }); | ||
|
||
const inaccurateResult = execPath('/', '/user/:id'); | ||
assert.equal(inaccurateResult, undefined); | ||
}); | ||
|
||
test('Param rest segment', () => { | ||
const accurateResult = execPath('/user/foo', '/user/*'); | ||
assert.equal(accurateResult, { path: '/user/foo', params: {}, query: {}, rest: '/foo' }); | ||
|
||
const inaccurateResult = execPath('/', '/user/:id/*'); | ||
assert.equal(inaccurateResult, undefined); | ||
}); | ||
|
||
test('Param route with rest segment', () => { | ||
const accurateResult = execPath('/user/2/foo', '/user/:id/*'); | ||
assert.equal(accurateResult, { path: '/user/2/foo', params: { id: '2' }, id: '2', query: {}, rest: '/foo' }); | ||
|
||
const accurateResult2 = execPath('/user/2/foo/bar/bob', '/user/:id/*'); | ||
assert.equal(accurateResult2, { | ||
path: '/user/2/foo/bar/bob', | ||
params: { id: '2' }, | ||
id: '2', | ||
query: {}, | ||
rest: '/foo/bar/bob' | ||
}); | ||
|
||
const inaccurateResult = execPath('/', '/user/:id/*'); | ||
assert.equal(inaccurateResult, undefined); | ||
}); | ||
|
||
test('Optional param route', () => { | ||
const accurateResult = execPath('/user', '/user/:id?'); | ||
assert.equal(accurateResult, { path: '/user', params: { id: undefined }, id: undefined, query: {} }); | ||
|
||
const inaccurateResult = execPath('/', '/user/:id?'); | ||
assert.equal(inaccurateResult, undefined); | ||
}); | ||
|
||
test('Optional rest param route "/:x*"', () => { | ||
const accurateResult = execPath('/user', '/user/:id?'); | ||
assert.equal(accurateResult, { path: '/user', params: { id: undefined }, id: undefined, query: {} }); | ||
|
||
const inaccurateResult = execPath('/', '/user/:id?'); | ||
assert.equal(inaccurateResult, undefined); | ||
}); | ||
|
||
test('Rest param route "/:x+"', () => { | ||
const matchedResult = execPath('/user/foo', '/user/:id+'); | ||
assert.equal(matchedResult, { path: '/user/foo', params: { id: 'foo' }, id: 'foo', query: {} }); | ||
|
||
const matchedResultWithSlash = execPath('/user/foo/bar', '/user/:id+'); | ||
assert.equal(matchedResultWithSlash, { | ||
path: '/user/foo/bar', | ||
params: { id: 'foo/bar' }, | ||
id: 'foo/bar', | ||
query: {} | ||
}); | ||
|
||
const emptyResult = execPath('/user', '/user/:id+'); | ||
assert.equal(emptyResult, undefined); | ||
|
||
const mismatchedResult = execPath('/', '/user/:id+'); | ||
assert.equal(mismatchedResult, undefined); | ||
}); | ||
|
||
test('Handles leading/trailing slashes', () => { | ||
const result = execPath('/about-late/_SEGMENT1_/_SEGMENT2_/', '/about-late/:seg1/:seg2/'); | ||
assert.equal(result, { | ||
path: '/about-late/_SEGMENT1_/_SEGMENT2_/', | ||
params: { | ||
seg1: '_SEGMENT1_', | ||
seg2: '_SEGMENT2_' | ||
}, | ||
seg1: '_SEGMENT1_', | ||
seg2: '_SEGMENT2_', | ||
query: {} | ||
}); | ||
}); | ||
|
||
test('should not overwrite existing properties', () => { | ||
const result = execPath('/foo/bar', '/:path/:query', { path: '/custom-path' }); | ||
assert.equal(result, { | ||
params: { path: 'foo', query: 'bar' }, | ||
path: '/custom-path', | ||
query: {} | ||
}); | ||
}); | ||
|
||
test.run(); |
Oops, something went wrong.