Agent Node JS Testing Library
This library provides a set of utilities for testing Node JS agents.
It's only available for Node JS agents.
It is in alpha version and is subject to breaking changes.
For the moment, it only provides an incomplete set of utilities for integration and unit testing, but it will be
extended in the future.
Installation
npm install @forestadmin-experimental/agent-nodejs-testing
or for Yarn users:
yarn add @forestadmin-experimental/agent-nodejs-testing
Integration Tests
Setup
const { createTestableAgent } = require('@forestadmin-experimental/agent-nodejs-testing');
export function addAgentCustomizations(agent) {
agent.addDataSource(createSequelizeDataSource(connection));
};
export async function setupAndStartTestableAgent() {
const testableAgent = await createTestableAgent();
addAgentCustomizations(testableAgent.agent);
await testableAgent.start();
return testableAgent;
}
Usage
describe('billing collection', () => {
let agent;
beforeAll(async () => {
agent = await setupAndStartTestableAgent();
});
afterAll(async () => {
await agent?.stop();
});
it('should return all the records of the billing collection', async () => {
const result = await agent.collection('billing').list();
expect(result).toHaveLength(2);
});
});
Unit Tests
WIP