diff options
-rw-r--r-- | std/http/file_server.ts | 5 | ||||
-rw-r--r-- | std/testing/_diff.ts | 5 | ||||
-rw-r--r-- | std/testing/asserts.ts | 18 |
3 files changed, 28 insertions, 0 deletions
diff --git a/std/http/file_server.ts b/std/http/file_server.ts index b75f9f9c1..331dbe5c5 100644 --- a/std/http/file_server.ts +++ b/std/http/file_server.ts @@ -112,6 +112,11 @@ function fileLenToString(len: number): string { return `${(len / base).toFixed(2)}${suffix[suffixIndex]}`; } +/** + * Returns an HTTP Response with the requested file as the body + * @param req The server request context used to cleanup the file handle + * @param filePath Path of the file to serve + */ export async function serveFile( req: ServerRequest, filePath: string, diff --git a/std/testing/_diff.ts b/std/testing/_diff.ts index 5c84e891f..e6f631002 100644 --- a/std/testing/_diff.ts +++ b/std/testing/_diff.ts @@ -36,6 +36,11 @@ function createCommon<T>(A: T[], B: T[], reverse?: boolean): T[] { return common; } +/** + * Renders the differences between the actual and expected values + * @param A Actual value + * @param B Expected value + */ export function diff<T>(A: T[], B: T[]): Array<DiffResult<T>> { const prefixCommon = createCommon(A, B); const suffixCommon = createCommon( diff --git a/std/testing/asserts.ts b/std/testing/asserts.ts index eefa8c4f4..8548fb700 100644 --- a/std/testing/asserts.ts +++ b/std/testing/asserts.ts @@ -19,6 +19,11 @@ export class AssertionError extends Error { } } +/** + * Converts the input into a string. Objects, Sets and Maps are sorted so as to + * make tests less flaky + * @param v Value to be formatted + */ export function _format(v: unknown): string { return globalThis.Deno ? Deno.inspect(v, { @@ -31,6 +36,10 @@ export function _format(v: unknown): string { : `"${String(v).replace(/(?=["\\])/g, "\\")}"`; } +/** + * Colors the output of assertion diffs + * @param diffType Difference type, either added or removed + */ function createColor(diffType: DiffType): (s: string) => string { switch (diffType) { case DiffType.added: @@ -42,6 +51,10 @@ function createColor(diffType: DiffType): (s: string) => string { } } +/** + * Prefixes `+` or `-` in diff output + * @param diffType Difference type, either added or removed + */ function createSign(diffType: DiffType): string { switch (diffType) { case DiffType.added: @@ -77,6 +90,11 @@ function isKeyedCollection(x: unknown): x is Set<unknown> { return [Symbol.iterator, "size"].every((k) => k in (x as Set<unknown>)); } +/** + * Deep equality comparison used in assertions + * @param c actual value + * @param d expected value + */ export function equal(c: unknown, d: unknown): boolean { const seen = new Map(); return (function compare(a: unknown, b: unknown): boolean { |