fix(test-runner): do not list tests to stdout when JSON reporter is used (#7730)

This commit is contained in:
Max Schmitt 2021-07-20 01:10:43 +02:00 committed by GitHub
parent 8eab2d0e5b
commit c84c5c8c9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 5 deletions

View File

@ -62,12 +62,12 @@ export class Runner {
this._loader = new Loader(defaultConfig, configOverrides);
}
private async _createReporter() {
private async _createReporter(list: boolean) {
const reporters: Reporter[] = [];
const defaultReporters = {
dot: DotReporter,
line: LineReporter,
list: ListReporter,
dot: list ? ListModeReporter : DotReporter,
line: list ? ListModeReporter : LineReporter,
list: list ? ListModeReporter : ListReporter,
json: JSONReporter,
junit: JUnitReporter,
null: EmptyReporter,
@ -93,7 +93,7 @@ export class Runner {
}
async run(list: boolean, filePatternFilters: FilePatternFilter[], projectName?: string): Promise<RunResultStatus> {
this._reporter = list ? new ListModeReporter() : await this._createReporter();
this._reporter = await this._createReporter(list);
const config = this._loader.fullConfig();
const globalDeadline = config.globalTimeout ? config.globalTimeout + monotonicTime() : undefined;
const { result, timedOut } = await raceAgainstDeadline(this._run(list, filePatternFilters, projectName), globalDeadline);

View File

@ -41,3 +41,26 @@ test('should list tests', async ({ runInlineTest }) => {
`Total: 4 tests in 1 file`
].join('\n'));
});
test('should not list tests to stdout when JSON reporter is used', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { projects: [{ name: 'foo' }, {}] };
`,
'a.test.js': `
const { test } = pwt;
test('example1', async ({}) => {
expect(1 + 1).toBe(2);
});
test('example2', async ({}) => {
expect(1 + 1).toBe(2);
});
`
}, { 'list': true, 'reporter': 'json' });
expect(result.exitCode).toBe(0);
expect(result.output).not.toContain('Listing tests');
expect(result.report.config.projects.length).toBe(2);
expect(result.report.suites.length).toBe(1);
expect(result.report.suites[0].specs.length).toBe(2);
expect(result.report.suites[0].specs.map(spec => spec.title)).toStrictEqual(['example1', 'example2']);
});