diff options
| author | Vincent LE GOFF <g_n_s@hotmail.fr> | 2019-03-28 17:29:27 +0100 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-03-28 12:29:27 -0400 |
| commit | 8f0407efad81ea8c255daf03c0e19b6bae3b88b6 (patch) | |
| tree | cdbf1b9914c2a01450364fbe3f7790564f91cc55 | |
| parent | b7022848f6b68cb6a79eb1593ad683ff4d217116 (diff) | |
Fix parallel testing (denoland/deno_std#309)
Fixes denoland/deno_std#308
Co-authored by @chiefbiiko
Original: https://github.com/denoland/deno_std/commit/cac060f3882ba5df2e0e641350b33ef771c8ee44
| -rw-r--r-- | testing/main.ts | 10 | ||||
| -rw-r--r-- | testing/mod.ts | 19 |
2 files changed, 22 insertions, 7 deletions
diff --git a/testing/main.ts b/testing/main.ts index 077d662ee..00502b237 100644 --- a/testing/main.ts +++ b/testing/main.ts @@ -1,3 +1,11 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import { runTests } from "./mod.ts"; -runTests(); + +async function main() { + // Testing entire test suite serially + await runTests(); + // Testing parallel execution on a subset that does not depend on exec order + await runTests({ parallel: true, only: /^testing/ }); +} + +main(); diff --git a/testing/mod.ts b/testing/mod.ts index d0d755e78..71f27db20 100644 --- a/testing/mod.ts +++ b/testing/mod.ts @@ -10,7 +10,7 @@ export interface TestDefinition { } let filterRegExp: RegExp | null; -const tests: TestDefinition[] = []; +const candidates: TestDefinition[] = []; let filtered = 0; @@ -35,7 +35,7 @@ export function test(t: TestDefinition | TestFunction): void { throw new Error("Test function may not be anonymous"); } if (filter(name)) { - tests.push({ fn, name }); + candidates.push({ fn, name }); } else { filtered++; } @@ -124,8 +124,8 @@ function previousPrinted(name: string, results: TestResults): boolean { async function createTestCase( stats: TestStats, results: TestResults, - { fn, name }: TestDefinition, - exitOnFail: boolean + exitOnFail: boolean, + { fn, name }: TestDefinition ): Promise<void> { const result: TestResult = results.cases.get(results.keys.get(name)); try { @@ -197,6 +197,8 @@ async function runTestsSerial( export interface RunOptions { parallel?: boolean; exitOnFail?: boolean; + only?: RegExp; + skip?: RegExp; } /** @@ -205,11 +207,16 @@ export interface RunOptions { */ export async function runTests({ parallel = false, - exitOnFail = false + exitOnFail = false, + only = /[^\s]/, + skip = /^\s*$/ }: RunOptions = {}): Promise<void> { + const tests: TestDefinition[] = candidates.filter( + ({ name }) => only.test(name) && !skip.test(name) + ); const stats: TestStats = { measured: 0, - ignored: 0, + ignored: candidates.length - tests.length, filtered: filtered, passed: 0, failed: 0 |
