test output for the browser
This commit is contained in:
parent
35e7e1f464
commit
f5a1a26368
@ -69,6 +69,10 @@ try {
|
|||||||
|
|
||||||
|
|
||||||
var script = `
|
var script = `
|
||||||
|
function onStatus(s) {
|
||||||
|
document.body.appendChild(document.createTextNode(s));
|
||||||
|
document.body.appendChild(document.createElement("br"));
|
||||||
|
}
|
||||||
function f() {
|
function f() {
|
||||||
if ("undefined" == typeof System) {
|
if ("undefined" == typeof System) {
|
||||||
console.log("can't access module loader");
|
console.log("can't access module loader");
|
||||||
@ -78,7 +82,7 @@ var script = `
|
|||||||
.then(tt => {
|
.then(tt => {
|
||||||
SystemJS.import("http://localhost:${httpPort}/${testScript}")
|
SystemJS.import("http://localhost:${httpPort}/${testScript}")
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return tt.run();
|
return tt.run(onStatus);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
window.__test_over = true;
|
window.__test_over = true;
|
||||||
|
@ -47,7 +47,7 @@ export function test(name: string, testFn: TestFn) {
|
|||||||
/**
|
/**
|
||||||
* Run all registered test case, producing a TAP stream.
|
* Run all registered test case, producing a TAP stream.
|
||||||
*/
|
*/
|
||||||
export async function run() {
|
export async function run(statusCallback?: (m: string) => void) {
|
||||||
console.log(`1..${tests.length}`);
|
console.log(`1..${tests.length}`);
|
||||||
for (let i in tests) {
|
for (let i in tests) {
|
||||||
let t = tests[i];
|
let t = tests[i];
|
||||||
@ -81,6 +81,7 @@ export async function run() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
console.log(`# ${t.name}`);
|
console.log(`# ${t.name}`);
|
||||||
|
statusCallback && statusCallback(`starting test ${t.name}`);
|
||||||
|
|
||||||
if (!lastMsg) {
|
if (!lastMsg) {
|
||||||
lastMsg = "-";
|
lastMsg = "-";
|
||||||
@ -92,9 +93,11 @@ export async function run() {
|
|||||||
throw Error("test did not call 'pass'");
|
throw Error("test did not call 'pass'");
|
||||||
}
|
}
|
||||||
console.log(`ok ${Number(i) + 1} ${lastMsg || "-"}`);
|
console.log(`ok ${Number(i) + 1} ${lastMsg || "-"}`);
|
||||||
|
statusCallback && statusCallback(`finished test ${t.name}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.log(`not ok ${Number(i) + 1} ${lastMsg || "-"}`);
|
console.log(`not ok ${Number(i) + 1} ${lastMsg || "-"}`);
|
||||||
|
statusCallback && statusCallback(`failed test ${t.name}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user