-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: test runner #516
feat: test runner #516
Changes from 9 commits
f81e666
79c6777
9d40715
f4c8fc3
eb5efa6
751440b
c4a5727
059f083
9fcc321
7d8a523
881af2c
3d741d4
a892063
b255038
527c2a8
39b5d73
b33d282
ddbfc11
fd517bc
a3313a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/usr/bin/env deno -A | ||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. | ||
import { parse } from "../flags/mod.ts"; | ||
import { glob, walk } from "../fs/mod.ts"; | ||
import { runTests } from "./mod.ts"; | ||
const { args, cwd } = Deno; | ||
|
||
const DEFAULT_GLOBS = [ | ||
"**/*_test.ts", | ||
"**/*_test.js", | ||
"**/test.ts", | ||
"**/test.js" | ||
]; | ||
|
||
/* eslint-disable max-len */ | ||
function showHelp(): void { | ||
console.log(`Deno test runner | ||
|
||
USAGE: | ||
deno -A https://deno.land/std/testing/runner.ts [OPTIONS] [FILES...] | ||
|
||
OPTIONS: | ||
-q, --quiet Don't show output from test cases | ||
-f, --failfast Stop test suite on first error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
-e, --exclude <FILES...> List of file names to exclude from run. If this options is | ||
used files to match must be specified after "--". | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I’m wondering if |
||
|
||
ARGS: | ||
[FILES...] List of file names to run. Defaults to: ${DEFAULT_GLOBS.join( | ||
"," | ||
)} | ||
`); | ||
} | ||
/* eslint-enable max-len */ | ||
|
||
async function main(): Promise<void> { | ||
const parsedArgs = parse(args.slice(1), { | ||
boolean: ["quiet", "failfast", "help"], | ||
string: ["exclude"], | ||
alias: { | ||
help: ["h"], | ||
quiet: ["q"], | ||
failfast: ["f"], | ||
exclude: ["e"] | ||
} | ||
}); | ||
|
||
if (parsedArgs.help) { | ||
return showHelp(); | ||
} | ||
|
||
let includeFiles; | ||
let excludeFiles; | ||
|
||
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 filesIterator = walk(cwd(), { | ||
bartlomieju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
match: includeFiles.map(glob), | ||
skip: excludeFiles.map(glob) | ||
}); | ||
|
||
const foundTestFiles: string[] = []; | ||
for await (const { filename } of filesIterator) { | ||
foundTestFiles.push(filename); | ||
} | ||
|
||
if (foundTestFiles.length === 0) { | ||
console.error("No matching test files found."); | ||
Deno.exit(0); | ||
bartlomieju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
console.log(`Found ${foundTestFiles.length} matching test files.`); | ||
|
||
for (const filename of foundTestFiles) { | ||
await import(filename); | ||
} | ||
|
||
await runTests({ | ||
exitOnFail: !!parsedArgs.failfast, | ||
disableLog: !!parsedArgs.quiet | ||
}); | ||
bartlomieju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
main(); | ||
ry marked this conversation as resolved.
Show resolved
Hide resolved
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--silent