Pactum and Fastify #101
-
Is it possible to use Pactum against a Fastify server, in the manner of Supertest or the Fastify manual-recommended way, without having the server running? Currently ever test file is starting a server, and when run in parallel, of course the port is taken. Varying the server port seems the wrong with to go. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Hi 👋, Can you let me know which test runner are you using? Ex: add a const server = require('./path-to-fastify-server');
// global hooks
before( () => {
server.start(); // start fastify server before tests
});
after( () => {
server.stop(); // if implemented for graceful shutdown
}); Hope this helps! Edited (07/02/22)Use this package - https://www.npmjs.com/package/pactum-supertest |
Beta Was this translation helpful? Give feedback.
Hi 👋,
Can you let me know which test runner are you using?
Does your setup require you to run server instances for every test? If not (assuming you might be using mocha), you can start your fastify server in a
before()
and stop it in anafter()
global hooks of mocha. This way you just have to run one instance of your server before all tests begin on a single port.Ex: add a
base.spec.js
Hope this helps!
Edited (07/02/22)
Use this package - https://www.npmjs.com/package/pa…