Dedicated Mode
The way this library works by default is it spins up a server for each request, as well as handles its graceful shutdown.
To speed up your tests and reduce the number of instances spawned in huge code bases, you can make use of
the dedicated
false.
// Import and create Sage request assistant instance with the dedicated mode enabledimport { request } from 'sagetest';
const app = getMyExpressApp();// Server is launched right hereconst requestDedicated = request(app, { dedicated: true });
Because of that, you’ll have to manually shut down this server after all tests are done.
describe('My Test Suite', () => { afterAll(async () => { // Server is shut down right here await requestDedicated.shutdown(); });
it('should request', async () => { const res = await requestDedicated.get('/').auth('user', 'pass');
expect(res.statusCode).toBe(200); });});
You can also use alias dedicated to avoid passing dedicated: true flag every time.
// Import and create Sage request assistant instance with the dedicated mode enabledimport { dedicated } from 'sagetest';
const app = getMyExpressApp();// Server is launched right hereconst request = dedicated(app);// Ready to use!