axe-playwright icon indicating copy to clipboard operation
axe-playwright copied to clipboard

Add log level functionality

Open yannbf opened this issue 2 years ago • 2 comments

Hey, we've been using this lib in our project and that is great! However when there are no violations, I'd rather not have any logs. When looking at the results of the tests, there is quite some noise added there. Would it be possible to either remove the log (no error logs should mean success), or add a log level so that these logs only appear when set to "verbose" or something like that?

image

Thank you!

yannbf avatar Apr 07 '22 09:04 yannbf

Hey @yannbf, came here with the exact same headache, but realized that the default reporter is just that – a default, and can be switched out to one's own implementation (as a positional argument to checkA11y).

Doesn't take away from the validity in having a better default as in #96, but just in case you missed it like I did!

Example:

class SilentOnSuccessReporter {
  async report(violations) {
    const violationData = violations.map(({ id, impact, description, nodes }) => {
      return {
        id,
        impact,
        description,
        nodes: nodes.length,
      }
    })

    if (violationData.length > 0) {
      console.table(violationData)
    }
  }
};

...used like:

const reporter = new SilentOnSuccessReporter();
checkA11y(page, '#my-selector', { some: options }, false, reporter);

emilbjorklund avatar Jun 07 '22 12:06 emilbjorklund

@emilbjorklund while this does work, sadly the types for checkA11y aren't updated correctly for this. See https://github.com/abhinaba-ghosh/axe-playwright/blob/master/index.d.ts#L58-L63

export function checkA11y(
  page: Page,
  context?: ElementContext,
  options?: Options,
  skipFailures?: boolean,
  // ... Reporter missing here
): Promise<void>

Kosai106 avatar Aug 10 '22 16:08 Kosai106