1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00
Original: 17a214bbd5
This commit is contained in:
Nayeem Rahman 2019-09-28 14:33:17 +01:00 committed by Ryan Dahl
parent af18093498
commit a472b6732d
25 changed files with 444 additions and 166 deletions

View file

@ -4,5 +4,5 @@ parameters:
steps:
- bash: deno${{ parameters.exe_suffix }} run --allow-run --allow-write --allow-read --allow-env ./format.ts --check
- bash: export START_TIME=$(date +%s)
- bash: deno${{ parameters.exe_suffix }} run --allow-run --allow-net --allow-write --allow-read --allow-env --config=tsconfig.test.json ./testing/runner.ts --exclude node_modules
- bash: deno${{ parameters.exe_suffix }} run --allow-run --allow-read .ci/check_source_file_changes.ts $START_TIME
- bash: deno${{ parameters.exe_suffix }} run --allow-run --allow-net --allow-write --allow-read --allow-env --config=tsconfig.test.json ./testing/runner.ts --exclude node_modules,**/testdata
- bash: deno${{ parameters.exe_suffix }} run --allow-run --allow-read .ci/check_source_file_changes.ts $START_TIME

View file

@ -1,4 +1,7 @@
import { globrex } from "./globrex.ts";
import { isAbsolute, join } from "./path/mod.ts";
import { WalkInfo, walk, walkSync } from "./walk.ts";
const { cwd } = Deno;
export interface GlobOptions {
// Allow ExtGlob features
@ -41,7 +44,11 @@ export interface GlobOptions {
* @returns A RegExp for the glob pattern
*/
export function glob(glob: string, options: GlobOptions = {}): RegExp {
return globrex(glob, options).regex;
const result = globrex(glob, options);
if (options.filepath) {
return result.path!.regex;
}
return result.regex;
}
/** Test whether the given string is a glob */
@ -76,3 +83,61 @@ export function isGlob(str: string): boolean {
return false;
}
export interface ExpandGlobOptions extends GlobOptions {
root?: string;
includeDirs?: boolean;
}
/**
* Expand the glob string from the specified `root` directory and yield each
* result as a `WalkInfo` object.
*/
// TODO: Use a proper glob expansion algorithm.
// This is a very incomplete solution. The whole directory tree from `root` is
// walked and parent paths are not supported.
export async function* expandGlob(
globString: string,
{
root = cwd(),
includeDirs = true,
extended = false,
globstar = false,
strict = false,
filepath = true,
flags = ""
}: ExpandGlobOptions = {}
): AsyncIterableIterator<WalkInfo> {
const absoluteGlob = isAbsolute(globString)
? globString
: join(root, globString);
const globOptions = { extended, globstar, strict, filepath, flags };
yield* walk(root, {
match: [glob(absoluteGlob, globOptions)],
includeDirs
});
}
/** Synchronous version of `expandGlob()`. */
// TODO: As `expandGlob()`.
export function* expandGlobSync(
globString: string,
{
root = cwd(),
includeDirs = true,
extended = false,
globstar = false,
strict = false,
filepath = true,
flags = ""
}: ExpandGlobOptions = {}
): IterableIterator<WalkInfo> {
const absoluteGlob = isAbsolute(globString)
? globString
: join(root, globString);
const globOptions = { extended, globstar, strict, filepath, flags };
yield* walkSync(root, {
match: [glob(absoluteGlob, globOptions)],
includeDirs
});
}

View file

@ -1,9 +1,16 @@
const { mkdir } = Deno;
type FileInfo = Deno.FileInfo;
const { cwd, mkdir } = Deno;
import { test, runIfMain } from "../testing/mod.ts";
import { assert, assertEquals } from "../testing/asserts.ts";
import { glob, isGlob } from "./glob.ts";
import { join } from "./path.ts";
import { isWindows } from "./path/constants.ts";
import {
ExpandGlobOptions,
expandGlob,
glob,
isGlob,
expandGlobSync
} from "./glob.ts";
import { join, normalize, relative } from "./path.ts";
import { WalkInfo } from "./walk.ts";
import { testWalk } from "./walk_test.ts";
import { touch, walkArray } from "./walk_test.ts";
@ -131,7 +138,6 @@ testWalk(
const arr = await walkArray(".", {
match: [glob("x.*", { flags: "g", globstar: true })]
});
console.log(arr);
assertEquals(arr.length, 2);
assertEquals(arr[0], "x.js");
assertEquals(arr[1], "x.ts");
@ -253,4 +259,76 @@ test({
}
});
async function expandGlobArray(
globString: string,
options: ExpandGlobOptions
): Promise<string[]> {
const infos: WalkInfo[] = [];
for await (const info of expandGlob(globString, options)) {
infos.push(info);
}
infos.sort();
const infosSync = [...expandGlobSync(globString, options)];
infosSync.sort();
assertEquals(infos, infosSync);
const root = normalize(options.root || cwd());
const paths = infos.map(({ filename }): string => filename);
for (const path of paths) {
assert(path.startsWith(root));
}
const relativePaths = paths.map((path: string): string =>
relative(root, path)
);
relativePaths.sort();
return relativePaths;
}
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);
}
const EG_OPTIONS = {
root: urlToFilePath(new URL(join("testdata", "glob"), import.meta.url)),
includeDirs: true,
extended: false,
globstar: false,
strict: false,
filepath: false,
flags: ""
};
test(async function expandGlobExt(): Promise<void> {
const options = { ...EG_OPTIONS, extended: true };
assertEquals(await expandGlobArray("abc?(def|ghi)", options), [
"abc",
"abcdef"
]);
assertEquals(await expandGlobArray("abc*(def|ghi)", options), [
"abc",
"abcdef",
"abcdefghi"
]);
assertEquals(await expandGlobArray("abc+(def|ghi)", options), [
"abcdef",
"abcdefghi"
]);
assertEquals(await expandGlobArray("abc@(def|ghi)", options), ["abcdef"]);
assertEquals(await expandGlobArray("abc{def,ghi}", options), ["abcdef"]);
assertEquals(await expandGlobArray("abc!(def|ghi)", options), ["abc"]);
});
test(async function expandGlobGlobstar(): Promise<void> {
const options = { ...EG_OPTIONS, globstar: true };
assertEquals(await expandGlobArray(join("**", "abc"), options), [
"abc",
join("subdir", "abc")
]);
});
test(async function expandGlobIncludeDirs(): Promise<void> {
const options = { ...EG_OPTIONS, includeDirs: false };
assertEquals(await expandGlobArray("subdir", options), []);
});
runIfMain(import.meta);

View file

@ -5,17 +5,18 @@
import { GlobOptions } from "./glob.ts";
const isWin = Deno.build.os === "win";
const SEP = isWin ? `\\\\+` : `\\/`;
const SEP = isWin ? `(\\\\+|\\/)` : `\\/`;
const SEP_ESC = isWin ? `\\\\` : `/`;
const GLOBSTAR = `((?:[^/]*(?:/|$))*)`;
const WILDCARD = `([^/]*)`;
const GLOBSTAR_SEGMENT = `((?:[^${SEP_ESC}]*(?:${SEP_ESC}|$))*)`;
const WILDCARD_SEGMENT = `([^${SEP_ESC}]*)`;
const SEP_RAW = isWin ? `\\` : `/`;
const GLOBSTAR = `((?:[^${SEP_ESC}/]*(?:${SEP_ESC}|\/|$))*)`;
const WILDCARD = `([^${SEP_ESC}/]*)`;
const GLOBSTAR_SEGMENT = `((?:[^${SEP_ESC}/]*(?:${SEP_ESC}|\/|$))*)`;
const WILDCARD_SEGMENT = `([^${SEP_ESC}/]*)`;
export interface GlobrexResult {
regex: RegExp;
path?: {
regex: string | RegExp;
regex: RegExp;
segments: RegExp[];
globstar?: RegExp;
};
@ -44,11 +45,8 @@ export function globrex(
): GlobrexResult {
let regex = "";
let segment = "";
let path: {
regex: string | RegExp;
segments: RegExp[];
globstar?: RegExp;
} = { regex: "", segments: [] };
let pathRegexStr = "";
const pathSegments = [];
// If we are doing extended matching, this boolean is true when we are inside
// a group (eg {*.html,*.js}), and false otherwise.
@ -72,13 +70,13 @@ export function globrex(
const { split, last, only } = options;
if (only !== "path") regex += str;
if (filepath && only !== "regex") {
path.regex += str === "\\/" ? SEP : str;
pathRegexStr += str.match(new RegExp(`^${SEP}$`)) ? SEP : str;
if (split) {
if (last) segment += str;
if (segment !== "") {
// change it 'includes'
if (!flags.includes("g")) segment = `^${segment}$`;
path.segments.push(new RegExp(segment, flags));
pathSegments.push(new RegExp(segment, flags));
}
segment = "";
} else {
@ -267,9 +265,9 @@ export function globrex(
let isGlobstar =
starCount > 1 && // multiple "*"'s
// from the start of the segment
(prevChar === "/" || prevChar === undefined) &&
[SEP_RAW, "/", undefined].includes(prevChar) &&
// to the end of the segment
(nextChar === "/" || nextChar === undefined);
[SEP_RAW, "/", undefined].includes(nextChar);
if (isGlobstar) {
// it's a globstar, so match zero or more path segments
add(GLOBSTAR, { only: "regex" });
@ -292,20 +290,22 @@ export function globrex(
if (!flags.includes("g")) {
regex = `^${regex}$`;
segment = `^${segment}$`;
if (filepath) path.regex = `^${path.regex}$`;
if (filepath) pathRegexStr = `^${pathRegexStr}$`;
}
const result: GlobrexResult = { regex: new RegExp(regex, flags) };
// Push the last segment
if (filepath) {
path.segments.push(new RegExp(segment, flags));
path.regex = new RegExp(path.regex.toString(), flags);
path.globstar = new RegExp(
!flags.includes("g") ? `^${GLOBSTAR_SEGMENT}$` : GLOBSTAR_SEGMENT,
flags
);
result.path = path;
pathSegments.push(new RegExp(segment, flags));
result.path = {
regex: new RegExp(pathRegexStr, flags),
segments: pathSegments,
globstar: new RegExp(
!flags.includes("g") ? `^${GLOBSTAR_SEGMENT}$` : GLOBSTAR_SEGMENT,
flags
)
};
}
return result;

View file

@ -50,3 +50,4 @@ export const CHAR_9 = 57; /* 9 */
export const isWindows = build.os === "win";
export const EOL = isWindows ? "\r\n" : "\n";
export const SEP = isWindows ? "\\" : "/";

0
fs/testdata/glob/abc vendored Normal file
View file

0
fs/testdata/glob/abcdef vendored Normal file
View file

0
fs/testdata/glob/abcdefghi vendored Normal file
View file

0
fs/testdata/glob/subdir/abc vendored Normal file
View file

View file

@ -348,7 +348,7 @@ async function runTestsSerial(
}
/** Defines options for controlling execution details of a test suite. */
export interface RunOptions {
export interface RunTestsOptions {
parallel?: boolean;
exitOnFail?: boolean;
only?: RegExp;
@ -368,7 +368,7 @@ export async function runTests({
only = /[^\s]/,
skip = /^\s*$/,
disableLog = false
}: RunOptions = {}): Promise<void> {
}: RunTestsOptions = {}): Promise<void> {
const tests: TestDefinition[] = candidates.filter(
({ name }): boolean => only.test(name) && !skip.test(name)
);
@ -415,7 +415,7 @@ export async function runTests({
*/
export async function runIfMain(
meta: ImportMeta,
opts?: RunOptions
opts?: RunTestsOptions
): Promise<void> {
if (meta.main) {
return runTests(opts);

View file

@ -1,44 +1,46 @@
#!/usr/bin/env -S deno -A
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { parse } from "../flags/mod.ts";
import { glob, isGlob, walk } from "../fs/mod.ts";
import { runTests } from "./mod.ts";
const { args, cwd } = Deno;
import {
WalkInfo,
expandGlobSync,
glob,
ExpandGlobOptions
} from "../fs/mod.ts";
import { isWindows } from "../fs/path/constants.ts";
import { isAbsolute, join } from "../fs/path/mod.ts";
import { RunTestsOptions, runTests } from "./mod.ts";
const { DenoError, ErrorKind, args, cwd, exit } = Deno;
const DEFAULT_GLOBS = [
"**/*_test.ts",
"**/*_test.js",
"**/test.ts",
"**/test.js"
];
const DIR_GLOBS = [join("**", "?(*_)test.{js,ts}")];
/* eslint-disable max-len */
function showHelp(): void {
console.log(`Deno test runner
USAGE:
deno -A https://deno.land/std/testing/runner.ts [OPTIONS] [FILES...]
deno -A https://deno.land/std/testing/runner.ts [OPTIONS] [MODULES...]
OPTIONS:
-q, --quiet Don't show output from test cases
-f, --failfast Stop test suite on first error
-e, --exclude <FILES...> List of file names to exclude from run. If this options is
used files to match must be specified after "--".
-q, --quiet Don't show output from test cases
-f, --failfast Stop running tests on first error
-e, --exclude <MODULES...> List of comma-separated modules to exclude
--allow-none Exit with status 0 even when no test modules are
found
ARGS:
[FILES...] List of file names to run. Defaults to: ${DEFAULT_GLOBS.join(
","
)}
`);
}
/* eslint-enable max-len */
[MODULES...] List of test modules to run.
A directory <dir> will expand to:
${DIR_GLOBS.map((s: string): string => `${join("<dir>", s)}`)
.join(`
`)}
Defaults to "." when none are provided.
function filePathToRegExp(str: string): RegExp {
if (isGlob(str)) {
return glob(str, { flags: "g" });
}
Note that modules can refer to file paths or URLs. File paths support glob
expansion.
return RegExp(str, "g");
Examples:
deno test src/**/*_test.ts
deno test tests`);
}
function isRemoteUrl(url: string): boolean {
@ -58,114 +60,186 @@ function partition(
);
}
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 list of globs or URLs to include and exclude and root directory return
* list of file URLs that should be imported for test runner.
* 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
* (file: or remote) that should be imported for the test runner.
*/
export async function getMatchingUrls(
matchPaths: string[],
excludePaths: string[],
root: string
export async function findTestModules(
includeModules: string[],
excludeModules: string[],
root: string = cwd()
): Promise<string[]> {
const [includeLocal, includeRemote] = partition(matchPaths, isRemoteUrl);
const [excludeLocal, excludeRemote] = partition(excludePaths, isRemoteUrl);
const [includePaths, includeUrls] = partition(includeModules, isRemoteUrl);
const [excludePaths, excludeUrls] = partition(excludeModules, isRemoteUrl);
const localFileIterator = walk(root, {
match: includeLocal.map((f: string): RegExp => filePathToRegExp(f)),
skip: excludeLocal.map((f: string): RegExp => filePathToRegExp(f))
});
const expandGlobOpts = {
root,
extended: true,
globstar: true,
filepath: true
};
let matchingLocalUrls: string[] = [];
for await (const { filename } of localFileIterator) {
matchingLocalUrls.push(`file://${filename}`);
}
const excludeRemotePatterns = excludeRemote.map(
// 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" })
);
const excludeUrlPatterns = excludeUrls.map(
(url: string): RegExp => RegExp(url)
);
const matchingRemoteUrls = includeRemote.filter(
(candidateUrl: string): boolean => {
return !excludeRemotePatterns.some((pattern: RegExp): boolean => {
const r = pattern.test(candidateUrl);
pattern.lastIndex = 0;
return r;
});
}
);
const notExcludedPath = ({ filename }: WalkInfo): boolean =>
!excludePathPatterns.some((p: RegExp): boolean => !!filename.match(p));
const notExcludedUrl = (url: string): boolean =>
!excludeUrlPatterns.some((p: RegExp): boolean => !!url.match(p));
return matchingLocalUrls.concat(matchingRemoteUrls);
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];
}
export interface RunTestModulesOptions extends RunTestsOptions {
include?: string[];
exclude?: string[];
allowNone?: boolean;
}
/**
* This function runs matching test files in `root` directory.
* Import the specified test modules and run their tests as a suite.
*
* File matching and excluding supports glob syntax, ie. if encountered arg is
* a glob it will be expanded using `glob` method from `fs` module.
* Test modules are specified as an array of strings and can include local files
* or URLs.
*
* Note that your shell may expand globs for you:
* $ deno -A ./runner.ts **\/*_test.ts **\/test.ts
* File matching and excluding support glob syntax - arguments recognized as
* globs will be expanded using `glob()` from the `fs` module.
*
* Expanding using `fs.glob`:
* $ deno -A ./runner.ts \*\*\/\*_test.ts \*\*\/test.ts
* Example:
*
* `**\/*_test.ts` and `**\/test.ts"` are arguments that will be parsed and
* expanded as: [glob("**\/*_test.ts"), glob("**\/test.ts")]
* runTestModules({ include: ["**\/*_test.ts", "**\/test.ts"] });
*
* Any matched directory `<dir>` will expand to:
* <dir>/**\/?(*_)test.{js,ts}
*
* So the above example is captured naturally by:
*
* runTestModules({ include: ["."] });
*
* Which is the default used for:
*
* runTestModules();
*/
// TODO: change return type to `Promise<void>` once, `runTests` is updated
// to return boolean instead of exiting
export async function main(root: string = cwd()): Promise<void> {
const parsedArgs = parse(args.slice(1), {
boolean: ["quiet", "failfast", "help"],
string: ["exclude"],
alias: {
help: ["h"],
quiet: ["q"],
failfast: ["f"],
exclude: ["e"]
// TODO: Change return type to `Promise<void>` once, `runTests` is updated
// to return boolean instead of exiting.
export async function runTestModules({
include = ["."],
exclude = [],
allowNone = false,
parallel = false,
exitOnFail = false,
only = /[^\s]/,
skip = /^\s*$/,
disableLog = false
}: RunTestModulesOptions = {}): Promise<void> {
const testModuleUrls = await findTestModules(include, exclude);
if (testModuleUrls.length == 0) {
const noneFoundMessage = "No matching test modules found.";
if (!allowNone) {
throw new DenoError(ErrorKind.NotFound, noneFoundMessage);
} else if (!disableLog) {
console.log(noneFoundMessage);
}
});
if (parsedArgs.help) {
return showHelp();
}
let includeFiles: string[];
let excludeFiles: string[];
if (parsedArgs._.length) {
includeFiles = (parsedArgs._ as string[])
.map((fileGlob: string): string[] => {
return fileGlob.split(",");
})
.flat();
} else {
includeFiles = DEFAULT_GLOBS;
}
if (parsedArgs.exclude) {
excludeFiles = (parsedArgs.exclude as string).split(",");
} else {
excludeFiles = [];
}
const foundTestUrls = await getMatchingUrls(includeFiles, excludeFiles, root);
if (foundTestUrls.length === 0) {
console.error("No matching test files found.");
return;
}
console.log(`Found ${foundTestUrls.length} matching test files.`);
if (!disableLog) {
console.log(`Found ${testModuleUrls.length} matching test modules.`);
}
for (const url of foundTestUrls) {
for (const url of testModuleUrls) {
await import(url);
}
await runTests({
exitOnFail: !!parsedArgs.failfast,
disableLog: !!parsedArgs.quiet
parallel,
exitOnFail,
only,
skip,
disableLog
});
}
async function main(): Promise<void> {
const parsedArgs = parse(args.slice(1), {
boolean: ["allow-none", "failfast", "help", "quiet"],
string: ["exclude"],
alias: {
exclude: ["e"],
failfast: ["f"],
help: ["h"],
quiet: ["q"]
},
default: {
"allow-none": false,
failfast: false,
help: false,
quiet: false
}
});
if (parsedArgs.help) {
return showHelp();
}
const include =
parsedArgs._.length > 0
? (parsedArgs._ as string[]).flatMap((fileGlob: string): string[] =>
fileGlob.split(",")
)
: ["."];
const exclude =
parsedArgs.exclude != null ? (parsedArgs.exclude as string).split(",") : [];
const allowNone = parsedArgs["allow-none"];
const exitOnFail = parsedArgs.failfast;
const disableLog = parsedArgs.quiet;
try {
await runTestModules({
include,
exclude,
allowNone,
exitOnFail,
disableLog
});
} catch (error) {
if (!disableLog) {
console.error(error.message);
}
exit(1);
}
}
if (import.meta.main) {
main();
}

View file

@ -1,30 +1,78 @@
// 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";
import { getMatchingUrls } from "./runner.ts";
import { join } from "../fs/path/mod.ts";
/**
* IMPORTANT: This file assumes it is run from root of repository.
*/
const cwd = Deno.cwd();
const TEST_ROOT_PATH = join(cwd, "fmt");
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);
}
test(async function getMatchingUrlsRemote(): Promise<void> {
const matches = [
"https://deno.land/std/fmt/colors_test.ts",
"http://deno.land/std/fmt/printf_test.ts"
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 findTestModules(["."], [], 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 findTestModules(["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 findTestModules(["**/*_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 findTestModules(["."], ["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 findTestModules(["."], ["**/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 urls = await getMatchingUrls(matches, [], TEST_ROOT_PATH);
assertEquals(urls, matches);
});
test(async function getMatchingUrlsLocal(): Promise<void> {
const urls = await getMatchingUrls(
["fmt/*_test.ts"],
["colors*"],
TEST_ROOT_PATH
);
assertEquals(urls.length, 1);
const matches = await findTestModules(urls, []);
assertEquals(matches, urls);
});

1
testing/testdata/bar.js vendored Normal file
View file

@ -0,0 +1 @@
export {};

1
testing/testdata/bar_test.js vendored Normal file
View file

@ -0,0 +1 @@
export {};

1
testing/testdata/foo.ts vendored Normal file
View file

@ -0,0 +1 @@
export {};

1
testing/testdata/foo_test.ts vendored Normal file
View file

@ -0,0 +1 @@
export {};

1
testing/testdata/subdir/bar.js vendored Normal file
View file

@ -0,0 +1 @@
export {};

1
testing/testdata/subdir/bar_test.js vendored Normal file
View file

@ -0,0 +1 @@
export {};

1
testing/testdata/subdir/foo.ts vendored Normal file
View file

@ -0,0 +1 @@
export {};

1
testing/testdata/subdir/foo_test.ts vendored Normal file
View file

@ -0,0 +1 @@
export {};

1
testing/testdata/subdir/test.js vendored Normal file
View file

@ -0,0 +1 @@
export {};

1
testing/testdata/subdir/test.ts vendored Normal file
View file

@ -0,0 +1 @@
export {};

1
testing/testdata/test.js vendored Normal file
View file

@ -0,0 +1 @@
export {};

1
testing/testdata/test.ts vendored Normal file
View file

@ -0,0 +1 @@
export {};

View file

@ -33,7 +33,7 @@ test(async function xevalCliReplvar(): Promise<void> {
await p.stdin!.write(encode("hello"));
await p.stdin!.close();
assertEquals(await p.status(), { code: 0, success: true });
assertEquals(decode(await p.output()), "hello\n");
assertEquals(decode(await p.output()).trimEnd(), "hello");
});
test(async function xevalCliSyntaxError(): Promise<void> {