npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cypress-redirect-browser-log

v1.3.0

Published

Will connect to **chrome** debugging protocol and redirect logs to node process

Downloads

1,432

Readme

cypress-redirect-browser-log

Will connect to chrome debugging protocol and redirect logs to node process

Will redirect browser console events like:

  • console API events
  • uncaught exceptions
  • browser console events

Install:

npm i --save-dev cypress-redirect-browser-log

Requires Cypress >11.x as peer dependency

Setup

1. Set environment variable

Logs will be redirected to node console when environment variable REDIRECT_BROWSER_LOG is set to true.

2. Setup plugins

You need to add redirectLog(on, config); into your plugins file.

See example of the simplest configuration:

// cypress.config.ts
import { redirectLog } from 'cypress-redirect-browser-log/plugins';

export default defineConfig({
  e2e: {
    // ...
    setupNodeEvents(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) {
      redirectLog(on, config);
    
      //... other existing configrations
    
      return config;
    }
  }
});

For more options see advanced section below.

3. Setup support (e2e.ts)

To see logs from tests put this into your support file (e2e.ts or support/index.ts)

// support/index.ts or where is support located (e2e.ts)
import { redirectTestLogs } from 'cypress-redirect-browser-log';

redirectTestLogs({
  isLogCommandDetails: false,
});
  • isLogCommandDetails: set to true to see all commands with details from test

To disable logs from tests you can setup plugins as follows:

// disable test log
redirectLog(on, config, handler => {
  handler.on('test:log', () => {
    // ignore 
  });
});

// or specify only events you want to see
redirectLog(on, config, ['excpetion', 'error', 'log', 'warn']);

4. Run tests

Run tests with --browser chrome --headless (for electron logs will not be redirected)

5. That's it

You'll see logs in node console like:

FROM CHROME >> 2023-06-06T07:12:01.046Z |     test | ======== TEST STARTED: test integration should be no details for commands
FROM CHROME >> 2023-06-06T07:12:01.148Z |     test | command: route ->
FROM CHROME >> 2023-06-06T07:12:01.166Z |     test | command: visit -> mytest.com
FROM CHROME >> 2023-06-06T07:12:01.438Z |      log | LOG FROM APPLICATION!!
FROM CHROME >> 2023-06-06T07:12:01.438Z |  warning | WARN FROM APPLICATION!!
FROM CHROME >> 2023-06-06T07:12:01.438Z |  warning |     at http://localhost:58040/mytest.com:23:16 (<no functionName>)
FROM CHROME >> 2023-06-06T07:12:01.438Z |    error | ERROR FROM APPLICATION!!
FROM CHROME >> 2023-06-06T07:12:01.438Z |    error |     at http://localhost:58040/mytest.com:24:16 (<no functionName>)
FROM CHROME >> 2023-06-06T07:12:01.466Z |     test | command: get -> div
FROM CHROME >> 2023-06-06T07:12:01.486Z |     test | command: assert -> expected [ <div>, 1 more... ] to exist in the DOM
FROM CHROME >> 2023-06-06T07:12:01.504Z |     test | ==== TEST RESULT: PASSED

:tada:

For your own log events and formatting see advanced

Advanced

With default configuration you will see logs from events : exception, error, warn, log, debug, test:log.

Showing only specific events

  • If you need to show for example only errors and exceptions in plugins add one more argument:

    // will show only errors in excpetions
    redirectLog(on, config, ['error', 'exception']);
  • If you want to create your own message (or do anything you want with result):

    // will override output of errors and excpetions
    redirectLog(on, config, handler => {
      handler.on('error', res => {
        console.error(res.message);
      });
           
      handler.on('exception', res => { 
        console.error(res.message);
      });
    });
  • If you want to show default log for specific events and own messages:

        // will show all from test logs and your errors and exceptions
        redirectLog(on, config, ['test:log'], handler => {
            handler.on('error', res => {
              console.error(res.message);
            });
            handler.on('exception', res => {
              console.error(res.message);
            });
          });

Handling before:browser:launch

if you need to handle 'before:browser:launch' you can use this configuration :

  const browserHandler = redirectLogBrowser(config);
  
  on('before:browser:launch', (browser: Browser, browserLaunchOptions: BrowserLaunchOptions) => {
    // your other browser handling
    return browserHandler(browser, browserLaunchOptions);
  });

redirectLogBrowser accepts similar overloads as redirectLog

Contribution

  • [x] typescript
  • [x] code coverage for cypress and jest, merge coverage
  • [x] formatting and eslint
  • [x] jest tests
  • [x] log uncaught exceptions from your Application
  • [ ] todo to file
  • [ ] todo config
  • [ ] todo docs