Compare commits
12 Commits
97d6fd9bfa
...
e5cd9a10b9
| Author | SHA1 | Date | |
|---|---|---|---|
|
e5cd9a10b9
|
|||
|
f84cbd492d
|
|||
|
16186882bf
|
|||
|
5d57b8e0fc
|
|||
|
bc39688aa3
|
|||
|
a462583783
|
|||
|
aabddddc89
|
|||
|
f12c74e77b
|
|||
|
550fd6f724
|
|||
|
cd46234892
|
|||
|
7697f44d94
|
|||
|
66c391d2eb
|
@@ -28,11 +28,32 @@ func serveStaticContent(w http.ResponseWriter, r *http.Request) {
|
|||||||
case "/static/test.js":
|
case "/static/test.js":
|
||||||
http.ServeFileFS(w, r, content, "ui/static/test.js")
|
http.ServeFileFS(w, r, content, "ui/static/test.js")
|
||||||
case "/static/test.css":
|
case "/static/test.css":
|
||||||
http.ServeFileFS(w, r, content, "ui/static/test.css")
|
darkTheme := r.CookiesNamed("dark_theme")
|
||||||
|
if len(darkTheme) > 0 && darkTheme[0].Value == "true" {
|
||||||
|
http.ServeFileFS(w, r, content, "ui/static/test_dark.css")
|
||||||
|
} else {
|
||||||
|
http.ServeFileFS(w, r, content, "ui/static/test_light.css")
|
||||||
|
}
|
||||||
case "/static/all_tests.js":
|
case "/static/all_tests.js":
|
||||||
http.ServeFileFS(w, r, content, "ui/static/all_tests.js")
|
http.ServeFileFS(w, r, content, "ui/static/all_tests.js")
|
||||||
case "/static/test_tests.js":
|
case "/static/test_tests.js":
|
||||||
http.ServeFileFS(w, r, content, "ui/static/test_tests.js")
|
http.ServeFileFS(w, r, content, "ui/static/test_tests.js")
|
||||||
|
case "/static/success-closed-white.svg":
|
||||||
|
http.ServeFileFS(w, r, content, "ui/static/success-closed-white.svg")
|
||||||
|
case "/static/success-open-white.svg":
|
||||||
|
http.ServeFileFS(w, r, content, "ui/static/success-open-white.svg")
|
||||||
|
case "/static/success-closed-black.svg":
|
||||||
|
http.ServeFileFS(w, r, content, "ui/static/success-closed-black.svg")
|
||||||
|
case "/static/success-open-black.svg":
|
||||||
|
http.ServeFileFS(w, r, content, "ui/static/success-open-black.svg")
|
||||||
|
case "/static/failure-closed.svg":
|
||||||
|
http.ServeFileFS(w, r, content, "ui/static/failure-closed.svg")
|
||||||
|
case "/static/failure-open.svg":
|
||||||
|
http.ServeFileFS(w, r, content, "ui/static/failure-open.svg")
|
||||||
|
case "/static/skip-closed.svg":
|
||||||
|
http.ServeFileFS(w, r, content, "ui/static/skip-closed.svg")
|
||||||
|
case "/static/skip-open.svg":
|
||||||
|
http.ServeFileFS(w, r, content, "ui/static/skip-open.svg")
|
||||||
default:
|
default:
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
|
|
||||||
|
|||||||
62
cmd/pkgserver/ui/static/_test_common.scss
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
html {
|
||||||
|
background-color: var(--bg);
|
||||||
|
color: var(--fg);
|
||||||
|
}
|
||||||
|
|
||||||
|
h1, p, summary {
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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, and
|
||||||
|
* its ::-webkit-details-marker doesn't seem to work whatsoever; thus,
|
||||||
|
* set a color as a fallback: while it may be confusing for colorblind
|
||||||
|
* individuals, it's better than no indication of a test's state.
|
||||||
|
* See: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/::marker#browser_compatibility
|
||||||
|
*/
|
||||||
|
color: var(--fg);
|
||||||
|
/* content set in theme-specific file. */
|
||||||
|
}
|
||||||
|
&.failure > summary::marker {
|
||||||
|
color: red;
|
||||||
|
content: url("/static/failure-closed.svg");
|
||||||
|
}
|
||||||
|
&.failure[open] > summary::marker {
|
||||||
|
content: url("/static/failure-open.svg");
|
||||||
|
}
|
||||||
|
&.skip > summary::marker {
|
||||||
|
color: blue;
|
||||||
|
content: url("/static/skip-closed.svg");
|
||||||
|
}
|
||||||
|
&.skip[open] > summary::marker {
|
||||||
|
content: url("/static/skip-open.svg");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p.test-desc {
|
||||||
|
margin: 0 0 0 1rem;
|
||||||
|
padding: 2px 0;
|
||||||
|
> pre {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.italic {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
13
cmd/pkgserver/ui/static/failure-closed.svg
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- See failure-open.svg for an explanation of the view box dimensions. -->
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" viewBox="-20,-20 160 130">
|
||||||
|
<!-- This triangle should match success-closed-black.svg, fill and stroke color notwithstanding. -->
|
||||||
|
<polygon points="0,0 100,50 0,100" fill="red" stroke="red" stroke-width="15" stroke-linejoin="round"/>
|
||||||
|
<!--
|
||||||
|
! y-coordinates go before x-coordinates here to highlight the difference
|
||||||
|
! (or, lack thereof) between these numbers and the ones in failure-open.svg;
|
||||||
|
! try a textual diff. Make sure to keep the numbers in sync!
|
||||||
|
-->
|
||||||
|
<line y1="30" x1="10" y2="70" x2="50" stroke="white" stroke-width="16"/>
|
||||||
|
<line y1="30" x1="50" y2="70" x2="10" stroke="white" stroke-width="16"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 794 B |
35
cmd/pkgserver/ui/static/failure-open.svg
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
! This view box is a bit weird: the strokes assume they're working in a view
|
||||||
|
! box that spans from the (0,0) to (100,100), and indeed that is convenient
|
||||||
|
! conceptualizing the strokes, but the stroke itself has a considerable width
|
||||||
|
! that gets clipped by restrictive view box dimensions. Hence, the view is
|
||||||
|
! shifted from (0,0)–(100,100) to (-20,-20)–(120,120), to make room for the
|
||||||
|
! clipped stroke, while leaving behind an illusion of working in a view box
|
||||||
|
! spanning from (0,0) to (100,100).
|
||||||
|
!
|
||||||
|
! However, the resulting SVG is too close to the summary text, and CSS
|
||||||
|
! properties to add padding do not seem to work with `content:` (likely because
|
||||||
|
! they're anonymous replaced elements); thus, the width of the view is
|
||||||
|
! increased considerably to provide padding in the SVG itself, while leaving
|
||||||
|
! the strokes oblivious.
|
||||||
|
!
|
||||||
|
! It gets worse: the summary text isn't vertically aligned with the icon! As
|
||||||
|
! a flexbox cannot be used in a summary to align the marker with the text, the
|
||||||
|
! simplest and most effective solution is to reduce the height of the view box
|
||||||
|
! from 140 to 130, thereby removing some of the bottom padding present.
|
||||||
|
!
|
||||||
|
! All eight SVGs use the same view box (and indeed, they refer to this comment)
|
||||||
|
! so that they all appear to be the same size and position relative to each
|
||||||
|
! other on the DOM—indeed, the view box dimensions, alongside the width,
|
||||||
|
! directly control their placement on the DOM.
|
||||||
|
!
|
||||||
|
! TL;DR: CSS is janky, overflow is weird, and SVG is awesome!
|
||||||
|
-->
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" viewBox="-20,-20 160 130">
|
||||||
|
<!-- This triangle should match success-open-black.svg, fill and stroke color notwithstanding. -->
|
||||||
|
<polygon points="0,0 100,0 50,100" fill="red" stroke="red" stroke-width="15" stroke-linejoin="round"/>
|
||||||
|
<!-- See the comment in failure-closed.svg before modifying this. -->
|
||||||
|
<line x1="30" y1="10" x2="70" y2="50" stroke="white" stroke-width="16"/>
|
||||||
|
<line x1="30" y1="50" x2="70" y2="10" stroke="white" stroke-width="16"/>
|
||||||
|
</svg>
|
||||||
@@ -1,7 +1,48 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
// Many editors have terminal emulators built in, so running tests with NodeJS
|
// Many editors have terminal emulators built in, so running tests with NodeJS
|
||||||
// provides faster iteration, especially for those acclimated to test-driven
|
// provides faster iteration, especially for those acclimated to test-driven
|
||||||
// development.
|
// development.
|
||||||
|
|
||||||
import "./all_tests.js";
|
import "./all_tests.js";
|
||||||
import { StreamReporter, TESTS } from "./test.js";
|
import { StreamReporter, TESTS } from "./test.js";
|
||||||
TESTS.run(new StreamReporter({ writeln: console.log }));
|
|
||||||
|
// TypeScript doesn't like process and Deno as their type definitions aren't
|
||||||
|
// installed, but doesn't seem to complain if they're accessed through
|
||||||
|
// globalThis.
|
||||||
|
const process: any = globalThis.process;
|
||||||
|
const Deno: any = globalThis.Deno;
|
||||||
|
|
||||||
|
function getArgs(): string[] {
|
||||||
|
if (process) {
|
||||||
|
const [runtime, program, ...args] = process.argv;
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
if (Deno) return Deno.args;
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function exit(code?: number): never {
|
||||||
|
if (Deno) Deno.exit(code);
|
||||||
|
if (process) process.exit(code);
|
||||||
|
throw `exited with code ${code ?? 0}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const args = getArgs();
|
||||||
|
let verbose = false;
|
||||||
|
if (args.length > 1) {
|
||||||
|
console.error("Too many arguments");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (args.length === 1) {
|
||||||
|
if (args[0] === "-v" || args[0] === "--verbose" || args[0] === "-verbose") {
|
||||||
|
verbose = true;
|
||||||
|
} else if (args[0] !== "--") {
|
||||||
|
console.error(`Unknown argument '${args[0]}'`);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let reporter = new StreamReporter({ writeln: console.log }, verbose);
|
||||||
|
TESTS.run(reporter);
|
||||||
|
exit(reporter.succeeded() ? 0 : 1);
|
||||||
|
|||||||
21
cmd/pkgserver/ui/static/skip-closed.svg
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- See failure-open.svg for an explanation of the view box dimensions. -->
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" viewBox="-20,-20 160 130">
|
||||||
|
<!-- This triangle should match success-closed-black.svg, fill and stroke color notwithstanding. -->
|
||||||
|
<polygon points="0,0 100,50 0,100" fill="blue" stroke="blue" stroke-width="15" stroke-linejoin="round"/>
|
||||||
|
<!--
|
||||||
|
! This path is extremely similar to the one in skip-open.svg; before
|
||||||
|
! making minor modifications, diff the two to understand how they should
|
||||||
|
! remain in sync.
|
||||||
|
-->
|
||||||
|
<path
|
||||||
|
d="M 50,50
|
||||||
|
A 23,23 270,1,1 30,30
|
||||||
|
l -10,20
|
||||||
|
m 10,-20
|
||||||
|
l -20,-10"
|
||||||
|
fill="none"
|
||||||
|
stroke="white"
|
||||||
|
stroke-width="12"
|
||||||
|
stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 818 B |
21
cmd/pkgserver/ui/static/skip-open.svg
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- See failure-open.svg for an explanation of the view box dimensions. -->
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" viewBox="-20,-20 160 130">
|
||||||
|
<!-- This triangle should match success-open-black.svg, fill and stroke color notwithstanding. -->
|
||||||
|
<polygon points="0,0 100,0 50,100" fill="blue" stroke="blue" stroke-width="15" stroke-linejoin="round"/>
|
||||||
|
<!--
|
||||||
|
! This path is extremely similar to the one in skip-closed.svg; before
|
||||||
|
! making minor modifications, diff the two to understand how they should
|
||||||
|
! remain in sync.
|
||||||
|
-->
|
||||||
|
<path
|
||||||
|
d="M 50,50
|
||||||
|
A 23,23 270,1,1 70,30
|
||||||
|
l 10,-20
|
||||||
|
m -10,20
|
||||||
|
l -20,-10"
|
||||||
|
fill="none"
|
||||||
|
stroke="white"
|
||||||
|
stroke-width="12"
|
||||||
|
stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 818 B |
6
cmd/pkgserver/ui/static/success-closed-black.svg
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- See failure-open.svg for an explanation of the view box dimensions. -->
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" viewBox="-20,-20 160 130">
|
||||||
|
<!-- When updating this triangle, also update the other seven SVGs. -->
|
||||||
|
<polygon points="0,0 100,50 0,100" fill="none" stroke="black" stroke-width="15" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 370 B |
6
cmd/pkgserver/ui/static/success-closed-white.svg
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- See failure-open.svg for an explanation of the view box dimensions. -->
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" viewBox="-20,-20 160 130">
|
||||||
|
<!-- This triangle should match success-closed-black.svg, stroke color notwithstanding. -->
|
||||||
|
<polygon points="0,0 100,50 0,100" fill="none" stroke="ghostwhite" stroke-width="15" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 395 B |
6
cmd/pkgserver/ui/static/success-open-black.svg
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- See failure-open.svg for an explanation of the view box dimensions. -->
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" viewBox="-20,-20 160 130">
|
||||||
|
<!-- When updating this triangle, also update the other seven SVGs. -->
|
||||||
|
<polygon points="0,0 100,0 50,100" fill="none" stroke="black" stroke-width="15" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 370 B |
6
cmd/pkgserver/ui/static/success-open-white.svg
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- See failure-open.svg for an explanation of the view box dimensions. -->
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" viewBox="-20,-20 160 130">
|
||||||
|
<!-- This triangle should match success-open-black.svg, stroke color notwithstanding. -->
|
||||||
|
<polygon points="0,0 100,0 50,100" fill="none" stroke="ghostwhite" stroke-width="15" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 393 B |
@@ -1,31 +0,0 @@
|
|||||||
h1, p, summary {
|
|
||||||
font-family: sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
.root {
|
|
||||||
margin: 1rem 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
details.test-node {
|
|
||||||
margin-left: 1rem;
|
|
||||||
padding: 0.2rem 0.5rem;
|
|
||||||
border-left: 2px dashed black;
|
|
||||||
> summary {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
&.failure > summary::marker {
|
|
||||||
color: red;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
p.test-desc {
|
|
||||||
margin: 0 0 0 1rem;
|
|
||||||
padding: 2px 0;
|
|
||||||
> pre {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.italic {
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
@@ -53,28 +53,44 @@ function checkDuplicates(parent: string, names: { name: string }[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FailNowSentinel {}
|
export type TestState = "success" | "failure" | "skip";
|
||||||
|
|
||||||
|
class AbortSentinel {}
|
||||||
|
|
||||||
export class TestController {
|
export class TestController {
|
||||||
|
#state: TestState;
|
||||||
logs: string[];
|
logs: string[];
|
||||||
#failed: boolean;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
this.#state = "success";
|
||||||
this.logs = [];
|
this.logs = [];
|
||||||
this.#failed = false;
|
}
|
||||||
|
|
||||||
|
getState(): TestState {
|
||||||
|
return this.#state;
|
||||||
}
|
}
|
||||||
|
|
||||||
fail() {
|
fail() {
|
||||||
this.#failed = true;
|
this.#state = "failure";
|
||||||
}
|
}
|
||||||
|
|
||||||
failed(): boolean {
|
failed(): boolean {
|
||||||
return this.#failed;
|
return this.#state === "failure";
|
||||||
}
|
}
|
||||||
|
|
||||||
failNow(): never {
|
failNow(): never {
|
||||||
this.fail();
|
this.fail();
|
||||||
throw new FailNowSentinel();
|
throw new AbortSentinel();
|
||||||
|
}
|
||||||
|
|
||||||
|
skip(message?: string): never {
|
||||||
|
if (message != null) this.log(message);
|
||||||
|
if (this.#state !== "failure") this.#state = "skip";
|
||||||
|
throw new AbortSentinel();
|
||||||
|
}
|
||||||
|
|
||||||
|
skipped(): boolean {
|
||||||
|
return this.#state === "skip";
|
||||||
}
|
}
|
||||||
|
|
||||||
log(message: string) {
|
log(message: string) {
|
||||||
@@ -96,7 +112,7 @@ export class TestController {
|
|||||||
// Execution
|
// Execution
|
||||||
|
|
||||||
export interface TestResult {
|
export interface TestResult {
|
||||||
success: boolean;
|
state: TestState;
|
||||||
logs: string[];
|
logs: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,11 +126,11 @@ function runTests(reporter: Reporter, parents: string[], node: TestTree) {
|
|||||||
try {
|
try {
|
||||||
node.test(controller);
|
node.test(controller);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!(e instanceof FailNowSentinel)) {
|
if (!(e instanceof AbortSentinel)) {
|
||||||
controller.error(extractExceptionString(e));
|
controller.error(extractExceptionString(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reporter.update(path, { success: !controller.failed(), logs: controller.logs });
|
reporter.update(path, { state: controller.getState(), logs: controller.logs });
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractExceptionString(e: any): string {
|
function extractExceptionString(e: any): string {
|
||||||
@@ -170,14 +186,20 @@ const SEP = " ❯ ";
|
|||||||
export class StreamReporter implements Reporter {
|
export class StreamReporter implements Reporter {
|
||||||
stream: Stream;
|
stream: Stream;
|
||||||
verbose: boolean;
|
verbose: boolean;
|
||||||
|
#successes: ({ path: string[] } & TestResult)[];
|
||||||
#failures: ({ path: string[] } & TestResult)[];
|
#failures: ({ path: string[] } & TestResult)[];
|
||||||
counts: { successes: number, failures: number };
|
#skips: ({ path: string[] } & TestResult)[];
|
||||||
|
|
||||||
constructor(stream: Stream, verbose: boolean = false) {
|
constructor(stream: Stream, verbose: boolean = false) {
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
this.verbose = verbose;
|
this.verbose = verbose;
|
||||||
|
this.#successes = [];
|
||||||
this.#failures = [];
|
this.#failures = [];
|
||||||
this.counts = { successes: 0, failures: 0 };
|
this.#skips = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
succeeded(): boolean {
|
||||||
|
return this.#successes.length > 0 && this.#failures.length === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
register(suites: TestGroup[]) {}
|
register(suites: TestGroup[]) {}
|
||||||
@@ -185,31 +207,52 @@ export class StreamReporter implements Reporter {
|
|||||||
update(path: string[], result: TestResult) {
|
update(path: string[], result: TestResult) {
|
||||||
if (path.length === 0) throw new RangeError("path is empty");
|
if (path.length === 0) throw new RangeError("path is empty");
|
||||||
const pathStr = path.join(SEP);
|
const pathStr = path.join(SEP);
|
||||||
if (result.success) {
|
switch (result.state) {
|
||||||
this.counts.successes++;
|
case "success":
|
||||||
|
this.#successes.push({ path, ...result });
|
||||||
if (this.verbose) this.stream.writeln(`✅️ ${pathStr}`);
|
if (this.verbose) this.stream.writeln(`✅️ ${pathStr}`);
|
||||||
} else {
|
break;
|
||||||
this.counts.failures++;
|
case "failure":
|
||||||
this.stream.writeln(`⚠️ ${pathStr}`);
|
|
||||||
this.#failures.push({ path, ...result });
|
this.#failures.push({ path, ...result });
|
||||||
|
this.stream.writeln(`⚠️ ${pathStr}`);
|
||||||
|
break;
|
||||||
|
case "skip":
|
||||||
|
this.#skips.push({ path, ...result });
|
||||||
|
this.stream.writeln(`⏭️ ${pathStr}`);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
finalize() {
|
finalize() {
|
||||||
|
if (this.verbose) this.#displaySection("successes", this.#successes, true);
|
||||||
|
this.#displaySection("failures", this.#failures);
|
||||||
|
this.#displaySection("skips", this.#skips);
|
||||||
|
this.stream.writeln("");
|
||||||
|
this.stream.writeln(
|
||||||
|
`${this.#successes.length} succeeded, ${this.#failures.length} failed`
|
||||||
|
+ (this.#skips.length ? `, ${this.#skips.length} skipped` : "")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#displaySection(name: string, data: ({ path: string[] } & TestResult)[], ignoreEmpty: boolean = false) {
|
||||||
|
if (!data.length) return;
|
||||||
|
|
||||||
// Transform [{ path: ["a", "b", "c"] }, { path: ["a", "b", "d"] }]
|
// Transform [{ path: ["a", "b", "c"] }, { path: ["a", "b", "d"] }]
|
||||||
// into { "a ❯ b": ["c", "d"] }.
|
// into { "a ❯ b": ["c", "d"] }.
|
||||||
let pathMap = new Map<string, ({ name: string } & TestResult)[]>();
|
let pathMap = new Map<string, ({ name: string } & TestResult)[]>();
|
||||||
for (const f of this.#failures) {
|
for (const t of data) {
|
||||||
const key = f.path.slice(0, -1).join(SEP);
|
const key = t.path.slice(0, -1).join(SEP);
|
||||||
if (!pathMap.has(key)) pathMap.set(key, []);
|
if (!pathMap.has(key)) pathMap.set(key, []);
|
||||||
pathMap.get(key).push({ name: f.path.at(-1), ...f });
|
pathMap.get(key).push({ name: t.path.at(-1), ...t });
|
||||||
}
|
}
|
||||||
|
|
||||||
this.stream.writeln("");
|
this.stream.writeln("");
|
||||||
this.stream.writeln("FAILURES");
|
this.stream.writeln(name.toUpperCase());
|
||||||
this.stream.writeln("========");
|
this.stream.writeln("=".repeat(name.length));
|
||||||
|
|
||||||
for (const [path, tests] of pathMap) {
|
for (let [path, tests] of pathMap) {
|
||||||
|
if (ignoreEmpty) tests = tests.filter((t) => t.logs.length);
|
||||||
|
if (tests.length === 0) continue;
|
||||||
if (tests.length === 1) {
|
if (tests.length === 1) {
|
||||||
this.#writeOutput(tests[0], path ? `${path}${SEP}` : "", false);
|
this.#writeOutput(tests[0], path ? `${path}${SEP}` : "", false);
|
||||||
} else {
|
} else {
|
||||||
@@ -217,10 +260,6 @@ export class StreamReporter implements Reporter {
|
|||||||
for (const t of tests) this.#writeOutput(t, " - ", true);
|
for (const t of tests) this.#writeOutput(t, " - ", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.stream.writeln("");
|
|
||||||
const { successes, failures } = this.counts;
|
|
||||||
this.stream.writeln(`${successes} succeeded, ${failures} failed`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#writeOutput(test: { name: string } & TestResult, prefix: string, nested: boolean) {
|
#writeOutput(test: { name: string } & TestResult, prefix: string, nested: boolean) {
|
||||||
@@ -246,8 +285,12 @@ export class DOMReporter implements Reporter {
|
|||||||
|
|
||||||
update(path: string[], result: TestResult) {
|
update(path: string[], result: TestResult) {
|
||||||
if (path.length === 0) throw new RangeError("path is empty");
|
if (path.length === 0) throw new RangeError("path is empty");
|
||||||
const counter = document.getElementById(result.success ? "successes" : "failures");
|
if (result.state === "skip") {
|
||||||
|
document.getElementById("skip-counter-text").classList.remove("hidden");
|
||||||
|
}
|
||||||
|
const counter = document.getElementById(`${result.state}-counter`);
|
||||||
counter.innerText = (Number(counter.innerText) + 1).toString();
|
counter.innerText = (Number(counter.innerText) + 1).toString();
|
||||||
|
|
||||||
let parent = document.getElementById("root");
|
let parent = document.getElementById("root");
|
||||||
for (const node of path) {
|
for (const node of path) {
|
||||||
let child = null;
|
let child = null;
|
||||||
@@ -267,12 +310,30 @@ export class DOMReporter implements Reporter {
|
|||||||
child.appendChild(summary);
|
child.appendChild(summary);
|
||||||
parent.appendChild(child);
|
parent.appendChild(child);
|
||||||
}
|
}
|
||||||
if (!result.success) {
|
|
||||||
|
switch (result.state) {
|
||||||
|
case "failure":
|
||||||
child.open = true;
|
child.open = true;
|
||||||
child.classList.add("failure");
|
child.classList.add("failure");
|
||||||
|
child.classList.remove("skip");
|
||||||
|
child.classList.remove("success");
|
||||||
|
break;
|
||||||
|
case "skip":
|
||||||
|
if (child.classList.contains("failure")) break;
|
||||||
|
child.classList.add("skip");
|
||||||
|
child.classList.remove("success");
|
||||||
|
break;
|
||||||
|
case "success":
|
||||||
|
if (!(child.classList.contains("failure") ||
|
||||||
|
child.classList.contains("skip"))) {
|
||||||
|
child.classList.add("success")
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
parent = child;
|
parent = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
const p = document.createElement("p");
|
const p = document.createElement("p");
|
||||||
p.classList.add("test-desc");
|
p.classList.add("test-desc");
|
||||||
if (result.logs.length) {
|
if (result.logs.length) {
|
||||||
@@ -309,7 +370,13 @@ export class GoTestReporter implements Reporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update(path: string[], result: TestResult) {
|
update(path: string[], result: TestResult) {
|
||||||
console.log(JSON.stringify({ path: path, ...result }));
|
let state: number;
|
||||||
|
switch (result.state) {
|
||||||
|
case "success": state = 0; break;
|
||||||
|
case "failure": state = 1; break;
|
||||||
|
case "skip": state = 2; break;
|
||||||
|
}
|
||||||
|
console.log(JSON.stringify({ path: path, state, logs: result.logs }));
|
||||||
}
|
}
|
||||||
|
|
||||||
finalize() {
|
finalize() {
|
||||||
|
|||||||
19
cmd/pkgserver/ui/static/test_dark.scss
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
@use "test_common";
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--bg: #2c2c2c;
|
||||||
|
--fg: ghostwhite;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The color of an SVG in a content: cannot be controlled via CSS as it's not
|
||||||
|
* present in the DOM, so use duplicated versions.
|
||||||
|
*/
|
||||||
|
details.test-node.success {
|
||||||
|
> summary::marker {
|
||||||
|
content: url("/static/success-closed-white.svg");
|
||||||
|
}
|
||||||
|
&[open] > summary::marker {
|
||||||
|
content: url("/static/success-open-white.svg");
|
||||||
|
}
|
||||||
|
}
|
||||||
19
cmd/pkgserver/ui/static/test_light.scss
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
@use "test_common";
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--bg: #d3d3d3;
|
||||||
|
--fg: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The color of an SVG in a content: cannot be controlled via CSS as it's not
|
||||||
|
* present in the DOM, so use duplicated versions.
|
||||||
|
*/
|
||||||
|
details.test-node.success {
|
||||||
|
> summary::marker {
|
||||||
|
content: url("/static/success-closed-black.svg");
|
||||||
|
}
|
||||||
|
&[open] > summary::marker {
|
||||||
|
content: url("/static/success-open-black.svg");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,6 +37,10 @@ suite("cat", [
|
|||||||
test("likes headpats", (t) => {
|
test("likes headpats", (t) => {
|
||||||
t.log("meow");
|
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) => {
|
test("tester tester", (t) => {
|
||||||
const r = new TestRegistrar();
|
const r = new TestRegistrar();
|
||||||
r.suite("explod", [
|
r.suite("explod", [
|
||||||
@@ -73,7 +77,7 @@ suite("cat", [
|
|||||||
result.path[1] === "with yarn")) {
|
result.path[1] === "with yarn")) {
|
||||||
t.error(`incorrect result path got=${result.path} want=["explod", "with yarn"]`);
|
t.error(`incorrect result path got=${result.path} want=["explod", "with yarn"]`);
|
||||||
}
|
}
|
||||||
if (!result.success) t.error(`expected test to succeed`);
|
if (result.state !== "success") t.error(`expected test to succeed`);
|
||||||
if (!(result.logs.length === 1 && result.logs[0] === "YAY")) {
|
if (!(result.logs.length === 1 && result.logs[0] === "YAY")) {
|
||||||
t.error(`incorrect result logs got=${result.logs} want=["YAY"]`);
|
t.error(`incorrect result logs got=${result.logs} want=["YAY"]`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link rel="stylesheet" href="static/style.css">
|
|
||||||
<link rel="stylesheet" href="static/test.css">
|
<link rel="stylesheet" href="static/test.css">
|
||||||
<title>PkgServer Tests</title>
|
<title>PkgServer Tests</title>
|
||||||
</head>
|
</head>
|
||||||
@@ -12,7 +11,8 @@
|
|||||||
|
|
||||||
<main>
|
<main>
|
||||||
<p id="counters">
|
<p id="counters">
|
||||||
<span id="successes">0</span> succeeded, <span id="failures">0</span> failed.
|
<span id="success-counter">0</span> succeeded, <span id="failure-counter">0</span>
|
||||||
|
failed<span id="skip-counter-text" class="hidden">, <span id="skip-counter">0</span> skipped</span>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div id="root">
|
<div id="root">
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ package main
|
|||||||
|
|
||||||
import "embed"
|
import "embed"
|
||||||
|
|
||||||
//go:generate sh -c "sass ui/static/dark.scss ui/static/dark.css && sass ui/static/light.scss ui/static/light.css && sass ui/static/test.scss ui/static/test.css && tsc -p ui/static"
|
//go:generate sh -c "sass ui/static/dark.scss ui/static/dark.css && sass ui/static/light.scss ui/static/light.css && sass ui/static/test_light.scss ui/static/test_light.css && sass ui/static/test_dark.scss ui/static/test_dark.css && tsc -p ui/static"
|
||||||
//go:embed ui/*
|
//go:embed ui/*
|
||||||
var content embed.FS
|
var content embed.FS
|
||||||
|
|||||||