mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(test-runner): do not list tests to stdout when JSON reporter is used (#7730)
This commit is contained in:
parent
8eab2d0e5b
commit
c84c5c8c9b
@ -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);
|
||||
|
@ -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']);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user