chore: create list reporter for watch mode directly (#22614)

This commit is contained in:
Yury Semikhatsky 2023-04-24 18:32:32 -07:00 committed by GitHub
parent 24478be565
commit 59678fdea7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 20 deletions

View File

@ -31,7 +31,7 @@ import type { BuiltInReporter, FullConfigInternal } from '../common/config';
import { loadReporter } from './loadUtils';
import { BlobReporter } from '../reporters/blob';
export async function createReporter(config: FullConfigInternal, mode: 'list' | 'watch' | 'run' | 'ui', additionalReporters: Reporter[] = []): Promise<Multiplexer> {
export async function createReporter(config: FullConfigInternal, mode: 'list' | 'run' | 'ui', additionalReporters: Reporter[] = []): Promise<Multiplexer> {
const defaultReporters: {[key in BuiltInReporter]: new(arg: any) => Reporter} = {
dot: mode === 'list' ? ListModeReporter : DotReporter,
line: mode === 'list' ? ListModeReporter : LineReporter,
@ -44,25 +44,21 @@ export async function createReporter(config: FullConfigInternal, mode: 'list' |
blob: BlobReporter,
};
const reporters: Reporter[] = [];
if (mode === 'watch') {
reporters.push(new ListReporter());
} else {
for (const r of config.config.reporter) {
const [name, arg] = r;
const options = { ...arg, configDir: config.configDir };
if (name in defaultReporters) {
reporters.push(new defaultReporters[name as keyof typeof defaultReporters](options));
} else {
const reporterConstructor = await loadReporter(config, name);
reporters.push(new reporterConstructor(options));
}
}
reporters.push(...additionalReporters);
if (process.env.PW_TEST_REPORTER) {
const reporterConstructor = await loadReporter(config, process.env.PW_TEST_REPORTER);
reporters.push(new reporterConstructor());
for (const r of config.config.reporter) {
const [name, arg] = r;
const options = { ...arg, configDir: config.configDir };
if (name in defaultReporters) {
reporters.push(new defaultReporters[name as keyof typeof defaultReporters](options));
} else {
const reporterConstructor = await loadReporter(config, name);
reporters.push(new reporterConstructor(options));
}
}
reporters.push(...additionalReporters);
if (process.env.PW_TEST_REPORTER) {
const reporterConstructor = await loadReporter(config, process.env.PW_TEST_REPORTER);
reporters.push(new reporterConstructor());
}
const someReporterPrintsToStdio = reporters.some(r => {
const prints = r.printsToStdio ? r.printsToStdio() : true;

View File

@ -26,7 +26,6 @@ import { clearCompilationCache, collectAffectedTestFiles } from '../common/compi
import type { FullResult } from 'packages/playwright-test/reporter';
import { chokidar } from '../utilsBundle';
import type { FSWatcher as CFSWatcher } from 'chokidar';
import { createReporter } from './reporters';
import { colors } from 'playwright-core/lib/utilsBundle';
import { enquirer } from '../utilsBundle';
import { separator } from '../reporters/base';
@ -113,7 +112,7 @@ export async function runWatchModeLoop(config: FullConfigInternal): Promise<Full
p.project.retries = 0;
// Perform global setup.
const reporter = await createReporter(config, 'watch');
const reporter = new Multiplexer([new ListReporter()]);
const testRun = new TestRun(config, reporter);
const taskRunner = createTaskRunnerForWatchSetup(config, reporter);
reporter.onConfigure(config);