summaryrefslogtreecommitdiff
path: root/cli/js/tests/unit_test_runner.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-03-10 01:06:47 +0100
committerGitHub <noreply@github.com>2020-03-10 01:06:47 +0100
commit68119e1d7ed23421ccdcba20532ebe9ae3df9f18 (patch)
tree455dd170024112e3388adc27ebebb119b0ecda38 /cli/js/tests/unit_test_runner.ts
parentdad8036766dca3417b79858b9a04d90447f88605 (diff)
reorg: move js runtime tests to cli/js/tests/ (#4250)
All Deno runtime test files were moved to cli/js/tests/ directory. It makes a clear distinction that cli/js/tests/ contains code that is run under Deno runtime as opposed to code in cli/js/ which is used to create bundle and snapshot with "deno_typescript".
Diffstat (limited to 'cli/js/tests/unit_test_runner.ts')
-rwxr-xr-xcli/js/tests/unit_test_runner.ts108
1 files changed, 108 insertions, 0 deletions
diff --git a/cli/js/tests/unit_test_runner.ts b/cli/js/tests/unit_test_runner.ts
new file mode 100755
index 000000000..a5b7c3a48
--- /dev/null
+++ b/cli/js/tests/unit_test_runner.ts
@@ -0,0 +1,108 @@
+#!/usr/bin/env -S deno run --reload --allow-run
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+import "./unit_tests.ts";
+import {
+ permissionCombinations,
+ parseUnitTestOutput,
+ Permissions
+} from "./test_util.ts";
+
+interface TestResult {
+ perms: string;
+ output?: string;
+ result: number;
+}
+
+function permsToCliFlags(perms: Permissions): string[] {
+ return Object.keys(perms)
+ .map(key => {
+ if (!perms[key as keyof Permissions]) return "";
+
+ const cliFlag = key.replace(
+ /\.?([A-Z])/g,
+ (x, y): string => `-${y.toLowerCase()}`
+ );
+ return `--allow-${cliFlag}`;
+ })
+ .filter((e): boolean => e.length > 0);
+}
+
+function fmtPerms(perms: Permissions): string {
+ let fmt = permsToCliFlags(perms).join(" ");
+
+ if (!fmt) {
+ fmt = "<no permissions>";
+ }
+
+ return fmt;
+}
+
+async function main(): Promise<void> {
+ console.log(
+ "Discovered permission combinations for tests:",
+ permissionCombinations.size
+ );
+
+ for (const perms of permissionCombinations.values()) {
+ console.log("\t" + fmtPerms(perms));
+ }
+
+ const testResults = new Set<TestResult>();
+
+ for (const perms of permissionCombinations.values()) {
+ const permsFmt = fmtPerms(perms);
+ console.log(`Running tests for: ${permsFmt}`);
+ const cliPerms = permsToCliFlags(perms);
+ // run subsequent tests using same deno executable
+ const args = [
+ Deno.execPath(),
+ "run",
+ ...cliPerms,
+ "cli/js/tests/unit_tests.ts"
+ ];
+
+ const p = Deno.run({
+ args,
+ stdout: "piped"
+ });
+
+ const { actual, expected, resultOutput } = await parseUnitTestOutput(
+ p.stdout!,
+ true
+ );
+
+ let result = 0;
+
+ if (!actual && !expected) {
+ console.error("Bad cli/js/tests/unit_test.ts output");
+ result = 1;
+ } else if (expected !== actual) {
+ result = 1;
+ }
+
+ testResults.add({
+ perms: permsFmt,
+ output: resultOutput,
+ result
+ });
+ }
+
+ // if any run tests returned non-zero status then whole test
+ // run should fail
+ let testsFailed = false;
+
+ for (const testResult of testResults) {
+ console.log(`Summary for ${testResult.perms}`);
+ console.log(testResult.output + "\n");
+ testsFailed = testsFailed || Boolean(testResult.result);
+ }
+
+ if (testsFailed) {
+ console.error("Unit tests failed");
+ Deno.exit(1);
+ }
+
+ console.log("Unit tests passed");
+}
+
+main();