export function filterBrowserMessages()

in src/plugins/browser-console.ts [97:122]


export function filterBrowserMessages(
  messages: BrowserMessage[],
  status: StatusValue
) {
  if (status == 'skipped') {
    return [];
  } else if (status === 'failed' || messages.length <= SUCCESSFUL_MSG_LIMIT) {
    return messages;
  }
  // collect 100 messages from the browser console when the test is successful,
  // giving priority to errors and warnings
  const result = messages.filter(msg => msg.type === 'error');
  if (result.length >= SUCCESSFUL_MSG_LIMIT) {
    return result.slice(-SUCCESSFUL_MSG_LIMIT);
  }

  // collect warnings
  result.push(...messages.filter(msg => msg.type === 'warning'));
  if (result.length >= SUCCESSFUL_MSG_LIMIT) {
    return result.slice(-SUCCESSFUL_MSG_LIMIT);
  }

  // collect logs
  result.push(...messages.filter(msg => msg.type === 'log'));
  return result.slice(-SUCCESSFUL_MSG_LIMIT);
}