summaryrefslogtreecommitdiff
path: root/cli/js/tests
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-03-15 17:58:59 +0100
committerGitHub <noreply@github.com>2020-03-15 17:58:59 +0100
commit70434b5bfba701f9de2221b64ee40262c5370ae0 (patch)
tree9aa3753abf6f2e0f98cd16055cf8819153921ac2 /cli/js/tests
parent620dd9724d4f8568efebb1642b49c653de9424cd (diff)
refactor: change test reporter output (#4371)
This commit changes output of default test reporter to resemble output from Rust test runner; first the name of running test is printed with "...", then after test has run result is printed on the same line. * Split "Deno.TestEvent.Result" into "TestStart" and "TestEnd"; * changes TestReporter interface to support both events; Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
Diffstat (limited to 'cli/js/tests')
-rw-r--r--cli/js/tests/README.md56
-rw-r--r--cli/js/tests/test_util.ts20
-rwxr-xr-xcli/js/tests/unit_test_runner.ts28
3 files changed, 43 insertions, 61 deletions
diff --git a/cli/js/tests/README.md b/cli/js/tests/README.md
index 40c3410e1..7553582d2 100644
--- a/cli/js/tests/README.md
+++ b/cli/js/tests/README.md
@@ -47,48 +47,32 @@ Runner discoveres required permissions combinations by loading
There are three ways to run `unit_test_runner.ts`:
-- run tests matching current process permissions
-
```
-// run tests that don't require any permissions
-target/debug/deno unit_test_runner.ts
-
-// run tests with "net" permission
-target/debug/deno --allow-net unit_test_runner.ts
+# Run all tests. Spawns worker processes for each discovered permission
+# combination:
+target/debug/deno -A cli/js/tests/unit_test_runner.ts --master
-target/debug/deno --allow-net --allow-read unit_test_runner.ts
-```
+# By default all output of worker processes is discarded; for debug purposes
+# the --verbose flag preserves output from the worker
+target/debug/deno -A cli/js/tests/unit_test_runner.ts --master --verbose
-- run all tests - "master" mode, that spawns worker processes for each
- discovered permission combination:
+# Run subset of tests that don't require any permissions
+target/debug/deno cli/js/tests/unit_test_runner.ts
-```
-target/debug/deno -A unit_test_runner.ts --master
-```
+# Run subset tests that require "net" and "read" permissions
+target/debug/deno --allow-net --allow-read cli/js/tests/unit_test_runner.ts
-By default all output of worker processes is discarded; for debug purposes
-`--verbose` flag can be provided to preserve output from worker
+# "worker" mode communicates with parent using TCP socket on provided address;
+# after initial setup drops permissions to specified set. It shouldn't be used
+# directly, only be "master" process.
+target/debug/deno -A cli/js/tests/unit_test_runner.ts --worker --addr=127.0.0.1:4500 --perms=net,write,run
-```
-target/debug/deno -A unit_test_runner.ts --master --verbose
+# Run specific tests
+target/debug/deno --allow-net cli/js/tests/unit_test_runner.ts -- netTcpListenClose
```
-- "worker" mode; communicates with parent using TCP socket on provided address;
- after initial setup drops permissions to specified set. It shouldn't be used
- directly, only be "master" process.
-
-```
-target/debug/deno -A unit_test_runner.ts --worker --addr=127.0.0.1:4500 --perms=net,write,run
-```
-
-### Filtering
-
-Runner supports basic test filtering by name:
-
-```
-target/debug/deno unit_test_runner.ts -- netAccept
-
-target/debug/deno -A unit_test_runner.ts --master -- netAccept
-```
+### Http server
-Filter string must be specified after "--" argument
+`tools/http_server.py` is required to run when one's running unit tests. During
+CI it's spawned automatically, but if you want to run tests manually make sure
+that server is spawned otherwise there'll be cascade of test failures.
diff --git a/cli/js/tests/test_util.ts b/cli/js/tests/test_util.ts
index a904b9412..78147f28c 100644
--- a/cli/js/tests/test_util.ts
+++ b/cli/js/tests/test_util.ts
@@ -92,10 +92,6 @@ export async function registerUnitTests(): Promise<void> {
const processPerms = await getProcessPermissions();
for (const unitTestDefinition of REGISTERED_UNIT_TESTS) {
- if (unitTestDefinition.skip) {
- continue;
- }
-
if (!permissionsMatch(processPerms, unitTestDefinition.perms)) {
continue;
}
@@ -172,10 +168,8 @@ interface UnitTestOptions {
perms?: UnitTestPermissions;
}
-interface UnitTestDefinition {
- name: string;
- fn: Deno.TestFunction;
- skip?: boolean;
+interface UnitTestDefinition extends Deno.TestDefinition {
+ skip: boolean;
perms: Permissions;
}
@@ -210,10 +204,6 @@ export function unitTest(
assert(name, "Missing test function name");
}
- if (options.skip) {
- return;
- }
-
const normalizedPerms = normalizeTestPermissions(options.perms || {});
registerPermCombination(normalizedPerms);
@@ -262,7 +252,11 @@ export class SocketReporter implements Deno.TestReporter {
await this.write(msg);
}
- async result(msg: Deno.TestEventResult): Promise<void> {
+ async testStart(msg: Deno.TestEventTestStart): Promise<void> {
+ await this.write(msg);
+ }
+
+ async testEnd(msg: Deno.TestEventTestEnd): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const serializedMsg: any = { ...msg };
diff --git a/cli/js/tests/unit_test_runner.ts b/cli/js/tests/unit_test_runner.ts
index 3fe66408b..fea6aa8da 100755
--- a/cli/js/tests/unit_test_runner.ts
+++ b/cli/js/tests/unit_test_runner.ts
@@ -17,6 +17,7 @@ interface PermissionSetTestResult {
stats: Deno.TestStats;
permsStr: string;
duration: number;
+ results: Deno.TestResult[];
}
const PERMISSIONS: Deno.PermissionName[] = [
@@ -144,16 +145,17 @@ async function runTestsForPermissionSet(
expectedPassedTests = msg.tests;
await reporter.start(msg);
continue;
- }
-
- if (msg.kind === Deno.TestEvent.Result) {
- await reporter.result(msg);
+ } else if (msg.kind === Deno.TestEvent.TestStart) {
+ await reporter.testStart(msg);
continue;
+ } else if (msg.kind === Deno.TestEvent.TestEnd) {
+ await reporter.testEnd(msg);
+ continue;
+ } else {
+ endEvent = msg;
+ await reporter.end(msg);
+ break;
}
-
- endEvent = msg;
- await reporter.end(msg);
- break;
}
} catch (e) {
hasThrown = true;
@@ -183,14 +185,16 @@ async function runTestsForPermissionSet(
workerProcess.close();
- const passed = expectedPassedTests === endEvent.stats.passed;
+ const passed =
+ expectedPassedTests === endEvent.stats.passed + endEvent.stats.ignored;
return {
perms,
passed,
permsStr: permsFmt,
duration: endEvent.duration,
- stats: endEvent.stats
+ stats: endEvent.stats,
+ results: endEvent.results
};
}
@@ -225,13 +229,13 @@ async function masterRunnerMain(
let testsPassed = true;
for (const testResult of testResults) {
- const { permsStr, stats, duration } = testResult;
+ const { permsStr, stats, duration, results } = testResult;
console.log(`Summary for ${permsStr}`);
await consoleReporter.end({
kind: Deno.TestEvent.End,
stats,
duration,
- results: []
+ results
});
testsPassed = testsPassed && testResult.passed;
}