From 20dad3659c60b61c9f5af5427ad61857593bf3e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 5 Mar 2020 11:52:18 +0100 Subject: refactor: preliminary cleanup of Deno.runTests() (#4237) * refactor: preliminary cleanup of Deno.runTests() * Change time measurement to use new Date() instead of performance.now(). Because there is no guarantee that tests are run with "--allow-hr" using new Date() guarantees higher precision of 1ms instead of 2ms. * Support String type filter in "skip" and "only". * Split "exitOnFail" into "exitOnFail" and "failFast". Former tells if "runTests()" should exit with code 1 on test failure, while latter tells if "runTests()" should stop running tests on first failure. * Use "defer" to wait for unhandled promise rejection - this bit is funky and doesn't seem right, but for now it's just a rewrite from using "setTimeout". Intended to be fixed in later commits. * Remove global "__DENO_TEST_REGISTRY", don't expose list of registered tests (to be addressed in follow up commits) * Remove arbitrary slow test threshold; use uniform coloring instead --- cli/js/testing_test.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 cli/js/testing_test.ts (limited to 'cli/js/testing_test.ts') diff --git a/cli/js/testing_test.ts b/cli/js/testing_test.ts new file mode 100644 index 000000000..b47eb03e2 --- /dev/null +++ b/cli/js/testing_test.ts @@ -0,0 +1,37 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +import { assertThrows, unitTest } from "./test_util.ts"; + +unitTest(function testFnOverloading(): void { + // just verifying that you can use this test definition syntax + Deno.test("test fn overloading", (): void => {}); +}); + +unitTest(function nameOfTestCaseCantBeEmpty(): void { + assertThrows( + () => { + Deno.test("", () => {}); + }, + Error, + "The name of test case can't be empty" + ); + assertThrows( + () => { + Deno.test({ + name: "", + fn: () => {} + }); + }, + Error, + "The name of test case can't be empty" + ); +}); + +unitTest(function testFnCantBeAnonymous(): void { + assertThrows( + () => { + Deno.test(function() {}); + }, + Error, + "Test function can't be anonymous" + ); +}); -- cgit v1.2.3