1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-27 01:29:14 -05:00

Fix parallel testing (#309)

Fixes #308

Co-authored by @chiefbiiko
This commit is contained in:
Vincent LE GOFF 2019-03-28 17:29:27 +01:00 committed by Ryan Dahl
parent d9e8953110
commit cac060f388
2 changed files with 22 additions and 7 deletions

View file

@ -1,3 +1,11 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { runTests } from "./mod.ts"; 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();

View file

@ -10,7 +10,7 @@ export interface TestDefinition {
} }
let filterRegExp: RegExp | null; let filterRegExp: RegExp | null;
const tests: TestDefinition[] = []; const candidates: TestDefinition[] = [];
let filtered = 0; let filtered = 0;
@ -35,7 +35,7 @@ export function test(t: TestDefinition | TestFunction): void {
throw new Error("Test function may not be anonymous"); throw new Error("Test function may not be anonymous");
} }
if (filter(name)) { if (filter(name)) {
tests.push({ fn, name }); candidates.push({ fn, name });
} else { } else {
filtered++; filtered++;
} }
@ -124,8 +124,8 @@ function previousPrinted(name: string, results: TestResults): boolean {
async function createTestCase( async function createTestCase(
stats: TestStats, stats: TestStats,
results: TestResults, results: TestResults,
{ fn, name }: TestDefinition, exitOnFail: boolean,
exitOnFail: boolean { fn, name }: TestDefinition
): Promise<void> { ): Promise<void> {
const result: TestResult = results.cases.get(results.keys.get(name)); const result: TestResult = results.cases.get(results.keys.get(name));
try { try {
@ -197,6 +197,8 @@ async function runTestsSerial(
export interface RunOptions { export interface RunOptions {
parallel?: boolean; parallel?: boolean;
exitOnFail?: boolean; exitOnFail?: boolean;
only?: RegExp;
skip?: RegExp;
} }
/** /**
@ -205,11 +207,16 @@ export interface RunOptions {
*/ */
export async function runTests({ export async function runTests({
parallel = false, parallel = false,
exitOnFail = false exitOnFail = false,
only = /[^\s]/,
skip = /^\s*$/
}: RunOptions = {}): Promise<void> { }: RunOptions = {}): Promise<void> {
const tests: TestDefinition[] = candidates.filter(
({ name }) => only.test(name) && !skip.test(name)
);
const stats: TestStats = { const stats: TestStats = {
measured: 0, measured: 0,
ignored: 0, ignored: candidates.length - tests.length,
filtered: filtered, filtered: filtered,
passed: 0, passed: 0,
failed: 0 failed: 0