summaryrefslogtreecommitdiff
path: root/std/testing
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-10-09 17:22:22 -0400
committerRyan Dahl <ry@tinyclouds.org>2019-10-09 17:22:22 -0400
commit93f7f00c956c14620ef031626f124b57397ca867 (patch)
treec5a9f536e79d2c8d2d02897511a9138acaf35394 /std/testing
parent28293acd9c12a94f5d769706291032e844c7b92b (diff)
Run deno_std tests in github actions
Diffstat (limited to 'std/testing')
-rw-r--r--std/testing/README.md42
-rw-r--r--std/testing/asserts.ts10
-rw-r--r--std/testing/format.ts10
-rw-r--r--std/testing/mod.ts38
-rwxr-xr-xstd/testing/runner.ts4
-rw-r--r--std/testing/test.ts20
6 files changed, 73 insertions, 51 deletions
diff --git a/std/testing/README.md b/std/testing/README.md
index 88923c1c9..e2bd90b24 100644
--- a/std/testing/README.md
+++ b/std/testing/README.md
@@ -1,15 +1,16 @@
# Testing
-This module provides a few basic utilities to make testing easier and
-consistent in Deno.
+This module provides a few basic utilities to make testing easier and consistent
+in Deno.
## Usage
The module exports a `test` function which is the test harness in Deno. It
accepts either a function (including async functions) or an object which
contains a `name` property and a `fn` property. When running tests and
-outputting the results, the name of the past function is used, or if the
-object is passed, the `name` property is used to identify the test. If the assertion is false an `AssertionError` will be thrown.
+outputting the results, the name of the past function is used, or if the object
+is passed, the `name` property is used to identify the test. If the assertion is
+false an `AssertionError` will be thrown.
Asserts are exposed in `testing/asserts.ts` module.
@@ -18,13 +19,14 @@ Asserts are exposed in `testing/asserts.ts` module.
- `assert()` - Expects a boolean value, throws if the value is `false`.
- `assertEquals()` - Uses the `equal` comparison and throws if the `actual` and
`expected` are not equal.
-- `assertNotEquals()` - Uses the `equal` comparison and throws if the `actual` and
- `expected` are equal.
-- `assertStrictEq()` - Compares `actual` and `expected` strictly, therefore
- for non-primitives the values must reference the same instance.
+- `assertNotEquals()` - Uses the `equal` comparison and throws if the `actual`
+ and `expected` are equal.
+- `assertStrictEq()` - Compares `actual` and `expected` strictly, therefore for
+ non-primitives the values must reference the same instance.
- `assertStrContains()` - Make an assertion that `actual` contains `expected`.
- `assertMatch()` - Make an assertion that `actual` match RegExp `expected`.
-- `assertArrayContains()` - Make an assertion that `actual` array contains the `expected` values.
+- `assertArrayContains()` - Make an assertion that `actual` array contains the
+ `expected` values.
- `assertThrows()` - Expects the passed `fn` to throw. If `fn` does not throw,
this function does. Also compares any errors thrown to an optional expected
`Error` class and checks that the error `.message` includes an optional
@@ -40,7 +42,8 @@ Asserts are exposed in `testing/asserts.ts` module.
`runTests()` executes the declared tests. It accepts a `RunOptions` parameter:
- parallel : Execute tests in a parallel way.
-- exitOnFail : if one test fails, test will throw an error and stop the tests. If not all tests will be processed.
+- exitOnFail : if one test fails, test will throw an error and stop the tests.
+ If not all tests will be processed.
Basic usage:
@@ -89,9 +92,11 @@ Using `assertThrows()`:
```ts
test(function doesThrow(): void {
- assertThrows((): void => {
- throw new TypeError("hello world!");
- });
+ assertThrows(
+ (): void => {
+ throw new TypeError("hello world!");
+ }
+ );
assertThrows((): void => {
throw new TypeError("hello world!");
}, TypeError);
@@ -106,9 +111,11 @@ test(function doesThrow(): void {
// This test will not pass
test(function fails(): void {
- assertThrows((): void => {
- console.log("Hello world");
- });
+ assertThrows(
+ (): void => {
+ console.log("Hello world");
+ }
+ );
});
```
@@ -187,7 +194,8 @@ Registers a benchmark that will be run once `runBenchmarks` is called.
##### `runBenchmarks(opts?: BenchmarkRunOptions): Promise<void>`
Runs all registered benchmarks serially. Filtering can be applied by setting
-`BenchmarkRunOptions.only` and/or `BenchmarkRunOptions.skip` to regular expressions matching benchmark names.
+`BenchmarkRunOptions.only` and/or `BenchmarkRunOptions.skip` to regular
+expressions matching benchmark names.
##### `runIfMain(meta: ImportMeta, opts?: BenchmarkRunOptions): Promise<void>`
diff --git a/std/testing/asserts.ts b/std/testing/asserts.ts
index 230e2c8d2..0f33bb3d2 100644
--- a/std/testing/asserts.ts
+++ b/std/testing/asserts.ts
@@ -56,10 +56,12 @@ function buildMessage(diffResult: ReadonlyArray<DiffResult<string>>): string[] {
);
messages.push("");
messages.push("");
- diffResult.forEach((result: DiffResult<string>): void => {
- 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/std/testing/format.ts b/std/testing/format.ts
index 953347c27..28937d567 100644
--- a/std/testing/format.ts
+++ b/std/testing/format.ts
@@ -360,11 +360,13 @@ const getKeysOfEnumerableProperties = (object: {}): Array<string | symbol> => {
const keys: Array<string | symbol> = Object.keys(object).sort();
if (Object.getOwnPropertySymbols) {
- Object.getOwnPropertySymbols(object).forEach((symbol): void => {
- 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;
diff --git a/std/testing/mod.ts b/std/testing/mod.ts
index 3b6386d5b..bd7642b81 100644
--- a/std/testing/mod.ts
+++ b/std/testing/mod.ts
@@ -203,12 +203,14 @@ function report(result: TestResult): void {
}
function printFailedSummary(results: TestResults): void {
- results.cases.forEach((v): void => {
- if (!v.ok) {
- console.error(`${RED_BG_FAIL} ${red(v.name)}`);
- console.error(v.error);
+ results.cases.forEach(
+ (v): void => {
+ if (!v.ok) {
+ console.error(`${RED_BG_FAIL} ${red(v.name)}`);
+ console.error(v.error);
+ }
}
- });
+ );
}
function printResults(
@@ -319,12 +321,14 @@ async function runTestsSerial(
print(
GREEN_OK + " " + name + " " + promptTestTime(end - start, true)
);
- results.cases.forEach((v): void => {
- if (v.name === name) {
- v.ok = true;
- v.printed = true;
+ results.cases.forEach(
+ (v): void => {
+ if (v.name === name) {
+ v.ok = true;
+ v.printed = true;
+ }
}
- });
+ );
} catch (err) {
if (disableLog) {
print(CLEAR_LINE, false);
@@ -332,13 +336,15 @@ async function runTestsSerial(
print(`${RED_FAILED} ${name}`);
print(err.stack);
stats.failed++;
- results.cases.forEach((v): void => {
- if (v.name === name) {
- v.error = err;
- v.ok = false;
- v.printed = true;
+ results.cases.forEach(
+ (v): void => {
+ if (v.name === name) {
+ v.error = err;
+ v.ok = false;
+ v.printed = true;
+ }
}
- });
+ );
if (exitOnFail) {
break;
}
diff --git a/std/testing/runner.ts b/std/testing/runner.ts
index a78ed2b3a..11c8f3944 100755
--- a/std/testing/runner.ts
+++ b/std/testing/runner.ts
@@ -205,8 +205,8 @@ async function main(): Promise<void> {
const include =
parsedArgs._.length > 0
- ? (parsedArgs._ as string[]).flatMap((fileGlob: string): string[] =>
- fileGlob.split(",")
+ ? (parsedArgs._ as string[]).flatMap(
+ (fileGlob: string): string[] => fileGlob.split(",")
)
: ["."];
const exclude =
diff --git a/std/testing/test.ts b/std/testing/test.ts
index dd6d772f6..93233f7cc 100644
--- a/std/testing/test.ts
+++ b/std/testing/test.ts
@@ -51,10 +51,12 @@ test(function testingAssertNotStrictEqual(): void {
test(function testingDoesThrow(): void {
let count = 0;
- assertThrows((): void => {
- count++;
- throw new Error();
- });
+ assertThrows(
+ (): void => {
+ count++;
+ throw new Error();
+ }
+ );
assert(count === 1);
});
@@ -62,10 +64,12 @@ test(function testingDoesNotThrow(): void {
let count = 0;
let didThrow = false;
try {
- assertThrows((): void => {
- count++;
- console.log("Hello world");
- });
+ assertThrows(
+ (): void => {
+ count++;
+ console.log("Hello world");
+ }
+ );
} catch (e) {
assert(e.message === "Expected function to throw.");
didThrow = true;