forked from rosa/hakurei
Compare commits
8 Commits
pkgserver-
...
982c48372f
| Author | SHA1 | Date | |
|---|---|---|---|
| 982c48372f | |||
|
3aef1e81a7
|
|||
|
b2bc5c396b
|
|||
|
4c62e90315
|
|||
|
6364cc0c51
|
|||
|
17732bfe54
|
|||
|
7255fa4ac3
|
|||
|
0183064f25
|
@@ -127,7 +127,7 @@ func (index *packageIndex) handleSearch(w http.ResponseWriter, r *http.Request)
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
search, err := url.QueryUnescape(q.Get("search"))
|
search, err := url.PathUnescape(q.Get("search"))
|
||||||
if len(search) > 100 || err != nil {
|
if len(search) > 100 || err != nil {
|
||||||
http.Error(
|
http.Error(
|
||||||
w, "search must be a string between 0 and 100 characters long",
|
w, "search must be a string between 0 and 100 characters long",
|
||||||
@@ -142,7 +142,7 @@ func (index *packageIndex) handleSearch(w http.ResponseWriter, r *http.Request)
|
|||||||
}
|
}
|
||||||
writeAPIPayload(w, &struct {
|
writeAPIPayload(w, &struct {
|
||||||
Count int `json:"count"`
|
Count int `json:"count"`
|
||||||
Values []searchResult `json:"values"`
|
Results []searchResult `json:"results"`
|
||||||
}{n, res})
|
}{n, res})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"hakurei.app/check"
|
|
||||||
"hakurei.app/command"
|
"hakurei.app/command"
|
||||||
|
"hakurei.app/container/check"
|
||||||
"hakurei.app/internal/pkg"
|
"hakurei.app/internal/pkg"
|
||||||
"hakurei.app/internal/rosa"
|
"hakurei.app/internal/rosa"
|
||||||
"hakurei.app/message"
|
"hakurei.app/message"
|
||||||
@@ -47,7 +47,7 @@ func main() {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cache, err = pkg.Open(ctx, msg, 0, 0, baseDir)
|
cache, err = pkg.Open(ctx, msg, 0, baseDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,13 +22,9 @@ type searchCacheEntry struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (index *packageIndex) performSearchQuery(limit int, i int, search string, desc bool) (int, []searchResult, error) {
|
func (index *packageIndex) performSearchQuery(limit int, i int, search string, desc bool) (int, []searchResult, error) {
|
||||||
query := search
|
entry, ok := index.search[search]
|
||||||
if desc {
|
if ok {
|
||||||
query += ";withDesc"
|
return len(entry.results), entry.results[i:min(i+limit, len(entry.results))], nil
|
||||||
}
|
|
||||||
entry, ok := index.search[query]
|
|
||||||
if ok && len(entry.results) > 0 {
|
|
||||||
return len(entry.results), entry.results[min(i, len(entry.results)-1):min(i+limit, len(entry.results))], nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
regex, err := regexp.Compile(search)
|
regex, err := regexp.Compile(search)
|
||||||
@@ -63,7 +59,7 @@ func (index *packageIndex) performSearchQuery(limit int, i int, search string, d
|
|||||||
results: res,
|
results: res,
|
||||||
expiry: expiry,
|
expiry: expiry,
|
||||||
}
|
}
|
||||||
index.search[query] = entry
|
index.search[search] = entry
|
||||||
|
|
||||||
return len(res), res[i:min(i+limit, len(entry.results))], nil
|
return len(res), res[i:min(i+limit, len(entry.results))], nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,11 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Always remove ui_test/ui; if the previous tsc run failed, the rm never
|
|
||||||
// executes.
|
|
||||||
|
|
||||||
//go:generate sh -c "rm -r ui_test/ui/ 2>/dev/null || true"
|
|
||||||
//go:generate mkdir ui_test/ui
|
//go:generate mkdir ui_test/ui
|
||||||
//go:generate sh -c "cp ui/static/*.ts ui_test/ui/"
|
//go:generate sh -c "cp ui/static/*.ts ui_test/ui/"
|
||||||
//go:generate tsc -p ui_test
|
//go:generate tsc --outDir ui_test/static -p ui_test
|
||||||
//go:generate rm -r ui_test/ui/
|
//go:generate rm -r ui_test/ui/
|
||||||
//go:generate cp ui_test/lib/ui.css ui_test/static/style.css
|
//go:generate sass ui_test/lib/ui.scss ui_test/static/style.css
|
||||||
//go:generate cp ui_test/lib/ui.html ui_test/static/index.html
|
//go:generate cp ui_test/lib/ui.html ui_test/static/index.html
|
||||||
//go:generate sh -c "cd ui_test/lib && cp *.svg ../static/"
|
//go:generate sh -c "cd ui_test/lib && cp *.svg ../static/"
|
||||||
//go:embed ui_test/static
|
//go:embed ui_test/static
|
||||||
|
|||||||
@@ -15,7 +15,12 @@ func serveWebUI(w http.ResponseWriter, r *http.Request) {
|
|||||||
func serveStaticContent(w http.ResponseWriter, r *http.Request) {
|
func serveStaticContent(w http.ResponseWriter, r *http.Request) {
|
||||||
switch r.URL.Path {
|
switch r.URL.Path {
|
||||||
case "/static/style.css":
|
case "/static/style.css":
|
||||||
http.ServeFileFS(w, r, content, "ui/static/style.css")
|
darkTheme := r.CookiesNamed("dark_theme")
|
||||||
|
if len(darkTheme) > 0 && darkTheme[0].Value == "true" {
|
||||||
|
http.ServeFileFS(w, r, content, "ui/static/dark.css")
|
||||||
|
} else {
|
||||||
|
http.ServeFileFS(w, r, content, "ui/static/light.css")
|
||||||
|
}
|
||||||
case "/favicon.ico":
|
case "/favicon.ico":
|
||||||
http.ServeFileFS(w, r, content, "ui/static/favicon.ico")
|
http.ServeFileFS(w, r, content, "ui/static/favicon.ico")
|
||||||
case "/static/index.js":
|
case "/static/index.js":
|
||||||
|
|||||||
@@ -2,56 +2,34 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<link rel="stylesheet" href="static/style.css">
|
<link rel="stylesheet" href="static/style.css">
|
||||||
<title>Hakurei PkgServer</title>
|
<title>Hakurei PkgServer</title>
|
||||||
<script src="static/index.js"></script>
|
<script src="static/index.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Hakurei PkgServer</h1>
|
<h1>Hakurei PkgServer</h1>
|
||||||
<div class="top-controls" id="top-controls-regular">
|
|
||||||
|
<table id="pkg-list">
|
||||||
|
<tr><td>Loading...</td></tr>
|
||||||
|
</table>
|
||||||
<p>Showing entries <span id="entry-counter"></span>.</p>
|
<p>Showing entries <span id="entry-counter"></span>.</p>
|
||||||
<span id="search-bar">
|
<span class="bottom-nav"><a href="javascript:prevPage()">« Previous</a> <span id="page-number">1</span> <a href="javascript:nextPage()">Next »</a></span>
|
||||||
<label for="search">Search: </label>
|
<span><label for="count">Entries per page: </label><select name="count" id="count">
|
||||||
<input type="text" name="search" id="search"/>
|
|
||||||
<button onclick="doSearch()">Find</button>
|
|
||||||
<label for="include-desc">Include descriptions: </label>
|
|
||||||
<input type="checkbox" name="include-desc" id="include-desc" checked/>
|
|
||||||
</span>
|
|
||||||
<div><label for="count">Entries per page: </label><select name="count" id="count">
|
|
||||||
<option value="10">10</option>
|
<option value="10">10</option>
|
||||||
<option value="20">20</option>
|
<option value="20">20</option>
|
||||||
<option value="30">30</option>
|
<option value="30">30</option>
|
||||||
<option value="50">50</option>
|
<option value="50">50</option>
|
||||||
</select></div>
|
</select></span>
|
||||||
<div><label for="sort">Sort by: </label><select name="sort" id="sort">
|
<span><label for="sort">Sort by: </label><select name="sort" id="sort">
|
||||||
<option value="0">Definition (ascending)</option>
|
<option value="0">Definition (ascending)</option>
|
||||||
<option value="1">Definition (descending)</option>
|
<option value="1">Definition (descending)</option>
|
||||||
<option value="2">Name (ascending)</option>
|
<option value="2">Name (ascending)</option>
|
||||||
<option value="3">Name (descending)</option>
|
<option value="3">Name (descending)</option>
|
||||||
<option value="4">Size (ascending)</option>
|
<option value="4">Size (ascending)</option>
|
||||||
<option value="5">Size (descending)</option>
|
<option value="5">Size (descending)</option>
|
||||||
</select></div>
|
</select></span>
|
||||||
</div>
|
</body>
|
||||||
<div class="top-controls" id="search-top-controls" hidden>
|
|
||||||
<p>Showing search results <span id="search-entry-counter"></span> for query "<span id="search-query"></span>".</p>
|
|
||||||
<button onclick="exitSearch()">Back</button>
|
|
||||||
<div><label for="search-count">Entries per page: </label><select name="search-count" id="search-count">
|
|
||||||
<option value="10">10</option>
|
|
||||||
<option value="20">20</option>
|
|
||||||
<option value="30">30</option>
|
|
||||||
<option value="50">50</option>
|
|
||||||
</select></div>
|
|
||||||
<p>Sorted by best match</p>
|
|
||||||
</div>
|
|
||||||
<div class="page-controls"><a href="javascript:prevPage()">« Previous</a> <input type="text" class="page-number" value="1"/> <a href="javascript:nextPage()">Next »</a></div>
|
|
||||||
<table id="pkg-list">
|
|
||||||
<tr><td>Loading...</td></tr>
|
|
||||||
</table>
|
|
||||||
<div class="page-controls"><a href="javascript:prevPage()">« Previous</a> <input type="text" class="page-number" value="1"/> <a href="javascript:nextPage()">Next »</a></div>
|
|
||||||
<footer>
|
<footer>
|
||||||
<p>©<a href="https://hakurei.app/">Hakurei</a> (<span id="hakurei-version">unknown</span>). Licensed under the MIT license.</p>
|
<p>©<a href="https://hakurei.app/">Hakurei</a> (<span id="hakurei-version">unknown</span>). Licensed under the MIT license.</p>
|
||||||
</footer>
|
</footer>
|
||||||
<script>main();</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
@@ -1,327 +0,0 @@
|
|||||||
interface PackageIndexEntry {
|
|
||||||
name: string
|
|
||||||
size?: number
|
|
||||||
description?: string
|
|
||||||
website?: string
|
|
||||||
version?: string
|
|
||||||
report?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
function entryToHTML(entry: PackageIndexEntry | SearchResult): HTMLTableRowElement {
|
|
||||||
let v = entry.version != null ? `<span>${escapeHtml(entry.version)}</span>` : ""
|
|
||||||
let s = entry.size != null && entry.size > 0 ? `<p>Size: ${toByteSizeString(entry.size)} (${entry.size})</p>` : ""
|
|
||||||
let n: string
|
|
||||||
let d: string
|
|
||||||
if ('name_matches' in entry) {
|
|
||||||
n = `<h2>${nameMatches(entry as SearchResult)} ${v}</h2>`
|
|
||||||
} else {
|
|
||||||
n = `<h2>${escapeHtml(entry.name)} ${v}</h2>`
|
|
||||||
}
|
|
||||||
if ('desc_matches' in entry && STATE.getIncludeDescriptions()) {
|
|
||||||
d = descMatches(entry as SearchResult)
|
|
||||||
} else {
|
|
||||||
d = (entry as PackageIndexEntry).description != null ? `<p>${escapeHtml((entry as PackageIndexEntry).description)}</p>` : ""
|
|
||||||
}
|
|
||||||
let w = entry.website != null ? `<a href="${encodeURI(entry.website)}">Website</a>` : ""
|
|
||||||
let r = entry.report ? `Log (<a href=\"${encodeURI('/api/v1/status/' + entry.name)}\">View</a> | <a href=\"${encodeURI('/status/' + entry.name)}\">Download</a>)` : ""
|
|
||||||
let row = <HTMLTableRowElement>(document.createElement('tr'))
|
|
||||||
row.innerHTML = `<td>
|
|
||||||
${n}
|
|
||||||
${d}
|
|
||||||
${s}
|
|
||||||
${w}
|
|
||||||
${r}
|
|
||||||
</td>`
|
|
||||||
return row
|
|
||||||
}
|
|
||||||
|
|
||||||
function nameMatches(sr: SearchResult): string {
|
|
||||||
return markMatches(sr.name, sr.name_matches)
|
|
||||||
}
|
|
||||||
|
|
||||||
function descMatches(sr: SearchResult): string {
|
|
||||||
return markMatches(sr.description!, sr.desc_matches)
|
|
||||||
}
|
|
||||||
|
|
||||||
function markMatches(str: string, indices: [number, number][]): string {
|
|
||||||
if (indices == null) {
|
|
||||||
return str
|
|
||||||
}
|
|
||||||
let out: string = ""
|
|
||||||
let j = 0
|
|
||||||
for (let i = 0; i < str.length; i++) {
|
|
||||||
if (j < indices.length) {
|
|
||||||
if (i === indices[j][0]) {
|
|
||||||
out += `<mark>${escapeHtmlChar(str[i])}`
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if (i === indices[j][1]) {
|
|
||||||
out += `</mark>${escapeHtmlChar(str[i])}`
|
|
||||||
j++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out += escapeHtmlChar(str[i])
|
|
||||||
}
|
|
||||||
if (indices[j] !== undefined) {
|
|
||||||
out += "</mark>"
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
function toByteSizeString(bytes: number): string {
|
|
||||||
if (bytes == null) return `unspecified`
|
|
||||||
if (bytes < 1024) return `${bytes}B`
|
|
||||||
if (bytes < Math.pow(1024, 2)) return `${(bytes / 1024).toFixed(2)}kiB`
|
|
||||||
if (bytes < Math.pow(1024, 3)) return `${(bytes / Math.pow(1024, 2)).toFixed(2)}MiB`
|
|
||||||
if (bytes < Math.pow(1024, 4)) return `${(bytes / Math.pow(1024, 3)).toFixed(2)}GiB`
|
|
||||||
if (bytes < Math.pow(1024, 5)) return `${(bytes / Math.pow(1024, 4)).toFixed(2)}TiB`
|
|
||||||
return "not only is it big, it's large"
|
|
||||||
}
|
|
||||||
|
|
||||||
const API_VERSION = 1
|
|
||||||
const ENDPOINT = `/api/v${API_VERSION}`
|
|
||||||
|
|
||||||
interface InfoPayload {
|
|
||||||
count?: number
|
|
||||||
hakurei_version?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
async function infoRequest(): Promise<InfoPayload> {
|
|
||||||
const res = await fetch(`${ENDPOINT}/info`)
|
|
||||||
const payload = await res.json()
|
|
||||||
return payload as InfoPayload
|
|
||||||
}
|
|
||||||
|
|
||||||
interface GetPayload {
|
|
||||||
values?: PackageIndexEntry[]
|
|
||||||
}
|
|
||||||
|
|
||||||
enum SortOrders {
|
|
||||||
DeclarationAscending,
|
|
||||||
DeclarationDescending,
|
|
||||||
NameAscending,
|
|
||||||
NameDescending
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getRequest(limit: number, index: number, sort: SortOrders): Promise<GetPayload> {
|
|
||||||
const res = await fetch(`${ENDPOINT}/get?limit=${limit}&index=${index}&sort=${sort.valueOf()}`)
|
|
||||||
const payload = await res.json()
|
|
||||||
return payload as GetPayload
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SearchResult extends PackageIndexEntry {
|
|
||||||
name_matches: [number, number][]
|
|
||||||
desc_matches: [number, number][]
|
|
||||||
score: number
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SearchPayload {
|
|
||||||
count?: number
|
|
||||||
values?: SearchResult[]
|
|
||||||
}
|
|
||||||
|
|
||||||
async function searchRequest(limit: number, index: number, search: string, desc: boolean): Promise<SearchPayload> {
|
|
||||||
const res = await fetch(`${ENDPOINT}/search?limit=${limit}&index=${index}&search=${encodeURIComponent(search)}&desc=${desc}`)
|
|
||||||
if (!res.ok) {
|
|
||||||
alert("invalid search query!")
|
|
||||||
exitSearch()
|
|
||||||
return Promise.reject(res.statusText)
|
|
||||||
}
|
|
||||||
const payload = await res.json()
|
|
||||||
return payload as SearchPayload
|
|
||||||
}
|
|
||||||
|
|
||||||
class State {
|
|
||||||
entriesPerPage: number = 10
|
|
||||||
entryIndex: number = 0
|
|
||||||
maxTotal: number = 0
|
|
||||||
maxEntries: number = 0
|
|
||||||
sort: SortOrders = SortOrders.DeclarationAscending
|
|
||||||
search: boolean = false
|
|
||||||
|
|
||||||
getEntriesPerPage(): number {
|
|
||||||
return this.entriesPerPage
|
|
||||||
}
|
|
||||||
|
|
||||||
setEntriesPerPage(entriesPerPage: number) {
|
|
||||||
this.entriesPerPage = entriesPerPage
|
|
||||||
this.setEntryIndex(Math.floor(this.getEntryIndex() / entriesPerPage) * entriesPerPage)
|
|
||||||
}
|
|
||||||
|
|
||||||
getEntryIndex(): number {
|
|
||||||
return this.entryIndex
|
|
||||||
}
|
|
||||||
|
|
||||||
setEntryIndex(entryIndex: number) {
|
|
||||||
this.entryIndex = entryIndex
|
|
||||||
this.updatePage()
|
|
||||||
this.updateRange()
|
|
||||||
this.updateListings()
|
|
||||||
}
|
|
||||||
|
|
||||||
getMaxTotal(): number {
|
|
||||||
return this.maxTotal
|
|
||||||
}
|
|
||||||
|
|
||||||
setMaxTotal(max: number) {
|
|
||||||
this.maxTotal = max
|
|
||||||
}
|
|
||||||
|
|
||||||
getSortOrder(): SortOrders {
|
|
||||||
return this.sort
|
|
||||||
}
|
|
||||||
|
|
||||||
setSortOrder(sortOrder: SortOrders) {
|
|
||||||
this.sort = sortOrder
|
|
||||||
this.setEntryIndex(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePage() {
|
|
||||||
let page = Math.ceil(((this.getEntryIndex() + this.getEntriesPerPage()) - 1) / this.getEntriesPerPage())
|
|
||||||
for (let e of document.getElementsByClassName("page-number")) {
|
|
||||||
(e as HTMLInputElement).value = String(page)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateRange() {
|
|
||||||
let max = Math.min(this.getEntryIndex() + this.getEntriesPerPage(), this.getMaxTotal())
|
|
||||||
document.getElementById("entry-counter")!.textContent = `${this.getEntryIndex() + 1}-${max} of ${this.getMaxTotal()}`
|
|
||||||
if (this.search) {
|
|
||||||
document.getElementById("search-entry-counter")!.textContent = `${this.getEntryIndex() + 1}-${max} of ${this.maxTotal}/${this.maxEntries}`
|
|
||||||
document.getElementById("search-query")!.innerHTML = `<code>${escapeHtml(this.getSearchQuery())}</code>`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getSearchQuery(): string {
|
|
||||||
let queryString = document.getElementById("search")!;
|
|
||||||
return (queryString as HTMLInputElement).value
|
|
||||||
}
|
|
||||||
|
|
||||||
getIncludeDescriptions(): boolean {
|
|
||||||
let includeDesc = document.getElementById("include-desc")!;
|
|
||||||
return (includeDesc as HTMLInputElement).checked
|
|
||||||
}
|
|
||||||
|
|
||||||
updateListings() {
|
|
||||||
if (this.search) {
|
|
||||||
searchRequest(this.getEntriesPerPage(), this.getEntryIndex(), this.getSearchQuery(), this.getIncludeDescriptions())
|
|
||||||
.then(res => {
|
|
||||||
let table = document.getElementById("pkg-list")!
|
|
||||||
table.innerHTML = ''
|
|
||||||
for (let row of res.values!) {
|
|
||||||
table.appendChild(entryToHTML(row))
|
|
||||||
}
|
|
||||||
STATE.maxTotal = res.count!
|
|
||||||
STATE.updateRange()
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
getRequest(this.getEntriesPerPage(), this.getEntryIndex(), this.getSortOrder())
|
|
||||||
.then(res => {
|
|
||||||
let table = document.getElementById("pkg-list")!
|
|
||||||
table.innerHTML = ''
|
|
||||||
for (let row of res.values!) {
|
|
||||||
table.appendChild(entryToHTML(row))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let STATE: State
|
|
||||||
|
|
||||||
|
|
||||||
function lastPageIndex(): number {
|
|
||||||
return Math.floor(STATE.getMaxTotal() / STATE.getEntriesPerPage()) * STATE.getEntriesPerPage()
|
|
||||||
}
|
|
||||||
|
|
||||||
function setPage(page: number) {
|
|
||||||
STATE.setEntryIndex(Math.max(0, Math.min(STATE.getEntriesPerPage() * (page - 1), lastPageIndex())))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function escapeHtml(str?: string): string {
|
|
||||||
let out: string = ''
|
|
||||||
if (str == undefined) return ""
|
|
||||||
for (let i = 0; i < str.length; i++) {
|
|
||||||
out += escapeHtmlChar(str[i])
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
function escapeHtmlChar(char: string): string {
|
|
||||||
if (char.length != 1) return char
|
|
||||||
switch (char[0]) {
|
|
||||||
case '&':
|
|
||||||
return "&"
|
|
||||||
case '<':
|
|
||||||
return "<"
|
|
||||||
case '>':
|
|
||||||
return ">"
|
|
||||||
case '"':
|
|
||||||
return """
|
|
||||||
case "'":
|
|
||||||
return "'"
|
|
||||||
default:
|
|
||||||
return char
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function firstPage() {
|
|
||||||
STATE.setEntryIndex(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
function prevPage() {
|
|
||||||
let index = STATE.getEntryIndex()
|
|
||||||
STATE.setEntryIndex(Math.max(0, index - STATE.getEntriesPerPage()))
|
|
||||||
}
|
|
||||||
|
|
||||||
function lastPage() {
|
|
||||||
STATE.setEntryIndex(lastPageIndex())
|
|
||||||
}
|
|
||||||
|
|
||||||
function nextPage() {
|
|
||||||
let index = STATE.getEntryIndex()
|
|
||||||
STATE.setEntryIndex(Math.min(lastPageIndex(), index + STATE.getEntriesPerPage()))
|
|
||||||
}
|
|
||||||
|
|
||||||
function doSearch() {
|
|
||||||
document.getElementById("top-controls-regular")!.toggleAttribute("hidden");
|
|
||||||
document.getElementById("search-top-controls")!.toggleAttribute("hidden");
|
|
||||||
STATE.search = true;
|
|
||||||
STATE.setEntryIndex(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function exitSearch() {
|
|
||||||
document.getElementById("top-controls-regular")!.toggleAttribute("hidden");
|
|
||||||
document.getElementById("search-top-controls")!.toggleAttribute("hidden");
|
|
||||||
STATE.search = false;
|
|
||||||
STATE.setMaxTotal(STATE.maxEntries)
|
|
||||||
STATE.setEntryIndex(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
function main() {
|
|
||||||
STATE = new State()
|
|
||||||
infoRequest()
|
|
||||||
.then(res => {
|
|
||||||
STATE.maxEntries = res.count!
|
|
||||||
STATE.setMaxTotal(STATE.maxEntries)
|
|
||||||
document.getElementById("hakurei-version")!.textContent = res.hakurei_version!
|
|
||||||
STATE.updateRange()
|
|
||||||
STATE.updateListings()
|
|
||||||
})
|
|
||||||
for (let e of document.getElementsByClassName("page-number")) {
|
|
||||||
e.addEventListener("change", (_) => {
|
|
||||||
setPage(parseInt((e as HTMLInputElement).value))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
document.getElementById("count")?.addEventListener("change", (event) => {
|
|
||||||
STATE.setEntriesPerPage(parseInt((event.target as HTMLSelectElement).value))
|
|
||||||
})
|
|
||||||
document.getElementById("sort")?.addEventListener("change", (event) => {
|
|
||||||
STATE.setSortOrder(parseInt((event.target as HTMLSelectElement).value))
|
|
||||||
})
|
|
||||||
document.getElementById("search")?.addEventListener("keyup", (event) => {
|
|
||||||
if (event.key === 'Enter') doSearch()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
0
cmd/pkgserver/ui/static/_common.scss
Normal file
0
cmd/pkgserver/ui/static/_common.scss
Normal file
6
cmd/pkgserver/ui/static/dark.scss
Normal file
6
cmd/pkgserver/ui/static/dark.scss
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
@use 'common';
|
||||||
|
|
||||||
|
html {
|
||||||
|
background-color: #2c2c2c;
|
||||||
|
color: ghostwhite;
|
||||||
|
}
|
||||||
161
cmd/pkgserver/ui/static/index.ts
Normal file
161
cmd/pkgserver/ui/static/index.ts
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
function assertGetElementById(id: string): HTMLElement {
|
||||||
|
let elem = document.getElementById(id)
|
||||||
|
if(elem == null) throw new ReferenceError(`element with ID '${id}' missing from DOM`)
|
||||||
|
return elem
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PackageIndexEntry {
|
||||||
|
name: string
|
||||||
|
size: number | null
|
||||||
|
description: string | null
|
||||||
|
website: string | null
|
||||||
|
version: string | null
|
||||||
|
report: boolean
|
||||||
|
}
|
||||||
|
function toHTML(entry: PackageIndexEntry): HTMLTableRowElement {
|
||||||
|
let v = entry.version != null ? `<span>${escapeHtml(entry.version)}</span>` : ""
|
||||||
|
let s = entry.size != null ? `<p>Size: ${toByteSizeString(entry.size)} (${entry.size})</p>` : ""
|
||||||
|
let d = entry.description != null ? `<p>${escapeHtml(entry.description)}</p>` : ""
|
||||||
|
let w = entry.website != null ? `<a href="${encodeURI(entry.website)}">Website</a>` : ""
|
||||||
|
let r = entry.report ? `Log (<a href=\"${encodeURI('/api/v1/status/' + entry.name)}\">View</a> | <a href=\"${encodeURI('/status/' + entry.name)}\">Download</a>)` : ""
|
||||||
|
let row = <HTMLTableRowElement>(document.createElement('tr'))
|
||||||
|
row.innerHTML = `<td>
|
||||||
|
<h2>${escapeHtml(entry.name)} ${v}</h2>
|
||||||
|
${d}
|
||||||
|
${s}
|
||||||
|
${w}
|
||||||
|
${r}
|
||||||
|
</td>`
|
||||||
|
return row
|
||||||
|
}
|
||||||
|
|
||||||
|
function toByteSizeString(bytes: number): string {
|
||||||
|
if(bytes == null || bytes < 1024) return `${bytes}B`
|
||||||
|
if(bytes < Math.pow(1024, 2)) return `${(bytes/1024).toFixed(2)}kiB`
|
||||||
|
if(bytes < Math.pow(1024, 3)) return `${(bytes/Math.pow(1024, 2)).toFixed(2)}MiB`
|
||||||
|
if(bytes < Math.pow(1024, 4)) return `${(bytes/Math.pow(1024, 3)).toFixed(2)}GiB`
|
||||||
|
if(bytes < Math.pow(1024, 5)) return `${(bytes/Math.pow(1024, 4)).toFixed(2)}TiB`
|
||||||
|
return "not only is it big, it's large"
|
||||||
|
}
|
||||||
|
|
||||||
|
const API_VERSION = 1
|
||||||
|
const ENDPOINT = `/api/v${API_VERSION}`
|
||||||
|
interface InfoPayload {
|
||||||
|
count: number
|
||||||
|
hakurei_version: string
|
||||||
|
}
|
||||||
|
|
||||||
|
async function infoRequest(): Promise<InfoPayload> {
|
||||||
|
const res = await fetch(`${ENDPOINT}/info`)
|
||||||
|
const payload = await res.json()
|
||||||
|
return payload
|
||||||
|
}
|
||||||
|
interface GetPayload {
|
||||||
|
values: PackageIndexEntry[]
|
||||||
|
}
|
||||||
|
|
||||||
|
enum SortOrders {
|
||||||
|
DeclarationAscending,
|
||||||
|
DeclarationDescending,
|
||||||
|
NameAscending,
|
||||||
|
NameDescending
|
||||||
|
}
|
||||||
|
async function getRequest(limit: number, index: number, sort: SortOrders): Promise<GetPayload> {
|
||||||
|
const res = await fetch(`${ENDPOINT}/get?limit=${limit}&index=${index}&sort=${sort.valueOf()}`)
|
||||||
|
const payload = await res.json()
|
||||||
|
return payload
|
||||||
|
}
|
||||||
|
class State {
|
||||||
|
entriesPerPage: number = 10
|
||||||
|
entryIndex: number = 0
|
||||||
|
maxEntries: number = 0
|
||||||
|
sort: SortOrders = SortOrders.DeclarationAscending
|
||||||
|
|
||||||
|
getEntriesPerPage(): number {
|
||||||
|
return this.entriesPerPage
|
||||||
|
}
|
||||||
|
setEntriesPerPage(entriesPerPage: number) {
|
||||||
|
this.entriesPerPage = entriesPerPage
|
||||||
|
this.setEntryIndex(Math.floor(this.getEntryIndex() / entriesPerPage) * entriesPerPage)
|
||||||
|
}
|
||||||
|
getEntryIndex(): number {
|
||||||
|
return this.entryIndex
|
||||||
|
}
|
||||||
|
setEntryIndex(entryIndex: number) {
|
||||||
|
this.entryIndex = entryIndex
|
||||||
|
this.updatePage()
|
||||||
|
this.updateRange()
|
||||||
|
this.updateListings()
|
||||||
|
}
|
||||||
|
getMaxEntries(): number {
|
||||||
|
return this.maxEntries
|
||||||
|
}
|
||||||
|
setMaxEntries(max: number) {
|
||||||
|
this.maxEntries = max
|
||||||
|
}
|
||||||
|
getSortOrder(): SortOrders {
|
||||||
|
return this.sort
|
||||||
|
}
|
||||||
|
setSortOrder(sortOrder: SortOrders) {
|
||||||
|
this.sort = sortOrder
|
||||||
|
this.setEntryIndex(0)
|
||||||
|
}
|
||||||
|
updatePage() {
|
||||||
|
let page = Math.ceil(((this.getEntryIndex() + this.getEntriesPerPage()) - 1) / this.getEntriesPerPage())
|
||||||
|
assertGetElementById("page-number").innerText = String(page)
|
||||||
|
}
|
||||||
|
updateRange() {
|
||||||
|
let max = Math.min(this.getEntryIndex() + this.getEntriesPerPage(), this.getMaxEntries())
|
||||||
|
assertGetElementById("entry-counter").innerText = `${this.getEntryIndex() + 1}-${max} of ${this.getMaxEntries()}`
|
||||||
|
}
|
||||||
|
updateListings() {
|
||||||
|
getRequest(this.getEntriesPerPage(), this.getEntryIndex(), this.getSortOrder())
|
||||||
|
.then(res => {
|
||||||
|
let table = assertGetElementById("pkg-list")
|
||||||
|
table.innerHTML = ''
|
||||||
|
res.values.forEach((row) => {
|
||||||
|
table.appendChild(toHTML(row))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
let STATE: State
|
||||||
|
|
||||||
|
function prevPage() {
|
||||||
|
let index = STATE.getEntryIndex()
|
||||||
|
STATE.setEntryIndex(Math.max(0, index - STATE.getEntriesPerPage()))
|
||||||
|
}
|
||||||
|
function nextPage() {
|
||||||
|
let index = STATE.getEntryIndex()
|
||||||
|
STATE.setEntryIndex(Math.min((Math.ceil(STATE.getMaxEntries() / STATE.getEntriesPerPage()) * STATE.getEntriesPerPage()) - STATE.getEntriesPerPage(), index + STATE.getEntriesPerPage()))
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeHtml(str: string): string {
|
||||||
|
if(str === undefined) return ""
|
||||||
|
return str
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/'/g, ''')
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
STATE = new State()
|
||||||
|
infoRequest()
|
||||||
|
.then(res => {
|
||||||
|
STATE.setMaxEntries(res.count)
|
||||||
|
assertGetElementById("hakurei-version").innerText = res.hakurei_version
|
||||||
|
STATE.updateRange()
|
||||||
|
STATE.updateListings()
|
||||||
|
})
|
||||||
|
|
||||||
|
assertGetElementById("count").addEventListener("change", (event) => {
|
||||||
|
STATE.setEntriesPerPage(parseInt((event.target as HTMLSelectElement).value))
|
||||||
|
})
|
||||||
|
assertGetElementById("sort").addEventListener("change", (event) => {
|
||||||
|
STATE.setSortOrder(parseInt((event.target as HTMLSelectElement).value))
|
||||||
|
})
|
||||||
|
})
|
||||||
6
cmd/pkgserver/ui/static/light.scss
Normal file
6
cmd/pkgserver/ui/static/light.scss
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
@use 'common';
|
||||||
|
|
||||||
|
html {
|
||||||
|
background-color: #d3d3d3;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
.page-number {
|
|
||||||
width: 2em;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
.page-number {
|
|
||||||
width: 2em;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
html {
|
|
||||||
background-color: #2c2c2c;
|
|
||||||
color: ghostwhite;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@media (prefers-color-scheme: light) {
|
|
||||||
html {
|
|
||||||
background-color: #d3d3d3;
|
|
||||||
color: black;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
6
cmd/pkgserver/ui/static/tsconfig.json
Normal file
6
cmd/pkgserver/ui/static/tsconfig.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"strict": true,
|
||||||
|
"target": "ES2024"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "ES2024",
|
|
||||||
"strict": true,
|
|
||||||
"alwaysStrict": true,
|
|
||||||
"outDir": "static"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,6 +4,6 @@ package main
|
|||||||
|
|
||||||
import "embed"
|
import "embed"
|
||||||
|
|
||||||
//go:generate tsc -p ui
|
//go:generate sh -c "sass ui/static/dark.scss ui/static/dark.css && sass ui/static/light.scss ui/static/light.css && tsc -p ui/static"
|
||||||
//go:embed ui/*
|
//go:embed ui/*
|
||||||
var content embed.FS
|
var content embed.FS
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
// Import all test files to register their test suites.
|
// Import all test files to register their test suites.
|
||||||
import "./index_test.js";
|
import "./sample_tests.js";
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
import { suite, test } from "./lib/test.js";
|
|
||||||
import "./ui/index.js";
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
* When updating the theme colors, also update them in success-closed.svg and
|
|
||||||
* success-open.svg!
|
|
||||||
*/
|
|
||||||
|
|
||||||
:root {
|
|
||||||
--bg: #d3d3d3;
|
|
||||||
--fg: black;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
:root {
|
|
||||||
--bg: #2c2c2c;
|
|
||||||
--fg: ghostwhite;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
html {
|
|
||||||
background-color: var(--bg);
|
|
||||||
color: var(--fg);
|
|
||||||
}
|
|
||||||
|
|
||||||
h1, p, summary, noscript {
|
|
||||||
font-family: sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
noscript {
|
|
||||||
font-size: 16pt;
|
|
||||||
}
|
|
||||||
|
|
||||||
.root {
|
|
||||||
margin: 1rem 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
details.test-node {
|
|
||||||
margin-left: 1rem;
|
|
||||||
padding: 0.2rem 0.5rem;
|
|
||||||
border-left: 2px dashed var(--fg);
|
|
||||||
> summary {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
&.success > summary::marker {
|
|
||||||
/*
|
|
||||||
* WebKit only supports color and font-size properties in ::marker [1], and
|
|
||||||
* its ::-webkit-details-marker only supports hiding the marker entirely
|
|
||||||
* [2], contrary to mdn's example [3]; thus, set a color as a fallback:
|
|
||||||
* while it may not be accessible for colorblind individuals, it's better
|
|
||||||
* than no indication of a test's state for anyone, as that there's no other
|
|
||||||
* way to include an indication in the marker on WebKit.
|
|
||||||
*
|
|
||||||
* [1]: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/::marker#browser_compatibility
|
|
||||||
* [2]: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/summary#default_style
|
|
||||||
* [3]: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/summary#changing_the_summarys_icon
|
|
||||||
*/
|
|
||||||
color: var(--fg);
|
|
||||||
content: url("/test/success-closed.svg") / "success";
|
|
||||||
}
|
|
||||||
&.success[open] > summary::marker {
|
|
||||||
content: url("/test/success-open.svg") / "success";
|
|
||||||
}
|
|
||||||
&.failure > summary::marker {
|
|
||||||
color: red;
|
|
||||||
content: url("/test/failure-closed.svg") / "failure";
|
|
||||||
}
|
|
||||||
&.failure[open] > summary::marker {
|
|
||||||
content: url("/test/failure-open.svg") / "failure";
|
|
||||||
}
|
|
||||||
&.skip > summary::marker {
|
|
||||||
color: blue;
|
|
||||||
content: url("/test/skip-closed.svg") / "skip";
|
|
||||||
}
|
|
||||||
&.skip[open] > summary::marker {
|
|
||||||
content: url("/test/skip-open.svg") / "skip";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
p.test-desc {
|
|
||||||
margin: 0 0 0 1rem;
|
|
||||||
padding: 2px 0;
|
|
||||||
> pre {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.italic {
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
88
cmd/pkgserver/ui_test/lib/ui.scss
Normal file
88
cmd/pkgserver/ui_test/lib/ui.scss
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* If updating the theme colors, also update them in success-closed.svg and
|
||||||
|
* success-open.svg!
|
||||||
|
*/
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--bg: #d3d3d3;
|
||||||
|
--fg: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root {
|
||||||
|
--bg: #2c2c2c;
|
||||||
|
--fg: ghostwhite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
background-color: var(--bg);
|
||||||
|
color: var(--fg);
|
||||||
|
}
|
||||||
|
|
||||||
|
h1, p, summary, noscript {
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
noscript {
|
||||||
|
font-size: 16pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
.root {
|
||||||
|
margin: 1rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
details.test-node {
|
||||||
|
margin-left: 1rem;
|
||||||
|
padding: 0.2rem 0.5rem;
|
||||||
|
border-left: 2px dashed var(--fg);
|
||||||
|
> summary {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
&.success > summary::marker {
|
||||||
|
/*
|
||||||
|
* WebKit only supports color and font-size properties in ::marker [1],
|
||||||
|
* and its ::-webkit-details-marker only supports hiding the marker
|
||||||
|
* entirely [2], contrary to mdn's example [3]; thus, set a color as
|
||||||
|
* a fallback: while it may not be accessible for colorblind
|
||||||
|
* individuals, it's better than no indication of a test's state for
|
||||||
|
* anyone, as that there's no other way to include an indication in the
|
||||||
|
* marker on WebKit.
|
||||||
|
*
|
||||||
|
* [1]: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/::marker#browser_compatibility
|
||||||
|
* [2]: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/summary#default_style
|
||||||
|
* [3]: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/summary#changing_the_summarys_icon
|
||||||
|
*/
|
||||||
|
color: var(--fg);
|
||||||
|
content: url("/test/success-closed.svg") / "success";
|
||||||
|
}
|
||||||
|
&.success[open] > summary::marker {
|
||||||
|
content: url("/test/success-open.svg") / "success";
|
||||||
|
}
|
||||||
|
&.failure > summary::marker {
|
||||||
|
color: red;
|
||||||
|
content: url("/test/failure-closed.svg") / "failure";
|
||||||
|
}
|
||||||
|
&.failure[open] > summary::marker {
|
||||||
|
content: url("/test/failure-open.svg") / "failure";
|
||||||
|
}
|
||||||
|
&.skip > summary::marker {
|
||||||
|
color: blue;
|
||||||
|
content: url("/test/skip-closed.svg") / "skip";
|
||||||
|
}
|
||||||
|
&.skip[open] > summary::marker {
|
||||||
|
content: url("/test/skip-open.svg") / "skip";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p.test-desc {
|
||||||
|
margin: 0 0 0 1rem;
|
||||||
|
padding: 2px 0;
|
||||||
|
> pre {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.italic {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
86
cmd/pkgserver/ui_test/sample_tests.ts
Normal file
86
cmd/pkgserver/ui_test/sample_tests.ts
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
import "./ui/index.js";
|
||||||
|
import { NoOpReporter, TestRegistrar, context, group, suite, test } from "./lib/test.js";
|
||||||
|
|
||||||
|
suite("dog", [
|
||||||
|
group("tail", [
|
||||||
|
test("wags when happy", (t) => {
|
||||||
|
if (0 / 0 !== Infinity / Infinity) {
|
||||||
|
t.fatal("undefined must not be defined");
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
test("idle when down", (t) => {
|
||||||
|
t.log("test test");
|
||||||
|
t.error("dog whining noises go here");
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
test("likes headpats", (t) => {
|
||||||
|
if (2 !== 2) {
|
||||||
|
t.error("IEEE 754 violated: 2 is NaN");
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
context("near cat", [
|
||||||
|
test("is ecstatic", (t) => {
|
||||||
|
if (("b" + "a" + + "a" + "a").toLowerCase() === "banana") {
|
||||||
|
t.error("🍌🍌🍌");
|
||||||
|
t.error("🍌🍌🍌");
|
||||||
|
t.error("🍌🍌🍌");
|
||||||
|
t.failNow();
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
test("playfully bites cats' tails", (t) => {
|
||||||
|
t.log("arf!");
|
||||||
|
throw new Error("nom");
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
suite("cat", [
|
||||||
|
test("likes headpats", (t) => {
|
||||||
|
t.log("meow");
|
||||||
|
}),
|
||||||
|
test("owns skipping rope", (t) => {
|
||||||
|
t.skip("this cat is stuck in your machine!");
|
||||||
|
t.log("never logged");
|
||||||
|
}),
|
||||||
|
test("tester tester", (t) => {
|
||||||
|
const r = new TestRegistrar();
|
||||||
|
r.suite("explod", [
|
||||||
|
test("with yarn", (t) => {
|
||||||
|
t.log("YAY");
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
const reporter = new NoOpReporter();
|
||||||
|
r.run(reporter);
|
||||||
|
if (reporter.suites.length !== 1) {
|
||||||
|
t.fatal(`incorrect number of suites registered got=${reporter.suites.length} want=1`);
|
||||||
|
}
|
||||||
|
const suite = reporter.suites[0];
|
||||||
|
if (suite.name !== "explod") {
|
||||||
|
t.error(`suite name incorrect got='${suite.name}' want='explod'`);
|
||||||
|
}
|
||||||
|
if (suite.children.length !== 1) {
|
||||||
|
t.fatal(`incorrect number of suite children got=${suite.children.length} want=1`);
|
||||||
|
}
|
||||||
|
const test_ = suite.children[0];
|
||||||
|
if (test_.name !== "with yarn") {
|
||||||
|
t.error(`incorrect test name got='${test_.name}' want='with yarn'`);
|
||||||
|
}
|
||||||
|
if ("children" in test_) {
|
||||||
|
t.error(`expected leaf node, got group of ${test_.children.length} children`);
|
||||||
|
}
|
||||||
|
if (!reporter.finalized) t.error(`expected reporter to have been finalized`);
|
||||||
|
if (reporter.results.length !== 1) {
|
||||||
|
t.fatal(`incorrect result count got=${reporter.results.length} want=1`);
|
||||||
|
}
|
||||||
|
const result = reporter.results[0];
|
||||||
|
if (!(result.path.length === 2 &&
|
||||||
|
result.path[0] === "explod" &&
|
||||||
|
result.path[1] === "with yarn")) {
|
||||||
|
t.error(`incorrect result path got=${result.path} want=["explod", "with yarn"]`);
|
||||||
|
}
|
||||||
|
if (result.state !== "success") t.error(`expected test to succeed`);
|
||||||
|
if (!(result.logs.length === 1 && result.logs[0] === "YAY")) {
|
||||||
|
t.error(`incorrect result logs got=${result.logs} want=["YAY"]`);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
]);
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2024",
|
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"alwaysStrict": true,
|
"target": "ES2024"
|
||||||
"outDir": "static"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user