PuppyJS | Docs 📓
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
puppy --help
puppy serve
puppy test
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
Sample:
module.exports = {
'/api/users': {
'GET': {
headers: {
'Authorization': 'Bearer some-token'
},
status: 200,
body: 'hello its a GET'
}
}
}
Sample:
module.exports = {
'notification': {
delay: 1000,
interval: 1000,
message: [
{seen: false, createdAt: Date.now(), text: 'I am a notification'}
]
}
}
Sample:
module.exports = {
port: 1337
}
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('https://localhost:1337/src/index.html') // page instance is a puppeteer page instance
... your code
expect(...) // Jest
})
})
To run this use the command
puppy test
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.