summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
Diffstat (limited to 'testing')
-rw-r--r--testing/README.md68
-rw-r--r--testing/asserts.ts2
-rw-r--r--testing/asserts_test.ts22
-rw-r--r--testing/bench.ts4
-rw-r--r--testing/bench_example.ts6
-rw-r--r--testing/bench_test.ts24
-rw-r--r--testing/diff.ts26
-rw-r--r--testing/diff_test.ts20
-rw-r--r--testing/format.ts12
-rw-r--r--testing/format_test.ts146
-rw-r--r--testing/mod.ts4
-rw-r--r--testing/pretty.ts14
-rw-r--r--testing/pretty_test.ts18
-rw-r--r--testing/test.ts114
-rw-r--r--testing/testing_bench.ts4
15 files changed, 261 insertions, 223 deletions
diff --git a/testing/README.md b/testing/README.md
index 271ff75e6..0445e344f 100644
--- a/testing/README.md
+++ b/testing/README.md
@@ -50,7 +50,7 @@ import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
test({
name: "testing example",
- fn() {
+ fn(): void {
assertEquals("world", "world");
assertEquals({ hello: "world" }, { hello: "world" });
}
@@ -62,7 +62,7 @@ runTests();
Short syntax (named function instead of object):
```ts
-test(function example() {
+test(function example(): void {
assertEquals("world", "world");
assertEquals({ hello: "world" }, { hello: "world" });
});
@@ -71,14 +71,14 @@ test(function example() {
Using `assertStrictEq()`:
```ts
-test(function isStrictlyEqual() {
+test(function isStrictlyEqual(): void {
const a = {};
const b = a;
assertStrictEq(a, b);
});
// This test fails
-test(function isNotStrictlyEqual() {
+test(function isNotStrictlyEqual(): void {
const a = {};
const b = {};
assertStrictEq(a, b);
@@ -88,15 +88,17 @@ test(function isNotStrictlyEqual() {
Using `assertThrows()`:
```ts
-test(function doesThrow() {
- assertThrows(() => {
- throw new TypeError("hello world!");
- });
- assertThrows(() => {
+test(function doesThrow(): void {
+ assertThrows(
+ (): void => {
+ throw new TypeError("hello world!");
+ }
+ );
+ assertThrows((): void => {
throw new TypeError("hello world!");
}, TypeError);
assertThrows(
- () => {
+ (): void => {
throw new TypeError("hello world!");
},
TypeError,
@@ -105,40 +107,48 @@ test(function doesThrow() {
});
// This test will not pass
-test(function fails() {
- assertThrows(() => {
- console.log("Hello world");
- });
+test(function fails(): void {
+ assertThrows(
+ (): void => {
+ console.log("Hello world");
+ }
+ );
});
```
Using `assertThrowsAsync()`:
```ts
-test(async function doesThrow() {
- await assertThrowsAsync(async () => {
- throw new TypeError("hello world!");
- });
- await assertThrowsAsync(async () => {
+test(async function doesThrow(): Promise<void> {
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ throw new TypeError("hello world!");
+ }
+ );
+ await assertThrowsAsync(async (): Promise<void> => {
throw new TypeError("hello world!");
}, TypeError);
await assertThrowsAsync(
- async () => {
+ async (): Promise<void> => {
throw new TypeError("hello world!");
},
TypeError,
"hello"
);
- await assertThrowsAsync(async () => {
- return Promise.reject(new Error());
- });
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ return Promise.reject(new Error());
+ }
+ );
});
// This test will not pass
-test(async function fails() {
- await assertThrowsAsync(async () => {
- console.log("Hello world");
- });
+test(async function fails(): Promise<void> {
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ console.log("Hello world");
+ }
+ );
});
```
@@ -149,7 +159,7 @@ Basic usage:
```ts
import { runBenchmarks, bench } from "https://deno.land/std/testing/bench.ts";
-bench(function forIncrementX1e9(b) {
+bench(function forIncrementX1e9(b): void {
b.start();
for (let i = 0; i < 1e9; i++);
b.stop();
@@ -164,7 +174,7 @@ Averaging execution time over multiple runs:
bench({
name: "runs100ForIncrementX1e6",
runs: 100,
- func(b) {
+ func(b): void {
b.start();
for (let i = 0; i < 1e6; i++);
b.stop();
diff --git a/testing/asserts.ts b/testing/asserts.ts
index 83fa7c8e5..a2583c22a 100644
--- a/testing/asserts.ts
+++ b/testing/asserts.ts
@@ -15,7 +15,7 @@ export class AssertionError extends Error {
export function equal(c: unknown, d: unknown): boolean {
const seen = new Map();
- return (function compare(a: unknown, b: unknown) {
+ return (function compare(a: unknown, b: unknown): boolean {
if (a && a instanceof Set && b && b instanceof Set) {
if (a.size !== b.size) {
return false;
diff --git a/testing/asserts_test.ts b/testing/asserts_test.ts
index ed58d74df..e4f05f166 100644
--- a/testing/asserts_test.ts
+++ b/testing/asserts_test.ts
@@ -16,7 +16,7 @@ import {
} from "./asserts.ts";
import { test } from "./mod.ts";
-test(function testingEqual() {
+test(function testingEqual(): void {
assert(equal("world", "world"));
assert(!equal("hello", "world"));
assert(equal(5, 5));
@@ -48,7 +48,7 @@ test(function testingEqual() {
assert(equal(new Set("denosaurus"), new Set("denosaurussss")));
});
-test(function testingNotEquals() {
+test(function testingNotEquals(): void {
const a = { foo: "bar" };
const b = { bar: "foo" };
assertNotEquals(a, b);
@@ -64,7 +64,7 @@ test(function testingNotEquals() {
assertEquals(didThrow, true);
});
-test(function testingAssertStringContains() {
+test(function testingAssertStringContains(): void {
assertStrContains("Denosaurus", "saur");
assertStrContains("Denosaurus", "Deno");
assertStrContains("Denosaurus", "rus");
@@ -79,7 +79,7 @@ test(function testingAssertStringContains() {
assertEquals(didThrow, true);
});
-test(function testingArrayContains() {
+test(function testingArrayContains(): void {
const fixture = ["deno", "iz", "luv"];
const fixtureObject = [{ deno: "luv" }, { deno: "Js" }];
assertArrayContains(fixture, ["deno"]);
@@ -95,7 +95,7 @@ test(function testingArrayContains() {
assertEquals(didThrow, true);
});
-test(function testingAssertStringContainsThrow() {
+test(function testingAssertStringContainsThrow(): void {
let didThrow = false;
try {
assertStrContains("Denosaurus from Jurassic", "Raptor");
@@ -110,11 +110,11 @@ test(function testingAssertStringContainsThrow() {
assert(didThrow);
});
-test(function testingAssertStringMatching() {
+test(function testingAssertStringMatching(): void {
assertMatch("foobar@deno.com", RegExp(/[a-zA-Z]+@[a-zA-Z]+.com/));
});
-test(function testingAssertStringMatchingThrows() {
+test(function testingAssertStringMatchingThrows(): void {
let didThrow = false;
try {
assertMatch("Denosaurus from Jurassic", RegExp(/Raptor/));
@@ -129,7 +129,7 @@ test(function testingAssertStringMatchingThrows() {
assert(didThrow);
});
-test(function testingAssertsUnimplemented() {
+test(function testingAssertsUnimplemented(): void {
let didThrow = false;
try {
unimplemented();
@@ -141,7 +141,7 @@ test(function testingAssertsUnimplemented() {
assert(didThrow);
});
-test(function testingAssertsUnreachable() {
+test(function testingAssertsUnreachable(): void {
let didThrow = false;
try {
unreachable();
@@ -153,10 +153,10 @@ test(function testingAssertsUnreachable() {
assert(didThrow);
});
-test(function testingAssertFail() {
+test(function testingAssertFail(): void {
assertThrows(fail, AssertionError, "Failed assertion.");
assertThrows(
- () => {
+ (): void => {
fail("foo");
},
AssertionError,
diff --git a/testing/bench.ts b/testing/bench.ts
index 0094f6292..5b396df0e 100644
--- a/testing/bench.ts
+++ b/testing/bench.ts
@@ -96,7 +96,7 @@ export async function runBenchmarks({
}: BenchmarkRunOptions = {}): Promise<void> {
// Filtering candidates by the "only" and "skip" constraint
const benchmarks: BenchmarkDefinition[] = candidates.filter(
- ({ name }) => only.test(name) && !skip.test(name)
+ ({ name }): boolean => only.test(name) && !skip.test(name)
);
// Init main counters and error flag
const filtered = candidates.length - benchmarks.length;
@@ -164,7 +164,7 @@ export async function runBenchmarks({
);
// Making sure the program exit code is not zero in case of failure
if (failed) {
- setTimeout(() => exit(1), 0);
+ setTimeout((): void => exit(1), 0);
}
}
diff --git a/testing/bench_example.ts b/testing/bench_example.ts
index 86e25b9a6..d27fb97e8 100644
--- a/testing/bench_example.ts
+++ b/testing/bench_example.ts
@@ -2,7 +2,7 @@
import { BenchmarkTimer, bench, runIfMain } from "./bench.ts";
// Basic
-bench(function forIncrementX1e9(b: BenchmarkTimer) {
+bench(function forIncrementX1e9(b: BenchmarkTimer): void {
b.start();
for (let i = 0; i < 1e9; i++);
b.stop();
@@ -12,7 +12,7 @@ bench(function forIncrementX1e9(b: BenchmarkTimer) {
bench({
name: "runs100ForIncrementX1e6",
runs: 100,
- func(b) {
+ func(b): void {
b.start();
for (let i = 0; i < 1e6; i++);
b.stop();
@@ -20,7 +20,7 @@ bench({
});
// Itsabug
-bench(function throwing(b) {
+bench(function throwing(b): void {
b.start();
// Throws bc the timer's stop method is never called
});
diff --git a/testing/bench_test.ts b/testing/bench_test.ts
index 8042db480..1c6459bbb 100644
--- a/testing/bench_test.ts
+++ b/testing/bench_test.ts
@@ -3,20 +3,20 @@ import { bench, runBenchmarks } from "./bench.ts";
import "./bench_example.ts";
-test(async function benching() {
- bench(function forIncrementX1e9(b) {
+test(async function benching(): Promise<void> {
+ bench(function forIncrementX1e9(b): void {
b.start();
for (let i = 0; i < 1e9; i++);
b.stop();
});
- bench(function forDecrementX1e9(b) {
+ bench(function forDecrementX1e9(b): void {
b.start();
for (let i = 1e9; i > 0; i--);
b.stop();
});
- bench(async function forAwaitFetchDenolandX10(b) {
+ bench(async function forAwaitFetchDenolandX10(b): Promise<void> {
b.start();
for (let i = 0; i < 10; i++) {
let r = await fetch("https://deno.land/");
@@ -25,14 +25,16 @@ test(async function benching() {
b.stop();
});
- bench(async function promiseAllFetchDenolandX10(b) {
+ bench(async function promiseAllFetchDenolandX10(b): Promise<void> {
const urls = new Array(10).fill("https://deno.land/");
b.start();
await Promise.all(
- urls.map(async (denoland: string) => {
- let r = await fetch(denoland);
- await r.text();
- })
+ urls.map(
+ async (denoland: string): Promise<void> => {
+ let r = await fetch(denoland);
+ await r.text();
+ }
+ )
);
b.stop();
});
@@ -40,14 +42,14 @@ test(async function benching() {
bench({
name: "runs100ForIncrementX1e6",
runs: 100,
- func(b) {
+ func(b): void {
b.start();
for (let i = 0; i < 1e6; i++);
b.stop();
}
});
- bench(function throwing(b) {
+ bench(function throwing(b): void {
b.start();
// Throws bc the timer's stop method is never called
});
diff --git a/testing/diff.ts b/testing/diff.ts
index e951032f5..4c96b3b28 100644
--- a/testing/diff.ts
+++ b/testing/diff.ts
@@ -54,12 +54,18 @@ export default function diff<T>(A: T[], B: T[]): Array<DiffResult<T>> {
if (!M && !N && !suffixCommon.length && !prefixCommon.length) return [];
if (!N) {
return [
- ...prefixCommon.map(c => ({ type: DiffType.common, value: c })),
- ...A.map(a => ({
- type: swapped ? DiffType.added : DiffType.removed,
- value: a
- })),
- ...suffixCommon.map(c => ({ type: DiffType.common, value: c }))
+ ...prefixCommon.map(
+ (c): DiffResult<typeof c> => ({ type: DiffType.common, value: c })
+ ),
+ ...A.map(
+ (a): DiffResult<typeof a> => ({
+ type: swapped ? DiffType.added : DiffType.removed,
+ value: a
+ })
+ ),
+ ...suffixCommon.map(
+ (c): DiffResult<typeof c> => ({ type: DiffType.common, value: c })
+ )
];
}
const offset = N;
@@ -198,8 +204,12 @@ export default function diff<T>(A: T[], B: T[]): Array<DiffResult<T>> {
);
}
return [
- ...prefixCommon.map(c => ({ type: DiffType.common, value: c })),
+ ...prefixCommon.map(
+ (c): DiffResult<typeof c> => ({ type: DiffType.common, value: c })
+ ),
...backTrace(A, B, fp[delta + offset], swapped),
- ...suffixCommon.map(c => ({ type: DiffType.common, value: c }))
+ ...suffixCommon.map(
+ (c): DiffResult<typeof c> => ({ type: DiffType.common, value: c })
+ )
];
}
diff --git a/testing/diff_test.ts b/testing/diff_test.ts
index e62f45248..d9fbdb956 100644
--- a/testing/diff_test.ts
+++ b/testing/diff_test.ts
@@ -4,14 +4,14 @@ import { test } from "./mod.ts";
test({
name: "empty",
- fn() {
+ fn(): void {
assertEquals(diff([], []), []);
}
});
test({
name: '"a" vs "b"',
- fn() {
+ fn(): void {
assertEquals(diff(["a"], ["b"]), [
{ type: "removed", value: "a" },
{ type: "added", value: "b" }
@@ -21,28 +21,28 @@ test({
test({
name: '"a" vs "a"',
- fn() {
+ fn(): void {
assertEquals(diff(["a"], ["a"]), [{ type: "common", value: "a" }]);
}
});
test({
name: '"a" vs ""',
- fn() {
+ fn(): void {
assertEquals(diff(["a"], []), [{ type: "removed", value: "a" }]);
}
});
test({
name: '"" vs "a"',
- fn() {
+ fn(): void {
assertEquals(diff([], ["a"]), [{ type: "added", value: "a" }]);
}
});
test({
name: '"a" vs "a, b"',
- fn() {
+ fn(): void {
assertEquals(diff(["a"], ["a", "b"]), [
{ type: "common", value: "a" },
{ type: "added", value: "b" }
@@ -52,7 +52,7 @@ test({
test({
name: '"strength" vs "string"',
- fn() {
+ fn(): void {
assertEquals(diff(Array.from("strength"), Array.from("string")), [
{ type: "common", value: "s" },
{ type: "common", value: "t" },
@@ -69,7 +69,7 @@ test({
test({
name: '"strength" vs ""',
- fn() {
+ fn(): void {
assertEquals(diff(Array.from("strength"), Array.from("")), [
{ type: "removed", value: "s" },
{ type: "removed", value: "t" },
@@ -85,7 +85,7 @@ test({
test({
name: '"" vs "strength"',
- fn() {
+ fn(): void {
assertEquals(diff(Array.from(""), Array.from("strength")), [
{ type: "added", value: "s" },
{ type: "added", value: "t" },
@@ -101,7 +101,7 @@ test({
test({
name: '"abc", "c" vs "abc", "bcd", "c"',
- fn() {
+ fn(): void {
assertEquals(diff(["abc", "c"], ["abc", "bcd", "c"]), [
{ type: "common", value: "abc" },
{ type: "added", value: "bcd" },
diff --git a/testing/format.ts b/testing/format.ts
index 9a8b02ac6..8ed066eb0 100644
--- a/testing/format.ts
+++ b/testing/format.ts
@@ -358,11 +358,13 @@ const getKeysOfEnumerableProperties = (object: {}): Array<string | symbol> => {
const keys: Array<string | symbol> = Object.keys(object).sort();
if (Object.getOwnPropertySymbols) {
- Object.getOwnPropertySymbols(object).forEach(symbol => {
- if (Object.getOwnPropertyDescriptor(object, symbol)!.enumerable) {
- keys.push(symbol);
+ Object.getOwnPropertySymbols(object).forEach(
+ (symbol): void => {
+ if (Object.getOwnPropertyDescriptor(object, symbol)!.enumerable) {
+ keys.push(symbol);
+ }
}
- });
+ );
}
return keys;
@@ -524,7 +526,7 @@ const getConfig = (options: Options): Config => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function format(val: any, options: Optional<Options> = {}): string {
const opts = Object.keys(DEFAULT_OPTIONS).reduce(
- (acc: Options, k: keyof Options) => {
+ (acc: Options, k: keyof Options): unknown => {
const opt = options[k];
if (typeof opt === "undefined") {
return { ...acc, [k]: DEFAULT_OPTIONS[k] };
diff --git a/testing/format_test.ts b/testing/format_test.ts
index fe6d946ef..0601a5db2 100644
--- a/testing/format_test.ts
+++ b/testing/format_test.ts
@@ -53,7 +53,7 @@ const createExpected = () =>
test({
name: "prints empty arguments",
- fn() {
+ fn(): void {
const val = returnArguments();
assertEquals(format(val), "Arguments []");
}
@@ -61,7 +61,7 @@ test({
test({
name: "prints an empty array",
- fn() {
+ fn(): void {
const val: unknown[] = [];
assertEquals(format(val), "Array []");
}
@@ -69,7 +69,7 @@ test({
test({
name: "prints an array with items",
- fn() {
+ fn(): void {
const val = [1, 2, 3];
assertEquals(format(val), "Array [\n 1,\n 2,\n 3,\n]");
}
@@ -77,7 +77,7 @@ test({
test({
name: "prints a empty typed array",
- fn() {
+ fn(): void {
const val = new Uint32Array(0);
assertEquals(format(val), "Uint32Array []");
}
@@ -85,7 +85,7 @@ test({
test({
name: "prints a typed array with items",
- fn() {
+ fn(): void {
const val = new Uint32Array(3);
assertEquals(format(val), "Uint32Array [\n 0,\n 0,\n 0,\n]");
}
@@ -93,7 +93,7 @@ test({
test({
name: "prints an array buffer",
- fn() {
+ fn(): void {
const val = new ArrayBuffer(3);
assertEquals(format(val), "ArrayBuffer []");
}
@@ -101,7 +101,7 @@ test({
test({
name: "prints a nested array",
- fn() {
+ fn(): void {
const val = [[1, 2, 3]];
assertEquals(
format(val),
@@ -112,7 +112,7 @@ test({
test({
name: "prints true",
- fn() {
+ fn(): void {
const val = true;
assertEquals(format(val), "true");
}
@@ -120,7 +120,7 @@ test({
test({
name: "prints false",
- fn() {
+ fn(): void {
const val = false;
assertEquals(format(val), "false");
}
@@ -128,7 +128,7 @@ test({
test({
name: "prints an error",
- fn() {
+ fn(): void {
const val = new Error();
assertEquals(format(val), "[Error]");
}
@@ -136,7 +136,7 @@ test({
test({
name: "prints a typed error with a message",
- fn() {
+ fn(): void {
const val = new TypeError("message");
assertEquals(format(val), "[TypeError: message]");
}
@@ -144,7 +144,7 @@ test({
test({
name: "prints a function constructor",
- fn() {
+ fn(): void {
// tslint:disable-next-line:function-constructor
const val = new Function();
assertEquals(format(val), "[Function anonymous]");
@@ -153,20 +153,20 @@ test({
test({
name: "prints an anonymous callback function",
- fn() {
+ fn(): void {
let val;
function f(cb: () => void): void {
val = cb;
}
// tslint:disable-next-line:no-empty
- f(() => {});
+ f((): void => {});
assertEquals(format(val), "[Function anonymous]");
}
});
test({
name: "prints an anonymous assigned function",
- fn() {
+ fn(): void {
// tslint:disable-next-line:no-empty
const val = (): void => {};
const formatted = format(val);
@@ -179,7 +179,7 @@ test({
test({
name: "prints a named function",
- fn() {
+ fn(): void {
// tslint:disable-next-line:no-empty
const val = function named(): void {};
assertEquals(format(val), "[Function named]");
@@ -188,7 +188,7 @@ test({
test({
name: "prints a named generator function",
- fn() {
+ fn(): void {
const val = function* generate(): IterableIterator<number> {
yield 1;
yield 2;
@@ -200,7 +200,7 @@ test({
test({
name: "can customize function names",
- fn() {
+ fn(): void {
// tslint:disable-next-line:no-empty
const val = function named(): void {};
assertEquals(
@@ -214,7 +214,7 @@ test({
test({
name: "prints Infinity",
- fn() {
+ fn(): void {
const val = Infinity;
assertEquals(format(val), "Infinity");
}
@@ -222,7 +222,7 @@ test({
test({
name: "prints -Infinity",
- fn() {
+ fn(): void {
const val = -Infinity;
assertEquals(format(val), "-Infinity");
}
@@ -230,7 +230,7 @@ test({
test({
name: "prints an empty map",
- fn() {
+ fn(): void {
const val = new Map();
assertEquals(format(val), "Map {}");
}
@@ -238,7 +238,7 @@ test({
test({
name: "prints a map with values",
- fn() {
+ fn(): void {
const val = new Map();
val.set("prop1", "value1");
val.set("prop2", "value2");
@@ -251,7 +251,7 @@ test({
test({
name: "prints a map with non-string keys",
- fn() {
+ fn(): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const val = new Map<any, any>([
[false, "boolean"],
@@ -294,7 +294,7 @@ test({
test({
name: "prints NaN",
- fn() {
+ fn(): void {
const val = NaN;
assertEquals(format(val), "NaN");
}
@@ -302,7 +302,7 @@ test({
test({
name: "prints null",
- fn() {
+ fn(): void {
const val = null;
assertEquals(format(val), "null");
}
@@ -310,7 +310,7 @@ test({
test({
name: "prints a positive number",
- fn() {
+ fn(): void {
const val = 123;
assertEquals(format(val), "123");
}
@@ -318,7 +318,7 @@ test({
test({
name: "prints a negative number",
- fn() {
+ fn(): void {
const val = -123;
assertEquals(format(val), "-123");
}
@@ -326,7 +326,7 @@ test({
test({
name: "prints zero",
- fn() {
+ fn(): void {
const val = 0;
assertEquals(format(val), "0");
}
@@ -334,7 +334,7 @@ test({
test({
name: "prints negative zero",
- fn() {
+ fn(): void {
const val = -0;
assertEquals(format(val), "-0");
}
@@ -342,7 +342,7 @@ test({
test({
name: "prints a date",
- fn() {
+ fn(): void {
const val = new Date(10e11);
assertEquals(format(val), "2001-09-09T01:46:40.000Z");
}
@@ -350,7 +350,7 @@ test({
test({
name: "prints an invalid date",
- fn() {
+ fn(): void {
const val = new Date(Infinity);
assertEquals(format(val), "Date { NaN }");
}
@@ -358,7 +358,7 @@ test({
test({
name: "prints an empty object",
- fn() {
+ fn(): void {
const val = {};
assertEquals(format(val), "Object {}");
}
@@ -366,7 +366,7 @@ test({
test({
name: "prints an object with properties",
- fn() {
+ fn(): void {
const val = { prop1: "value1", prop2: "value2" };
assertEquals(
format(val),
@@ -377,7 +377,7 @@ test({
test({
name: "prints an object with properties and symbols",
- fn() {
+ fn(): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const val: any = {};
val[Symbol("symbol1")] = "value2";
@@ -393,7 +393,7 @@ test({
test({
name:
"prints an object without non-enumerable properties which have string key",
- fn() {
+ fn(): void {
const val = {
enumerable: true
};
@@ -409,7 +409,7 @@ test({
test({
name:
"prints an object without non-enumerable properties which have symbol key",
- fn() {
+ fn(): void {
const val = {
enumerable: true
};
@@ -424,7 +424,7 @@ test({
test({
name: "prints an object with sorted properties",
- fn() {
+ fn(): void {
const val = { b: 1, a: 2 };
assertEquals(format(val), 'Object {\n "a": 2,\n "b": 1,\n}');
}
@@ -432,7 +432,7 @@ test({
test({
name: "prints regular expressions from constructors",
- fn() {
+ fn(): void {
const val = new RegExp("regexp");
assertEquals(format(val), "/regexp/");
}
@@ -440,7 +440,7 @@ test({
test({
name: "prints regular expressions from literals",
- fn() {
+ fn(): void {
const val = /regexp/gi;
assertEquals(format(val), "/regexp/gi");
}
@@ -448,7 +448,7 @@ test({
test({
name: "prints regular expressions {escapeRegex: false}",
- fn() {
+ fn(): void {
const val = /regexp\d/gi;
assertEquals(format(val), "/regexp\\d/gi");
}
@@ -456,7 +456,7 @@ test({
test({
name: "prints regular expressions {escapeRegex: true}",
- fn() {
+ fn(): void {
const val = /regexp\d/gi;
assertEquals(format(val, { escapeRegex: true }), "/regexp\\\\d/gi");
}
@@ -464,7 +464,7 @@ test({
test({
name: "escapes regular expressions nested inside object",
- fn() {
+ fn(): void {
const obj = { test: /regexp\d/gi };
assertEquals(
format(obj, { escapeRegex: true }),
@@ -475,7 +475,7 @@ test({
test({
name: "prints an empty set",
- fn() {
+ fn(): void {
const val = new Set();
assertEquals(format(val), "Set {}");
}
@@ -483,7 +483,7 @@ test({
test({
name: "prints a set with values",
- fn() {
+ fn(): void {
const val = new Set();
val.add("value1");
val.add("value2");
@@ -493,7 +493,7 @@ test({
test({
name: "prints a string",
- fn() {
+ fn(): void {
const val = "string";
assertEquals(format(val), '"string"');
}
@@ -501,7 +501,7 @@ test({
test({
name: "prints and escape a string",
- fn() {
+ fn(): void {
const val = "\"'\\";
assertEquals(format(val), '"\\"\'\\\\"');
}
@@ -509,7 +509,7 @@ test({
test({
name: "doesn't escape string with {excapeString: false}",
- fn() {
+ fn(): void {
const val = "\"'\\n";
assertEquals(format(val, { escapeString: false }), '""\'\\n"');
}
@@ -517,7 +517,7 @@ test({
test({
name: "prints a string with escapes",
- fn() {
+ fn(): void {
assertEquals(format('"-"'), '"\\"-\\""');
assertEquals(format("\\ \\\\"), '"\\\\ \\\\\\\\"');
}
@@ -525,7 +525,7 @@ test({
test({
name: "prints a multiline string",
- fn() {
+ fn(): void {
const val = ["line 1", "line 2", "line 3"].join("\n");
assertEquals(format(val), '"' + val + '"');
}
@@ -533,7 +533,7 @@ test({
test({
name: "prints a multiline string as value of object property",
- fn() {
+ fn(): void {
const polyline = {
props: {
id: "J",
@@ -571,7 +571,7 @@ test({
test({
name: "prints a symbol",
- fn() {
+ fn(): void {
const val = Symbol("symbol");
assertEquals(format(val), "Symbol(symbol)");
}
@@ -579,7 +579,7 @@ test({
test({
name: "prints undefined",
- fn() {
+ fn(): void {
const val = undefined;
assertEquals(format(val), "undefined");
}
@@ -587,7 +587,7 @@ test({
test({
name: "prints a WeakMap",
- fn() {
+ fn(): void {
const val = new WeakMap();
assertEquals(format(val), "WeakMap {}");
}
@@ -595,7 +595,7 @@ test({
test({
name: "prints a WeakSet",
- fn() {
+ fn(): void {
const val = new WeakSet();
assertEquals(format(val), "WeakSet {}");
}
@@ -603,7 +603,7 @@ test({
test({
name: "prints deeply nested objects",
- fn() {
+ fn(): void {
const val = { prop: { prop: { prop: "value" } } };
assertEquals(
format(val),
@@ -614,7 +614,7 @@ test({
test({
name: "prints circular references",
- fn() {
+ fn(): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const val: any = {};
val.prop = val;
@@ -624,7 +624,7 @@ test({
test({
name: "prints parallel references",
- fn() {
+ fn(): void {
const inner = {};
const val = { prop1: inner, prop2: inner };
assertEquals(
@@ -636,14 +636,14 @@ test({
test({
name: "default implicit: 2 spaces",
- fn() {
+ fn(): void {
assertEquals(format(createVal()), createExpected());
}
});
test({
name: "default explicit: 2 spaces",
- fn() {
+ fn(): void {
assertEquals(format(createVal(), { indent: 2 }), createExpected());
}
});
@@ -651,7 +651,7 @@ test({
// Tests assume that no strings in val contain multiple adjacent spaces!
test({
name: "non-default: 0 spaces",
- fn() {
+ fn(): void {
const indent = 0;
assertEquals(
format(createVal(), { indent }),
@@ -662,7 +662,7 @@ test({
test({
name: "non-default: 4 spaces",
- fn() {
+ fn(): void {
const indent = 4;
assertEquals(
format(createVal(), { indent }),
@@ -673,7 +673,7 @@ test({
test({
name: "can customize the max depth",
- fn() {
+ fn(): void {
const v = [
{
"arguments empty": returnArguments(),
@@ -719,14 +719,14 @@ test({
test({
name: "prints objects with no constructor",
- fn() {
+ fn(): void {
assertEquals(format(Object.create(null)), "Object {}");
}
});
test({
name: "prints identity-obj-proxy with string constructor",
- fn() {
+ fn(): void {
const obj = Object.create(null);
obj.constructor = "constructor";
const expected = [
@@ -740,10 +740,10 @@ test({
test({
name: "calls toJSON and prints its return value",
- fn() {
+ fn(): void {
assertEquals(
format({
- toJSON: () => ({ value: false }),
+ toJSON: (): unknown => ({ value: false }),
value: true
}),
'Object {\n "value": false,\n}'
@@ -753,10 +753,10 @@ test({
test({
name: "calls toJSON and prints an internal representation.",
- fn() {
+ fn(): void {
assertEquals(
format({
- toJSON: () => "[Internal Object]",
+ toJSON: (): string => "[Internal Object]",
value: true
}),
'"[Internal Object]"'
@@ -766,7 +766,7 @@ test({
test({
name: "calls toJSON only on functions",
- fn() {
+ fn(): void {
assertEquals(
format({
toJSON: false,
@@ -779,10 +779,10 @@ test({
test({
name: "does not call toJSON recursively",
- fn() {
+ fn(): void {
assertEquals(
format({
- toJSON: () => ({ toJSON: () => ({ value: true }) }),
+ toJSON: (): unknown => ({ toJSON: (): unknown => ({ value: true }) }),
value: false
}),
'Object {\n "toJSON": [Function toJSON],\n}'
@@ -792,10 +792,10 @@ test({
test({
name: "calls toJSON on Sets",
- fn() {
+ fn(): void {
const set = new Set([1]);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
- (set as any).toJSON = () => "map";
+ (set as any).toJSON = (): string => "map";
assertEquals(format(set), '"map"');
}
});
diff --git a/testing/mod.ts b/testing/mod.ts
index 71f27db20..fab8145e8 100644
--- a/testing/mod.ts
+++ b/testing/mod.ts
@@ -212,7 +212,7 @@ export async function runTests({
skip = /^\s*$/
}: RunOptions = {}): Promise<void> {
const tests: TestDefinition[] = candidates.filter(
- ({ name }) => only.test(name) && !skip.test(name)
+ ({ name }): boolean => only.test(name) && !skip.test(name)
);
const stats: TestStats = {
measured: 0,
@@ -232,7 +232,7 @@ export async function runTests({
if (stats.failed) {
// Use setTimeout to avoid the error being ignored due to unhandled
// promise rejections being swallowed.
- setTimeout(() => {
+ setTimeout((): void => {
console.error(`There were ${stats.failed} test failures.`);
Deno.exit(1);
}, 0);
diff --git a/testing/pretty.ts b/testing/pretty.ts
index f4794f889..b2ab79d70 100644
--- a/testing/pretty.ts
+++ b/testing/pretty.ts
@@ -18,9 +18,9 @@ function createStr(v: unknown): string {
function createColor(diffType: DiffType): (s: string) => string {
switch (diffType) {
case DiffType.added:
- return (s: string) => green(bold(s));
+ return (s: string): string => green(bold(s));
case DiffType.removed:
- return (s: string) => red(bold(s));
+ return (s: string): string => red(bold(s));
default:
return white;
}
@@ -46,10 +46,12 @@ function buildMessage(diffResult: ReadonlyArray<DiffResult<string>>): string[] {
);
messages.push("");
messages.push("");
- diffResult.forEach((result: DiffResult<string>) => {
- const c = createColor(result.type);
- messages.push(c(`${createSign(result.type)}${result.value}`));
- });
+ diffResult.forEach(
+ (result: DiffResult<string>): void => {
+ const c = createColor(result.type);
+ messages.push(c(`${createSign(result.type)}${result.value}`));
+ }
+ );
messages.push("");
return messages;
diff --git a/testing/pretty_test.ts b/testing/pretty_test.ts
index d0e90f656..07ab83d5e 100644
--- a/testing/pretty_test.ts
+++ b/testing/pretty_test.ts
@@ -18,7 +18,7 @@ const removed: (s: string) => string = (s: string): string => red(bold(s));
test({
name: "pass case",
- fn() {
+ fn(): void {
assertEquals({ a: 10 }, { a: 10 });
assertEquals(true, true);
assertEquals(10, 10);
@@ -29,9 +29,9 @@ test({
test({
name: "failed with number",
- fn() {
+ fn(): void {
assertThrows(
- () => assertEquals(1, 2),
+ (): void => assertEquals(1, 2),
Error,
[...createHeader(), removed(`- 1`), added(`+ 2`), ""].join("\n")
);
@@ -40,9 +40,9 @@ test({
test({
name: "failed with number vs string",
- fn() {
+ fn(): void {
assertThrows(
- () => assertEquals(1, "1"),
+ (): void => assertEquals(1, "1"),
Error,
[...createHeader(), removed(`- 1`), added(`+ "1"`)].join("\n")
);
@@ -51,9 +51,9 @@ test({
test({
name: "failed with array",
- fn() {
+ fn(): void {
assertThrows(
- () => assertEquals([1, "2", 3], ["1", "2", 3]),
+ (): void => assertEquals([1, "2", 3], ["1", "2", 3]),
Error,
[
...createHeader(),
@@ -71,9 +71,9 @@ test({
test({
name: "failed with object",
- fn() {
+ fn(): void {
assertThrows(
- () => assertEquals({ a: 1, b: "2", c: 3 }, { a: 1, b: 2, c: [3] }),
+ (): void => assertEquals({ a: 1, b: "2", c: 3 }, { a: 1, b: 2, c: [3] }),
Error,
[
...createHeader(),
diff --git a/testing/test.ts b/testing/test.ts
index 2359cba2e..8c0644272 100644
--- a/testing/test.ts
+++ b/testing/test.ts
@@ -13,7 +13,7 @@ import "./pretty_test.ts";
import "./asserts_test.ts";
import "./bench_test.ts";
-test(function testingAssertEqualActualUncoercable() {
+test(function testingAssertEqualActualUncoercable(): void {
let didThrow = false;
const a = Object.create(null);
try {
@@ -24,7 +24,7 @@ test(function testingAssertEqualActualUncoercable() {
assert(didThrow);
});
-test(function testingAssertEqualExpectedUncoercable() {
+test(function testingAssertEqualExpectedUncoercable(): void {
let didThrow = false;
const a = Object.create(null);
try {
@@ -35,13 +35,13 @@ test(function testingAssertEqualExpectedUncoercable() {
assert(didThrow);
});
-test(function testingAssertStrictEqual() {
+test(function testingAssertStrictEqual(): void {
const a = {};
const b = a;
assertStrictEq(a, b);
});
-test(function testingAssertNotStrictEqual() {
+test(function testingAssertNotStrictEqual(): void {
let didThrow = false;
const a = {};
const b = {};
@@ -54,23 +54,27 @@ test(function testingAssertNotStrictEqual() {
assert(didThrow);
});
-test(function testingDoesThrow() {
+test(function testingDoesThrow(): void {
let count = 0;
- assertThrows(() => {
- count++;
- throw new Error();
- });
+ assertThrows(
+ (): void => {
+ count++;
+ throw new Error();
+ }
+ );
assert(count === 1);
});
-test(function testingDoesNotThrow() {
+test(function testingDoesNotThrow(): void {
let count = 0;
let didThrow = false;
try {
- assertThrows(() => {
- count++;
- console.log("Hello world");
- });
+ assertThrows(
+ (): void => {
+ count++;
+ console.log("Hello world");
+ }
+ );
} catch (e) {
assert(e.message === "Expected function to throw.");
didThrow = true;
@@ -79,20 +83,20 @@ test(function testingDoesNotThrow() {
assert(didThrow);
});
-test(function testingThrowsErrorType() {
+test(function testingThrowsErrorType(): void {
let count = 0;
- assertThrows(() => {
+ assertThrows((): void => {
count++;
throw new TypeError();
}, TypeError);
assert(count === 1);
});
-test(function testingThrowsNotErrorType() {
+test(function testingThrowsNotErrorType(): void {
let count = 0;
let didThrow = false;
try {
- assertThrows(() => {
+ assertThrows((): void => {
count++;
throw new TypeError();
}, RangeError);
@@ -104,10 +108,10 @@ test(function testingThrowsNotErrorType() {
assert(didThrow);
});
-test(function testingThrowsMsgIncludes() {
+test(function testingThrowsMsgIncludes(): void {
let count = 0;
assertThrows(
- () => {
+ (): void => {
count++;
throw new TypeError("Hello world!");
},
@@ -117,12 +121,12 @@ test(function testingThrowsMsgIncludes() {
assert(count === 1);
});
-test(function testingThrowsMsgNotIncludes() {
+test(function testingThrowsMsgNotIncludes(): void {
let count = 0;
let didThrow = false;
try {
assertThrows(
- () => {
+ (): void => {
count++;
throw new TypeError("Hello world!");
},
@@ -140,32 +144,38 @@ test(function testingThrowsMsgNotIncludes() {
assert(didThrow);
});
-test(async function testingDoesThrowAsync() {
+test(async function testingDoesThrowAsync(): Promise<void> {
let count = 0;
- await assertThrowsAsync(async () => {
- count++;
- throw new Error();
- });
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ count++;
+ throw new Error();
+ }
+ );
assert(count === 1);
});
-test(async function testingDoesReject() {
+test(async function testingDoesReject(): Promise<void> {
let count = 0;
- await assertThrowsAsync(() => {
- count++;
- return Promise.reject(new Error());
- });
+ await assertThrowsAsync(
+ (): Promise<never> => {
+ count++;
+ return Promise.reject(new Error());
+ }
+ );
assert(count === 1);
});
-test(async function testingDoesNotThrowAsync() {
+test(async function testingDoesNotThrowAsync(): Promise<void> {
let count = 0;
let didThrow = false;
try {
- await assertThrowsAsync(async () => {
- count++;
- console.log("Hello world");
- });
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ count++;
+ console.log("Hello world");
+ }
+ );
} catch (e) {
assert(e.message === "Expected function to throw.");
didThrow = true;
@@ -174,15 +184,17 @@ test(async function testingDoesNotThrowAsync() {
assert(didThrow);
});
-test(async function testingDoesNotRejectAsync() {
+test(async function testingDoesNotRejectAsync(): Promise<void> {
let count = 0;
let didThrow = false;
try {
- await assertThrowsAsync(() => {
- count++;
- console.log("Hello world");
- return Promise.resolve();
- });
+ await assertThrowsAsync(
+ (): Promise<void> => {
+ count++;
+ console.log("Hello world");
+ return Promise.resolve();
+ }
+ );
} catch (e) {
assert(e.message === "Expected function to throw.");
didThrow = true;
@@ -191,20 +203,20 @@ test(async function testingDoesNotRejectAsync() {
assert(didThrow);
});
-test(async function testingThrowsAsyncErrorType() {
+test(async function testingThrowsAsyncErrorType(): Promise<void> {
let count = 0;
- await assertThrowsAsync(async () => {
+ await assertThrowsAsync((): Promise<void> => {
count++;
throw new TypeError();
}, TypeError);
assert(count === 1);
});
-test(async function testingThrowsAsyncNotErrorType() {
+test(async function testingThrowsAsyncNotErrorType(): Promise<void> {
let count = 0;
let didThrow = false;
try {
- await assertThrowsAsync(async () => {
+ await assertThrowsAsync(async (): Promise<void> => {
count++;
throw new TypeError();
}, RangeError);
@@ -216,10 +228,10 @@ test(async function testingThrowsAsyncNotErrorType() {
assert(didThrow);
});
-test(async function testingThrowsAsyncMsgIncludes() {
+test(async function testingThrowsAsyncMsgIncludes(): Promise<void> {
let count = 0;
await assertThrowsAsync(
- async () => {
+ async (): Promise<void> => {
count++;
throw new TypeError("Hello world!");
},
@@ -229,12 +241,12 @@ test(async function testingThrowsAsyncMsgIncludes() {
assert(count === 1);
});
-test(async function testingThrowsAsyncMsgNotIncludes() {
+test(async function testingThrowsAsyncMsgNotIncludes(): Promise<void> {
let count = 0;
let didThrow = false;
try {
await assertThrowsAsync(
- async () => {
+ async (): Promise<void> => {
count++;
throw new TypeError("Hello world!");
},
diff --git a/testing/testing_bench.ts b/testing/testing_bench.ts
index 0cc2f233b..9033e3a72 100644
--- a/testing/testing_bench.ts
+++ b/testing/testing_bench.ts
@@ -3,13 +3,13 @@ import { runTests } from "./mod.ts";
import "./asserts_test.ts";
-bench(async function testingSerial(b) {
+bench(async function testingSerial(b): Promise<void> {
b.start();
await runTests();
b.stop();
});
-bench(async function testingParallel(b) {
+bench(async function testingParallel(b): Promise<void> {
b.start();
await runTests({ parallel: true });
b.stop();