Skip to content

fix(summaryReporter): add back broken error reporting and make log reporting optional for summaryReporter #2932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tiny-apes-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@web/test-runner': patch
---

Fixed error reporting and made browser logs optional in summary reporter
35 changes: 20 additions & 15 deletions packages/test-runner/src/reporter/summaryReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import type {
import { reportTestsErrors } from './reportTestsErrors.js';
import { reportTestFileErrors } from './reportTestFileErrors.js';

import { TestRunnerLogger } from '../logger/TestRunnerLogger.js';
import { reportBrowserLogs } from './reportBrowserLogs.js';

interface Options {
flatten?: boolean;
reportTestLogs?: boolean;
reportTestErrors?: boolean;
}

const color =
Expand All @@ -26,10 +29,12 @@ const dim = color([2, 0]);

/** Test reporter that summarizes all test for a given run */
export function summaryReporter(opts: Options): Reporter {
const { flatten = false } = opts ?? {};
const { flatten = false, reportTestLogs = true, reportTestErrors = false } = opts ?? {};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't reportTestErrors be made to default to on?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it could be changed so that reportTestErrors is true by default. I was worried that setting it to true would alter the logging of anyone who has already upgraded to use the broken summaryReporter and maybe they are now used to having no report errors at the bottom or have worked around the issue somehow. But maybe this is not a big issue and we can just turn it on by default.

let args: ReporterArgs;
let favoriteBrowser: string;

const testLogger = new TestRunnerLogger();

function log(
logger: Logger,
name: string,
Expand Down Expand Up @@ -80,7 +85,6 @@ export function summaryReporter(opts: Options): Reporter {
logResults(logger, suite, pref, browser);
}

let cachedLogger: Logger;
return {
start(_args) {
args = _args;
Expand All @@ -92,26 +96,27 @@ export function summaryReporter(opts: Options): Reporter {
},

reportTestFileResults({ logger, sessionsForTestFile }) {
cachedLogger = logger;
for (const session of sessionsForTestFile) {
logResults(logger, session.testResults, '', session.browser);
logger.log('');
}
reportBrowserLogs(logger, sessionsForTestFile);
if (reportTestLogs) reportBrowserLogs(logger, sessionsForTestFile);
},

onTestRunFinished({ sessions }) {
const failedSessions = sessions.filter(s => !s.passed);
if (failedSessions.length > 0) {
cachedLogger.log('\n\nErrors Reported in Tests:\n\n');
reportTestsErrors(cachedLogger, args.browserNames, favoriteBrowser, failedSessions);
reportTestFileErrors(
cachedLogger,
args.browserNames,
favoriteBrowser,
failedSessions,
true,
);
if (reportTestErrors) {
const failedSessions = sessions.filter(s => !s.passed);
if (failedSessions.length > 0) {
testLogger.log('\n\nErrors Reported in Tests:\n\n');
reportTestsErrors(testLogger, args.browserNames, favoriteBrowser, failedSessions);
reportTestFileErrors(
testLogger,
args.browserNames,
favoriteBrowser,
failedSessions,
true,
);
}
}
},
};
Expand Down