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

puppyjs

v1.2.24

Published

puppeteer + jest + awesome-code = puppyjs

Downloads

78

Readme

PuppyJS | Docs :notebook:

js-standard-style npm npm GitHub last commit (branch) CircleCI branch

Puppeteer + Jest + awesome-code = Puppy.JS

PuppyJS is a framework agnostic E2E (end-to-end) testing and mocking tool for front end developers. Puppy depends on Jest for tests and Puppeteer for the testing environment so if you know these tools then you already know 80% of Puppy.

Puppy also lets you mock HTTP APIs and web socket events so you can develop your application until the backend is ready as well as run your E2E tests against the same mock API and socket events you used for development.

Getting Started

Install

npm install puppyjs --save-dev

Install globally

npm install puppyjs --global

Get some help

puppy --help

Run mocking servers

puppy serve

Run tests

puppy test

Sample directory structure

Below you can find a sample directory structure. The important thing to notice are the puppy.api.js, puppy.ws.js and puppy.config.js and that they are at the root level of the directory.

.
|
├── puppy.config.js <optional>
├── puppy.api.js <optional>
├── puppy.ws.js <optional>
|
├── package.json
|
├── dist
|   ├── background.jpg
|   ├── index.html
|   └── fonts
|
└── tests
    ├── users.pup.js
    └── notifications.pup.js

puppy.api.js

Sample:

module.exports = {
  '/api/users': {
    'GET': {
      headers: {
        'Authorization': 'Bearer some-token'
      },
      status: 200,
      body: 'hello its a GET'
    }
  }
}

puppy.ws.js

Sample:

module.exports = {
  'notification': {
      delay: 1000,
      interval: 1000,
      message: [
        {seen: false, createdAt: Date.now(), text: 'I am a notification'}
      ]
    }
}

puppy.config.js

Sample:

module.exports = {
    port: 1337
}

Your first End-to-End test

Underneath, Puppy uses Jest for asserting and Puppeteer for executing actions in the browser. Please head to their documentation if you are not familiar. In the example below it assumes a file index.html inside src folder and a file with any name but ends with .pup.js which will hold the test.

describe('test', () => {
  let page
  
  it('check that puppy works', async () => {
      page = await puppy.newPage('http://localhost:1337/src/index.html') // page instance is a puppeteer page instance
      
      ... your code
      
      expect(...) // Jest
  })
})

To run this use the command

puppy test

Puppy Development Mock Server

You can use the same puppy.api.js file that you configure above for development purpose. Run puppy serve and you can now make a GET request to /api/users and get a reply back as set in the puppy.api.js file.