mirror of
https://github.com/denoland/deno.git
synced 2025-09-20 01:19:51 +00:00
feat: deno test --filter (#4570)
This commit is contained in:
parent
ff0b32f81d
commit
c738797944
6 changed files with 325 additions and 289 deletions
2
cli/js/lib.deno.ns.d.ts
vendored
2
cli/js/lib.deno.ns.d.ts
vendored
|
@ -120,7 +120,7 @@ declare namespace Deno {
|
|||
failFast?: boolean;
|
||||
/** String or RegExp used to filter test to run. Only test with names
|
||||
* matching provided `String` or `RegExp` will be run. */
|
||||
only?: string | RegExp;
|
||||
filter?: string | RegExp;
|
||||
/** String or RegExp used to skip tests to run. Tests with names
|
||||
* matching provided `String` or `RegExp` will not be run. */
|
||||
skip?: string | RegExp;
|
||||
|
|
|
@ -270,17 +270,17 @@ class TestApi {
|
|||
}
|
||||
|
||||
function createFilterFn(
|
||||
only: undefined | string | RegExp,
|
||||
filter: undefined | string | RegExp,
|
||||
skip: undefined | string | RegExp
|
||||
): (def: TestDefinition) => boolean {
|
||||
return (def: TestDefinition): boolean => {
|
||||
let passes = true;
|
||||
|
||||
if (only) {
|
||||
if (only instanceof RegExp) {
|
||||
passes = passes && only.test(def.name);
|
||||
if (filter) {
|
||||
if (filter instanceof RegExp) {
|
||||
passes = passes && filter.test(def.name);
|
||||
} else {
|
||||
passes = passes && def.name.includes(only);
|
||||
passes = passes && def.name.includes(filter);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -299,7 +299,7 @@ function createFilterFn(
|
|||
export interface RunTestsOptions {
|
||||
exitOnFail?: boolean;
|
||||
failFast?: boolean;
|
||||
only?: string | RegExp;
|
||||
filter?: string | RegExp;
|
||||
skip?: string | RegExp;
|
||||
disableLog?: boolean;
|
||||
reportToConsole?: boolean;
|
||||
|
@ -309,13 +309,13 @@ export interface RunTestsOptions {
|
|||
export async function runTests({
|
||||
exitOnFail = true,
|
||||
failFast = false,
|
||||
only = undefined,
|
||||
filter = undefined,
|
||||
skip = undefined,
|
||||
disableLog = false,
|
||||
reportToConsole: reportToConsole_ = true,
|
||||
onMessage = undefined,
|
||||
}: RunTestsOptions = {}): Promise<TestMessage["end"] & {}> {
|
||||
const filterFn = createFilterFn(only, skip);
|
||||
const filterFn = createFilterFn(filter, skip);
|
||||
const testApi = new TestApi(TEST_REGISTRY, filterFn, failFast);
|
||||
|
||||
// @ts-ignore
|
||||
|
|
|
@ -68,7 +68,7 @@ async function workerRunnerMain(
|
|||
// Execute tests
|
||||
await Deno.runTests({
|
||||
exitOnFail: false,
|
||||
only: filter,
|
||||
filter,
|
||||
reportToConsole: false,
|
||||
onMessage: reportToConn.bind(null, conn),
|
||||
});
|
||||
|
@ -296,7 +296,7 @@ async function main(): Promise<void> {
|
|||
|
||||
// Running tests matching current process permissions
|
||||
await registerUnitTests();
|
||||
await Deno.runTests({ only: filter });
|
||||
await Deno.runTests({ filter });
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue