Skip to content

Commit

Permalink
feat: update summary reporter to include browser name
Browse files Browse the repository at this point in the history
  • Loading branch information
castastrophe authored and LarsDenBakker committed Aug 5, 2022
1 parent 7834ace commit 13b75cf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-ties-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@web/test-runner': minor
---

Add browser name to summaryReporter output
35 changes: 21 additions & 14 deletions packages/test-runner/src/reporter/summaryReporter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { Reporter, ReporterArgs, TestSuiteResult } from '@web/test-runner-core';
import type {
BrowserLauncher,
Reporter,
ReporterArgs,
TestSuiteResult,
} from '@web/test-runner-core';

import { reportTestsErrors } from './reportTestsErrors.js';
import { reportTestFileErrors } from './reportTestFileErrors.js';
Expand All @@ -16,6 +21,7 @@ const color =
const reset = `\x1b[0m\x1b[0m`;
const green = color([32, 89]);
const red = color([31, 89]);
const dim = color([2, 0]);

/** Test reporter that summarizes all test for a given run */
export function summaryReporter(opts: Options): Reporter {
Expand All @@ -25,29 +31,30 @@ export function summaryReporter(opts: Options): Reporter {

const logger = new TestRunnerLogger();

function log(name: string, passed: boolean, prefix = ' ') {
function log(name: string, passed: boolean, prefix = ' ', postfix = '') {
const sign = passed ? green('✓') : red('𐄂');
logger.log(flatten ? `${sign} ${prefix} ${name}` : `${prefix} ${sign} ${name}`);
if (flatten) logger.log(`${sign} ${prefix} ${name}${postfix}`);
else logger.log(`${prefix} ${sign} ${name}`);
}

function logResults(results?: TestSuiteResult, prefix?: string) {
function logResults(results?: TestSuiteResult, prefix?: string, browser?: BrowserLauncher) {
const browserName = browser?.name ? ` ${dim(`[${browser.name}]`)}` : '';
for (const result of results?.tests ?? []) {
log(result.name, result.passed, prefix);
log(result.name, result.passed, prefix, browserName);
}

for (const suite of results?.suites ?? []) {
logSuite(suite, prefix);
logSuite(suite, prefix, browser);
}
}

function logSuite(suite: TestSuiteResult, parent?: string) {
const pref = flatten ? `${parent ? `${parent}` : ''} ${suite.name}` : `${parent ?? ''} `;
function logSuite(suite: TestSuiteResult, parent?: string, browser?: BrowserLauncher) {
const browserName = browser?.name ? ` ${dim(`[${browser.name}]`)}` : '';
let pref = parent ? `${parent} ` : '';
if (flatten) pref += `${suite.name}`;
else logger.log(`${pref}${suite.name}${browserName}`);

if (!flatten) {
logger.log(`${pref}${suite.name}`);
}

logResults(suite, pref);
logResults(suite, pref, browser);
}

return {
Expand All @@ -62,7 +69,7 @@ export function summaryReporter(opts: Options): Reporter {

reportTestFileResults({ sessionsForTestFile: sessions }) {
for (const session of sessions) {
logResults(session.testResults);
logResults(session.testResults, '', session.browser);
logger.log('');
}
},
Expand Down

0 comments on commit 13b75cf

Please sign in to comment.