diff options
Diffstat (limited to 'cli/tests/unit')
-rw-r--r-- | cli/tests/unit/test_util.ts | 9 | ||||
-rwxr-xr-x | cli/tests/unit/unit_test_runner.ts | 9 |
2 files changed, 17 insertions, 1 deletions
diff --git a/cli/tests/unit/test_util.ts b/cli/tests/unit/test_util.ts index 660e13511..25da7a638 100644 --- a/cli/tests/unit/test_util.ts +++ b/cli/tests/unit/test_util.ts @@ -1,6 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { assert, assertEquals } from "../../../std/testing/asserts.ts"; +import * as colors from "../../../std/fmt/colors.ts"; +export { colors }; import { resolve } from "../../../std/path/mod.ts"; export { assert, @@ -93,7 +95,9 @@ function registerPermCombination(perms: Permissions): void { export async function registerUnitTests(): Promise<void> { const processPerms = await getProcessPermissions(); - for (const unitTestDefinition of REGISTERED_UNIT_TESTS) { + const onlyTests = REGISTERED_UNIT_TESTS.filter(({ only }) => only); + const unitTests = onlyTests.length > 0 ? onlyTests : REGISTERED_UNIT_TESTS; + for (const unitTestDefinition of unitTests) { if (!permissionsMatch(processPerms, unitTestDefinition.perms)) { continue; } @@ -126,11 +130,13 @@ interface UnitTestPermissions { interface UnitTestOptions { ignore?: boolean; + only?: boolean; perms?: UnitTestPermissions; } interface UnitTestDefinition extends Deno.TestDefinition { ignore: boolean; + only: boolean; perms: Permissions; } @@ -174,6 +180,7 @@ export function unitTest( name, fn, ignore: !!options.ignore, + only: !!options.only, perms: normalizedPerms, }; diff --git a/cli/tests/unit/unit_test_runner.ts b/cli/tests/unit/unit_test_runner.ts index e3df358d7..38db545c7 100755 --- a/cli/tests/unit/unit_test_runner.ts +++ b/cli/tests/unit/unit_test_runner.ts @@ -2,6 +2,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import "./unit_tests.ts"; import { + REGISTERED_UNIT_TESTS, + colors, readLines, permissionCombinations, Permissions, @@ -225,6 +227,13 @@ async function masterRunnerMain( } console.log("Unit tests passed"); + + if (REGISTERED_UNIT_TESTS.find(({ only }) => only)) { + console.error( + `\n${colors.red("FAILED")} because the "only" option was used` + ); + Deno.exit(1); + } } const HELP = `Unit test runner |