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

taiko-diagnostics

v0.4.0

Published

A plugin for taiko which provides some diagnostics features

Downloads

15,251

Readme

Build Status npm versionGreenkeeper badge CodeFactor

NPM

taiko-diagnostics

A plugin for taiko which provides some diagnostics features like measuring speedindex, performance metrics of webpage.

Installation

  • npm install taiko-diagnostics --save

Usage

import { openBrowser, goto, closeBrowser, diagnostics } from 'taiko';
const {
  startTracing,
  startCssTracing,
  stopCssTracing,
  endTracing,
  getSpeedIndex,
  getPerformanceMetrics
} = diagnostics;

jest.setTimeout(30000);
beforeEach(async () => {
  await openBrowser();
});

afterEach(async () => {
  await closeBrowser();
});

test('Should return speedindex and perceptualSpeedIndex', async () => {
  await startTracing();
  await goto('https://github.com/');
  await endTracing();
  const { speedIndex, perceptualSpeedIndex } = await getSpeedIndex();
  expect(speedIndex).toBeTruthy();
  expect(perceptualSpeedIndex).toBeTruthy();
});

startTracing() Command

Start tracing the browser. Tracing could be started only once per browser.

startTracing();

endTracing Command

Stop tracing the browser.

endTracing();

getTracingLogs Command

Returns the tracelogs that was captured within the tracing period. You can use this command to store the trace logs on the file system to analyse the trace via Chrome DevTools interface.

startTracing();
goto('https://github.com/');
endTracing();

fs.writeFileSync(
  '/path/to/tracelog.json',
  JSON.stringify(await getTracingLogs())
);

getSpeedIndex Command

Returns the Speed Index and Perceptual Speed Index from the page load that happened between the tracing period.

startTracing();
goto('https://github.com/');
endTracing();

console.log(getSpeedIndex());
// outputs
// { speedIndex: 789.6634800064564,
//   perceptualSpeedIndex: 876.0901860232523 }

getPerformanceMetrics Command

startTracing();
goto('https://github.com/');
endTracing();

console.log(getPerformanceMetrics());
// outputs
//{
//    firstPaint: 735.666,
//    firstContentfulPaint: 735.669,
//    firstMeaningfulPaint: 735.671,
//    domContentLoaded: 574.546,
//    timeToFirstInteractive: 735.671,
//    load: 1379.895
//    }

getCssCoverage Command

startCssTracing();
goto('https://unused-css-example-site-qijunirqpu.now.sh');
const cssCoverage = await stopCssTracing();
//[ { url: 'https://unused-css-example-site-qijunirqpu.now.sh/main.css',
//        type: 'CSS',
//        totalBytes: 1453,
//        usedBytesTotal: 653,
//        unusedBytesTotal: 800,
//       usedPercentage: 44.941500344115624,
//        unusedPercentage: 55.058499655884376 } ]

Coverage tab

Pretty print cssCoverage in table

await prettyCSS(coverage);

CSS Table

logConsoleInfo command

const error = [];
  let emitter = await logConsoleInfo();
  emitter.on('pageError', e => { // Other emitters - logEntry, consoleLog
    error.push(e);
  });

await goto('gauge.org/sdfsd');
Make sure not to add `await` as logConsoleInfo enables log Listener.

//{
//"source":"network",
//"level":"error",
//"text":"Failed to load resource: the server responded with a status of 404 ()",
//"timestamp":1553288625400,
//"url":"https://gauge.org/sdfsd",
//"networkRequestId":"D56332F8080344A2696C18D0771EC383"
//}

Use in Taiko REPL

To launch the REPL type taiko --plugin taiko-diagnostics in your favorite terminal application. This will launch the Taiko Prompt.

e.g Version: 0.7.0 (Chromium:74.0.3723.0) Type .api for help and .exit to quit

You should now have full access to all of the diagnostics in the taiko REPL window

REPL example

> openBrowser()
 ✔ Browser opened
> startTracing()
 ✔ Browser tracing started
> goto('https://github.com/');
 ✔ Navigated to url "https://github.com/"
> endTracing();
 ✔ Browser tracing ended
> getSpeedIndex();
{ speedIndex: 30631.375729995667,
  perceptualSpeedIndex: 30634.177980202476 }
> getPerformanceMetrics();
info Detected renderer thread by 'TracingStartedInBrowser' event: pid 69317, tid 775
{ firstPaint: 834.819,
  firstContentfulPaint: 834.821,
  firstMeaningfulPaint: 997.381,
  domContentLoaded: 1073.878,
  timeToFirstInteractive: 1194.132,
  load: 1208.64 }

Note that startTracing,endTracing, and getSpeedIndex apis are not from taiko. These are given by the plugin.