Get unlimited public & private packages + team-based management with npm Teams.Learn more »

puppyjs

1.2.24 • Public • Published

PuppyJS | Docs 📓

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.

Install

npm i puppyjs

DownloadsWeekly Downloads

2

Version

1.2.24

License

MIT

Unpacked Size

64.1 kB

Total Files

48

Last publish

Collaborators

  • avatar
  • avatar
  • avatar