diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2019-10-10 05:31:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-10 05:31:23 -0400 |
commit | e7562eed8c816cd0d97aab6b818d7c8453dbaa2b (patch) | |
tree | c5a9f536e79d2c8d2d02897511a9138acaf35394 /std/testing/runner_test.ts | |
parent | 3882c9d19a641e0c919f1350d87c6d7ee280cf78 (diff) | |
parent | 93f7f00c956c14620ef031626f124b57397ca867 (diff) |
Merge deno_std in main repo (#3091)
The history of deno_std is persevered but rewritten to update links to issues and PRs
Fixes denoland/deno_std#603
Diffstat (limited to 'std/testing/runner_test.ts')
m--------- | std | 0 | ||||
-rw-r--r-- | std/testing/runner_test.ts | 95 |
2 files changed, 95 insertions, 0 deletions
diff --git a/std b/std deleted file mode 160000 -Subproject 43aafbf33285753e7b42230f0eb7969b300f71c diff --git a/std/testing/runner_test.ts b/std/testing/runner_test.ts new file mode 100644 index 000000000..e2617b155 --- /dev/null +++ b/std/testing/runner_test.ts @@ -0,0 +1,95 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +import { test } from "./mod.ts"; +import { findTestModules } from "./runner.ts"; +import { isWindows } from "../fs/path/constants.ts"; +import { assertEquals } from "../testing/asserts.ts"; +const { cwd } = Deno; + +function urlToFilePath(url: URL): string { + // Since `new URL('file:///C:/a').pathname` is `/C:/a`, remove leading slash. + return url.pathname.slice(url.protocol == "file:" && isWindows ? 1 : 0); +} + +async function findTestModulesArray( + include: string[], + exclude: string[], + root: string = cwd() +): Promise<string[]> { + const result = []; + for await (const testModule of findTestModules(include, exclude, root)) { + result.push(testModule); + } + return result; +} + +const TEST_DATA_URL = new URL("testdata", import.meta.url); +const TEST_DATA_PATH = urlToFilePath(TEST_DATA_URL); + +test(async function findTestModulesDir1(): Promise<void> { + const urls = await findTestModulesArray(["."], [], TEST_DATA_PATH); + assertEquals(urls.sort(), [ + `${TEST_DATA_URL}/bar_test.js`, + `${TEST_DATA_URL}/foo_test.ts`, + `${TEST_DATA_URL}/subdir/bar_test.js`, + `${TEST_DATA_URL}/subdir/foo_test.ts`, + `${TEST_DATA_URL}/subdir/test.js`, + `${TEST_DATA_URL}/subdir/test.ts`, + `${TEST_DATA_URL}/test.js`, + `${TEST_DATA_URL}/test.ts` + ]); +}); + +test(async function findTestModulesDir2(): Promise<void> { + const urls = await findTestModulesArray(["subdir"], [], TEST_DATA_PATH); + assertEquals(urls.sort(), [ + `${TEST_DATA_URL}/subdir/bar_test.js`, + `${TEST_DATA_URL}/subdir/foo_test.ts`, + `${TEST_DATA_URL}/subdir/test.js`, + `${TEST_DATA_URL}/subdir/test.ts` + ]); +}); + +test(async function findTestModulesGlob(): Promise<void> { + const urls = await findTestModulesArray( + ["**/*_test.{js,ts}"], + [], + TEST_DATA_PATH + ); + assertEquals(urls.sort(), [ + `${TEST_DATA_URL}/bar_test.js`, + `${TEST_DATA_URL}/foo_test.ts`, + `${TEST_DATA_URL}/subdir/bar_test.js`, + `${TEST_DATA_URL}/subdir/foo_test.ts` + ]); +}); + +test(async function findTestModulesExcludeDir(): Promise<void> { + const urls = await findTestModulesArray(["."], ["subdir"], TEST_DATA_PATH); + assertEquals(urls.sort(), [ + `${TEST_DATA_URL}/bar_test.js`, + `${TEST_DATA_URL}/foo_test.ts`, + `${TEST_DATA_URL}/test.js`, + `${TEST_DATA_URL}/test.ts` + ]); +}); + +test(async function findTestModulesExcludeGlob(): Promise<void> { + const urls = await findTestModulesArray(["."], ["**/foo*"], TEST_DATA_PATH); + assertEquals(urls.sort(), [ + `${TEST_DATA_URL}/bar_test.js`, + `${TEST_DATA_URL}/subdir/bar_test.js`, + `${TEST_DATA_URL}/subdir/test.js`, + `${TEST_DATA_URL}/subdir/test.ts`, + `${TEST_DATA_URL}/test.js`, + `${TEST_DATA_URL}/test.ts` + ]); +}); + +test(async function findTestModulesRemote(): Promise<void> { + const urls = [ + "https://example.com/colors_test.ts", + "http://example.com/printf_test.ts" + ]; + const matches = await findTestModulesArray(urls, []); + assertEquals(matches, urls); +}); |