@desk-framework/frame-test
Advanced tools
Comparing version 4.0.0-dev.29 to 4.0.0-dev.30
@@ -11,2 +11,3 @@ import { Assertion, NegatedAssertion } from "./Assertion.js"; | ||
export * from "./app/TestContext.js"; | ||
export * from "./format.js"; | ||
/** | ||
@@ -152,7 +153,1 @@ * Creates a new {@link Assertion} object, ready to evaluate the given value | ||
export declare function getTestResults(): TestResultsData; | ||
/** | ||
* Returns a string-formatted version of the provided test results object, in English | ||
* - The test results object can be obtained using {@link getTestResults()}. | ||
* - Formatted results only include skipped, todo, and failed tests. It's advisable to log the full JSON data to a file as well. | ||
*/ | ||
export declare function formatTestResults(results: TestResultsData): string; |
@@ -10,2 +10,3 @@ import { Assertion, NegatedAssertion } from "./Assertion.js"; | ||
export * from "./app/TestContext.js"; | ||
export * from "./format.js"; | ||
/** | ||
@@ -183,42 +184,1 @@ * Creates a new {@link Assertion} object, ready to evaluate the given value | ||
} | ||
/** | ||
* Returns a string-formatted version of the provided test results object, in English | ||
* - The test results object can be obtained using {@link getTestResults()}. | ||
* - Formatted results only include skipped, todo, and failed tests. It's advisable to log the full JSON data to a file as well. | ||
*/ | ||
export function formatTestResults(results) { | ||
let text = ""; | ||
text += `Tests completed in ${results.time}ms\n`; | ||
for (let r of results.results) { | ||
if (r.state === "skip") | ||
text += `- Skipped: ${r.name}\n`; | ||
if (r.state === "todo") | ||
text += `- To do: ${r.name}\n`; | ||
} | ||
for (let r of results.results) { | ||
if (r.state === "fail") { | ||
text += `\nERROR: ${r.name}\n`; | ||
if (r.logs) | ||
text += r.logs + "\n"; | ||
if (r.error) | ||
text += r.error + "\n"; | ||
if (r.stack) | ||
text += | ||
String(r.stack) | ||
.split(/[\r\n]+/) | ||
.filter((line) => /\.js:\d+/.test(line)) | ||
.filter((line) => !/\/dist\//.test(line)) | ||
.slice(0, 3) | ||
.join("\n") + "\n"; | ||
} | ||
} | ||
text += results.failed ? "\n❌ FAIL" : "✅ PASS"; | ||
if (results.totals.fail) | ||
text += ", " + results.totals.fail + " failed"; | ||
if (results.totals.todo) | ||
text += ", " + results.totals.todo + " to do"; | ||
if (results.totals.skip) | ||
text += ", " + results.totals.skip + " skipped"; | ||
text += ", " + results.totals.pass + " passed."; | ||
return text; | ||
} |
@@ -39,3 +39,3 @@ import { RenderContext, View } from "@desk-framework/frame-core"; | ||
/** Returns a global render callback, which adds new output to the root element */ | ||
getRenderCallback(): RenderContext.RenderCallback<unknown>; | ||
getRenderCallback(): RenderContext.RenderCallback; | ||
/** | ||
@@ -42,0 +42,0 @@ * Attempts to set input focus to the specified element in the background |
@@ -183,2 +183,5 @@ import { RenderContext, app, } from "@desk-framework/frame-core"; | ||
async expectOutputAsync(timeout, ...select) { | ||
// prepare timeout error first, to capture accurate stack trace | ||
let timeoutError = Error("expectOutputAsync timeout: " + select.map((s) => val2str(s)).join(" ")); | ||
// start polling | ||
let startT = Date.now(); | ||
@@ -196,5 +199,3 @@ return new Promise((resolve, reject) => { | ||
if (timeout && Date.now() > startT + timeout) { | ||
// reject because of timeout | ||
return reject(new Error("expectOutputAsync timeout: " + | ||
select.map((s) => val2str(s)).join(" "))); | ||
return reject(timeoutError); | ||
} | ||
@@ -201,0 +202,0 @@ poll(); |
@@ -332,6 +332,11 @@ import { app } from "@desk-framework/frame-core"; | ||
async expectNavAsync(timeout, pageId, detail = "") { | ||
await this.pollAsync(() => app.navigation.pageId === pageId && app.navigation.detail === detail, 5, timeout, () => Error("Expected navigation to " + | ||
val2str(pageId + "/" + detail) + | ||
" but location is " + | ||
val2str(app.navigation.pageId + "/" + app.navigation.detail))); | ||
// create error first, to capture accurate stack trace | ||
let error = Error("Expected navigation to " + val2str(pageId + "/" + detail)); | ||
// start polling | ||
await this.pollAsync(() => app.navigation.pageId === pageId && app.navigation.detail === detail, 5, timeout, () => { | ||
error.message += | ||
", but location is " + | ||
val2str(app.navigation.pageId + "/" + app.navigation.detail); | ||
return error; | ||
}); | ||
} | ||
@@ -338,0 +343,0 @@ /** |
{ | ||
"name": "@desk-framework/frame-test", | ||
"version": "4.0.0-dev.29", | ||
"version": "4.0.0-dev.30", | ||
"publishConfig": { | ||
@@ -31,2 +31,5 @@ "tag": "next" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"peerDependencies": { | ||
@@ -33,0 +36,0 @@ "@desk-framework/frame-core": "4.0.0-dev.29" |
@@ -25,2 +25,2 @@ # Desk framework: Test library | ||
Copyright © 2023 Jelmer Cormont | ||
Copyright © 2024 Jelmer Cormont |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
213974
63
5023