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

codeceptjs-resources-check

v0.4.0

Published

Load with puppeteer a url and listen the request during while the page is loading.

Downloads

12

Readme

npm install codeceptjs-resources-check

codeceptjs-resources-check

Codeceptjs helper. Load a URL with Puppeteer and listen to the requests while the page is loading.

Usage

Run a browser with puppeteer and spy the resources loaded in a specific url. You can ask questions about these resources later on.

I.spyTheResourcesLoadedIn(url)

Open a new tab in the browser, listen to the resources the page asks for until it is fully loaded. Close the tab.

startSpyTheResources

Start to listen the resources in the last tab open.

I.checkTheNumberOfResources(number)

Check that the page loads the exact number of resources.

I.checkTheResourceSize(pattern, expectedSize)

Check that the page only calls for one resource that matches with the pattern and has expectedSize while taking in consideration a threshold that you can set up in the helper configuration.

I.checkTheResourcesSize(pattern, expectedSize)

Check that the sum of all sizes of the resources that match with the pattern and has expectedSize while taking in consideration a threshold that you can set up in the helper configuration.

I.checkTheResourceTypeSize(contentType, expectedSize)

Check that the sum of all sizes of the resources have a specific contentType and has expectedSize while taking in consideration a threshold that you can set up in the helper configuration.

I.checkAllResourcesSize(expectedSize)

Check that the sum of all sizes of the resources has expectedSize while taking in consideration a threshold that you can set up in the helper configuration.

I.checkTheNumberOfResource(pattern, expectedNumber)

Check that the number of the resources that match with a specific pattern is expectedNumber.

I.checkTheNumberOfResourceType(contentType, expectedNumber)

Check that the number of the resources that have a specific contentType is expectedNumber.

Config:

You can add these lines into your codecept.conf.js

  helpers: {
    CodeceptjsResourcesCheck: {
      require: 'codeceptjs-resources-check',
      threshold: 0.2
    }
  },

threshold by default is 0.

Example of usage in a Scenario:

Scenario('test something', async (I) => {

    // You have lunch the brower, maybe in your before step 
    const browser = await puppeteer.launch();

    I.spyTheResourcesLoadedIn('https://stackoverflow.com/');

    I.checkTheNumberOfResources(49);

    // I.checkTheResourceSize(/vendor-[A-Za-z0-9]{20}\.js/, 248524);
    I.checkTheResourceSize(/full-anon/, 67707);

    I.checkTheResourcesSize(/\.js$/, 67707);

    I.checkTheResourceTypeSize('text/css', 104525);
    I.checkAllResourcesSize(387616);

    I.checkTheNumberOfResourceType('text/javascript', 1);

    // Remember to close your browser, maybe in your after step 
    await browser.close();
});

Another example

Scenario('test something 2', async (I) => {
    I.openNewTab();
    I.emulateIPhone();

    I.startSpyTheResources();

    I.amOnPage('https://stackoverflow.com/')

    I.checkTheNumberOfResources(51);

	// I.checkTheResourceSize(/vendor-[A-Za-z0-9]{20}\.js/, 248524);
    I.checkTheResourceSize(/full-anon/, 67707);

    I.checkTheResourcesSize(/\.js$/, 67707);

	I.checkTheResourceTypeSize('text/css', 104525);
	I.checkAllResourcesSize(387616);

	I.checkTheNumberOfResourceType('text/javascript', 1);
});