summaryrefslogtreecommitdiff
path: root/testing/runner.ts
diff options
context:
space:
mode:
Diffstat (limited to 'testing/runner.ts')
-rwxr-xr-xtesting/runner.ts89
1 files changed, 40 insertions, 49 deletions
diff --git a/testing/runner.ts b/testing/runner.ts
index b0357d8e4..a78ed2b3a 100755
--- a/testing/runner.ts
+++ b/testing/runner.ts
@@ -1,14 +1,9 @@
#!/usr/bin/env -S deno -A
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { parse } from "../flags/mod.ts";
-import {
- WalkInfo,
- expandGlobSync,
- glob,
- ExpandGlobOptions
-} from "../fs/mod.ts";
+import { ExpandGlobOptions, expandGlob } from "../fs/mod.ts";
import { isWindows } from "../fs/path/constants.ts";
-import { isAbsolute, join } from "../fs/path/mod.ts";
+import { join } from "../fs/path/mod.ts";
import { RunTestsOptions, runTests } from "./mod.ts";
const { DenoError, ErrorKind, args, cwd, exit } = Deno;
@@ -64,60 +59,56 @@ function filePathToUrl(path: string): string {
return `file://${isWindows ? "/" : ""}${path.replace(/\\/g, "/")}`;
}
-function expandDirectory(dir: string, options: ExpandGlobOptions): WalkInfo[] {
- return DIR_GLOBS.flatMap((s: string): WalkInfo[] => [
- ...expandGlobSync(s, { ...options, root: dir })
- ]);
-}
-
/**
* Given a list of globs or URLs to include and exclude and a root directory
- * from which to expand relative globs, return a list of URLs
+ * from which to expand relative globs, yield a list of URLs
* (file: or remote) that should be imported for the test runner.
*/
-export async function findTestModules(
+export async function* findTestModules(
includeModules: string[],
excludeModules: string[],
root: string = cwd()
-): Promise<string[]> {
+): AsyncIterableIterator<string> {
const [includePaths, includeUrls] = partition(includeModules, isRemoteUrl);
const [excludePaths, excludeUrls] = partition(excludeModules, isRemoteUrl);
- const expandGlobOpts = {
+ const expandGlobOpts: ExpandGlobOptions = {
root,
+ exclude: excludePaths,
+ includeDirs: true,
extended: true,
- globstar: true,
- filepath: true
+ globstar: true
};
- // TODO: We use the `g` flag here to support path prefixes when specifying
- // excludes. Replace with a solution that does this more correctly.
- const excludePathPatterns = excludePaths.map(
- (s: string): RegExp =>
- glob(isAbsolute(s) ? s : join(root, s), { ...expandGlobOpts, flags: "g" })
- );
+ async function* expandDirectory(d: string): AsyncIterableIterator<string> {
+ for (const dirGlob of DIR_GLOBS) {
+ for await (const walkInfo of expandGlob(dirGlob, {
+ ...expandGlobOpts,
+ root: d,
+ includeDirs: false
+ })) {
+ yield filePathToUrl(walkInfo.filename);
+ }
+ }
+ }
+
+ for (const globString of includePaths) {
+ for await (const walkInfo of expandGlob(globString, expandGlobOpts)) {
+ if (walkInfo.info.isDirectory()) {
+ yield* expandDirectory(walkInfo.filename);
+ } else {
+ yield filePathToUrl(walkInfo.filename);
+ }
+ }
+ }
+
const excludeUrlPatterns = excludeUrls.map(
(url: string): RegExp => RegExp(url)
);
- const notExcludedPath = ({ filename }: WalkInfo): boolean =>
- !excludePathPatterns.some((p: RegExp): boolean => !!filename.match(p));
- const notExcludedUrl = (url: string): boolean =>
+ const shouldIncludeUrl = (url: string): boolean =>
!excludeUrlPatterns.some((p: RegExp): boolean => !!url.match(p));
- const matchedPaths = includePaths
- .flatMap((s: string): WalkInfo[] => [...expandGlobSync(s, expandGlobOpts)])
- .filter(notExcludedPath)
- .flatMap(({ filename, info }): string[] =>
- info.isDirectory()
- ? expandDirectory(filename, { ...expandGlobOpts, includeDirs: false })
- .filter(notExcludedPath)
- .map(({ filename }): string => filename)
- : [filename]
- );
-
- const matchedUrls = includeUrls.filter(notExcludedUrl);
-
- return [...matchedPaths.map(filePathToUrl), ...matchedUrls];
+ yield* includeUrls.filter(shouldIncludeUrl);
}
export interface RunTestModulesOptions extends RunTestsOptions {
@@ -162,9 +153,13 @@ export async function runTestModules({
skip = /^\s*$/,
disableLog = false
}: RunTestModulesOptions = {}): Promise<void> {
- const testModuleUrls = await findTestModules(include, exclude);
+ let moduleCount = 0;
+ for await (const testModule of findTestModules(include, exclude)) {
+ await import(testModule);
+ moduleCount++;
+ }
- if (testModuleUrls.length == 0) {
+ if (moduleCount == 0) {
const noneFoundMessage = "No matching test modules found.";
if (!allowNone) {
throw new DenoError(ErrorKind.NotFound, noneFoundMessage);
@@ -175,11 +170,7 @@ export async function runTestModules({
}
if (!disableLog) {
- console.log(`Found ${testModuleUrls.length} matching test modules.`);
- }
-
- for (const url of testModuleUrls) {
- await import(url);
+ console.log(`Found ${moduleCount} matching test modules.`);
}
await runTests({