forked from rosa/hakurei
Compare commits
18 Commits
pkgserver-
...
pkgserver-
| Author | SHA1 | Date | |
|---|---|---|---|
|
5ae3083690
|
|||
|
29f971b891
|
|||
|
7f932abfb9
|
|||
|
fac9ed4079
|
|||
|
29705065b8
|
|||
|
85b3d0e5cd
|
|||
|
a9816c7c93
|
|||
|
7be50fb888
|
|||
|
ab7eef1f5e
|
|||
|
9b0f8d123f
|
|||
|
5b7bfeaee7
|
|||
|
ed21c6d7ad
|
|||
|
10cf17b6b1
|
|||
|
9de2e5ee03
|
|||
|
ff39f57385
|
|||
|
c5350601ef
|
|||
|
4c051b082f
|
|||
|
77a597fc44
|
@@ -91,7 +91,7 @@ func redirectUI(w http.ResponseWriter, r *http.Request) {
|
||||
func testUiRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /test.html", serveTestWebUI)
|
||||
mux.HandleFunc("GET /testui/", serveTestWebUIStaticContent)
|
||||
mux.HandleFunc("GET /test/lib/", serveTestLibrary)
|
||||
mux.HandleFunc("GET /test/lib", serveTestLibrary)
|
||||
mux.HandleFunc("GET /test/", serveTests)
|
||||
mux.HandleFunc("GET /ui/", redirectUI)
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
// Import all test files to register their test suites.
|
||||
import "./sample_tests.js";
|
||||
// Import all test files to execute their suite registrations.
|
||||
import "./test_tests.js";
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// development.
|
||||
|
||||
import "../all_tests.js";
|
||||
import { StreamReporter, GLOBAL_REGISTRAR } from "./test.js";
|
||||
import { StreamReporter, TESTS } from "./test.js";
|
||||
|
||||
// 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
|
||||
@@ -44,5 +44,5 @@ if (args.length === 1) {
|
||||
}
|
||||
|
||||
let reporter = new StreamReporter({ writeln: console.log }, verbose);
|
||||
GLOBAL_REGISTRAR.run(reporter);
|
||||
TESTS.run(reporter);
|
||||
exit(reporter.succeeded() ? 0 : 1);
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import "../all_tests.js";
|
||||
import { GoTestReporter, GLOBAL_REGISTRAR } from "./test.js";
|
||||
GLOBAL_REGISTRAR.run(new GoTestReporter());
|
||||
import { GoTestReporter, TESTS } from "./test.js";
|
||||
TESTS.run(new GoTestReporter());
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
// DSL
|
||||
|
||||
type TestTree = TestGroup | Test;
|
||||
type TestGroup = { name: string; children: TestTree[] };
|
||||
type Test = { name: string; test: (t: TestController) => void };
|
||||
type TestGroup = { name: string, children: TestTree[] };
|
||||
type Test = { name: string, test: (t: TestController) => void };
|
||||
|
||||
export class TestRegistrar {
|
||||
#suites: TestGroup[];
|
||||
@@ -13,7 +13,7 @@ export class TestRegistrar {
|
||||
}
|
||||
|
||||
suite(name: string, children: TestTree[]) {
|
||||
checkDuplicates(name, children);
|
||||
checkDuplicates(name, children)
|
||||
this.#suites.push({ name, children });
|
||||
}
|
||||
|
||||
@@ -26,19 +26,18 @@ export class TestRegistrar {
|
||||
}
|
||||
}
|
||||
|
||||
export let GLOBAL_REGISTRAR = new TestRegistrar();
|
||||
export let TESTS = new TestRegistrar();
|
||||
|
||||
// Register a suite in the global registrar.
|
||||
export function suite(name: string, children: TestTree[]) {
|
||||
GLOBAL_REGISTRAR.suite(name, children);
|
||||
TESTS.suite(name, children);
|
||||
}
|
||||
|
||||
export function group(name: string, children: TestTree[]): TestTree {
|
||||
export function context(name: string, children: TestTree[]): TestTree {
|
||||
checkDuplicates(name, children);
|
||||
return { name, children };
|
||||
}
|
||||
export const context = group;
|
||||
export const describe = group;
|
||||
export const group = context;
|
||||
|
||||
export function test(name: string, test: (t: TestController) => void): TestTree {
|
||||
return { name, test };
|
||||
@@ -149,7 +148,7 @@ function extractExceptionString(e: any): string {
|
||||
// Reporting
|
||||
|
||||
export interface Reporter {
|
||||
register(suites: TestGroup[]): void;
|
||||
register(suites: TestGroup[]): void
|
||||
update(path: string[], result: TestResult): void;
|
||||
finalize(): void;
|
||||
}
|
||||
@@ -230,8 +229,8 @@ export class StreamReporter implements Reporter {
|
||||
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` : ""),
|
||||
`${this.#successes.length} succeeded, ${this.#failures.length} failed`
|
||||
+ (this.#skips.length ? `, ${this.#skips.length} skipped` : "")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -294,7 +293,7 @@ export class DOMReporter implements Reporter {
|
||||
update(path: string[], result: TestResult) {
|
||||
if (path.length === 0) throw new RangeError("path is empty");
|
||||
if (result.state === "skip") {
|
||||
assertGetElementById("skip-counter-text").hidden = false;
|
||||
assertGetElementById("skip-counter-text").classList.remove("hidden");
|
||||
}
|
||||
const counter = assertGetElementById(`${result.state}-counter`);
|
||||
counter.innerText = (Number(counter.innerText) + 1).toString();
|
||||
@@ -332,8 +331,6 @@ export class DOMReporter implements Reporter {
|
||||
child.classList.add("failure");
|
||||
child.classList.remove("skip");
|
||||
child.classList.remove("success");
|
||||
// The summary marker does not appear in the AOM, so setting its
|
||||
// alt text is fruitless; label the summary itself instead.
|
||||
summary.setAttribute("aria-labelledby", "failure-description");
|
||||
break;
|
||||
case "skip":
|
||||
@@ -370,23 +367,23 @@ export class DOMReporter implements Reporter {
|
||||
|
||||
interface GoNode {
|
||||
name: string;
|
||||
subtests?: GoNode[];
|
||||
subtests: GoNode[] | null;
|
||||
}
|
||||
|
||||
// Used to display results via `go test`, via some glue code from the Go side.
|
||||
export class GoTestReporter implements Reporter {
|
||||
register(suites: TestGroup[]) {
|
||||
console.log(JSON.stringify(suites.map(GoTestReporter.serialize)));
|
||||
}
|
||||
|
||||
// Convert a test tree into the one expected by the Go code.
|
||||
static serialize(node: TestTree): GoNode {
|
||||
return {
|
||||
name: node.name,
|
||||
subtests: "children" in node ? node.children.map(GoTestReporter.serialize) : undefined,
|
||||
subtests: "children" in node ? node.children.map(GoTestReporter.serialize) : null,
|
||||
};
|
||||
}
|
||||
|
||||
register(suites: TestGroup[]) {
|
||||
console.log(JSON.stringify(suites.map(GoTestReporter.serialize)));
|
||||
}
|
||||
|
||||
update(path: string[], result: TestResult) {
|
||||
let state: number;
|
||||
switch (result.state) {
|
||||
@@ -394,7 +391,7 @@ export class GoTestReporter implements Reporter {
|
||||
case "failure": state = 1; break;
|
||||
case "skip": state = 2; break;
|
||||
}
|
||||
console.log(JSON.stringify({ path, state, logs: result.logs }));
|
||||
console.log(JSON.stringify({ path: path, state, logs: result.logs }));
|
||||
}
|
||||
|
||||
finalize() {
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<main>
|
||||
<p id="counters">
|
||||
<span id="success-counter">0</span> succeeded, <span id="failure-counter">0</span>
|
||||
failed<span id="skip-counter-text" hidden>, <span id="skip-counter">0</span> skipped</span>.
|
||||
failed<span id="skip-counter-text" class="hidden">, <span id="skip-counter">0</span> skipped</span>.
|
||||
</p>
|
||||
|
||||
<p hidden id="success-description">Successful test</p>
|
||||
@@ -31,8 +31,8 @@
|
||||
|
||||
<script type="module">
|
||||
import "/test/all_tests.js";
|
||||
import { DOMReporter, GLOBAL_REGISTRAR } from "/test/lib/test.js";
|
||||
GLOBAL_REGISTRAR.run(new DOMReporter());
|
||||
import { DOMReporter, TESTS } from "/test/lib/test.js";
|
||||
TESTS.run(new DOMReporter());
|
||||
</script>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
/*
|
||||
* If updating the theme colors, also update them in success-closed.svg and
|
||||
* success-open.svg!
|
||||
*/
|
||||
|
||||
:root {
|
||||
--bg: #d3d3d3;
|
||||
--fg: black;
|
||||
@@ -83,6 +78,10 @@ p.test-desc {
|
||||
}
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.italic {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user