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.
npm install puppyjs --save-dev
npm install puppyjs --global
Get some help
Run mocking servers
Sample directory structure
Below you can find a sample directory structure. The important thing to notice are the
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
moduleexports ='/api/users':'GET':headers:'Authorization': 'Bearer some-token'status: 200body: 'hello its a GET'
moduleexports ='notification':delay: 1000interval: 1000message:seen: false createdAt: Date text: 'I am a notification'
moduleexports =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
src folder and a file with any name but ends with
.pup.js which will hold the test.
To run this use the command
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