Skip to content

Commit

Permalink
feat(testrunner): convert reporter to an interface (#3588)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Aug 24, 2020
1 parent 847201b commit baa6b64
Show file tree
Hide file tree
Showing 12 changed files with 347 additions and 257 deletions.
14 changes: 11 additions & 3 deletions test-runner/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ import program from 'commander';
import * as fs from 'fs';
import * as path from 'path';
import { collectTests, runTests, RunnerConfig } from '.';
import { reporters } from './reporters';
import { DotReporter } from './reporters/dot';
import { ListReporter } from './reporters/list';
import { JSONReporter } from './reporters/json';

export const reporters = {
'dot': DotReporter,
'list': ListReporter,
'json': JSONReporter
};

program
.version('Version ' + /** @type {any} */ (require)('../package.json').version)
Expand Down Expand Up @@ -66,8 +74,8 @@ program
process.exit(1);
}

const reporterFactory = reporters[command.reporter || 'dot'];
await runTests(config, suite, reporterFactory);
const reporter = new (reporters[command.reporter || 'dot'])();
await runTests(config, suite, reporter);
const hasFailures = suite.eachTest(t => t.error);
process.exit(hasFailures ? 1 : 0);
});
Expand Down
8 changes: 4 additions & 4 deletions test-runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import * as path from 'path';
import './builtin.fixtures';
import './expect';
import { registerFixture as registerFixtureT, registerWorkerFixture as registerWorkerFixtureT } from './fixtures';
import { reporters } from './reporters';
import { Reporter } from './reporter';
import { Runner } from './runner';
import { RunnerConfig } from './runnerConfig';
import { Suite, Test } from './test';
import { Matrix, TestCollector } from './testCollector';
import { installTransform } from './transform';
export { parameters, registerParameter } from './fixtures';
export { Reporter } from './reporter';
export { RunnerConfig } from './runnerConfig';
export { Suite, Test } from './test';

Expand Down Expand Up @@ -76,11 +77,10 @@ export function collectTests(config: RunnerConfig, files: string[]): Suite {
return testCollector.suite;
}

export async function runTests(config: RunnerConfig, suite: Suite, reporterFactory: any) {
export async function runTests(config: RunnerConfig, suite: Suite, reporter: Reporter) {
// Trial run does not need many workers, use one.
const jobs = (config.trialRun || config.debug) ? 1 : config.jobs;
const runner = new Runner(suite, { ...config, jobs });
new reporterFactory(runner);
const runner = new Runner(suite, { ...config, jobs }, reporter);

try {
for (const f of beforeFunctions)
Expand Down
27 changes: 27 additions & 0 deletions test-runner/src/reporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { RunnerConfig } from './runnerConfig';
import { Suite, Test } from './test';

export interface Reporter {
onBegin(config: RunnerConfig, suite: Suite): void;
onTest(test: Test): void;
onPending(test: Test): void;
onPass(test: Test): void;
onFail(test: Test): void;
onEnd(): void;
}
234 changes: 0 additions & 234 deletions test-runner/src/reporters.ts

This file was deleted.

Loading

0 comments on commit baa6b64

Please sign in to comment.