@dechamp/express-auto-route
Version:
An express auto route module which allows routes and middleware to be configured via config file.
40 lines (33 loc) • 1.17 kB
text/typescript
import * as path from 'path';
import moduleImporter from '../../../src/moduleImporter';
import appRoot from 'app-root-path';
it('will import module with default basePath', async () => {
const callback = await moduleImporter(`${path.relative(appRoot.toString(), __dirname)}/middleware.ts`);
const req = {
json: jest.fn()
};
const res = {};
const next = () => jest.fn();
await callback(req, res, next);
expect(req.json.mock.calls[0][0]).toEqual({response: 'ran'});
});
it('will import using basePath', async () => {
const callback = await moduleImporter('middleware.ts', __dirname);
const req = {
json: jest.fn()
};
const res = {};
const next = () => jest.fn();
callback(req, res, next);
expect(req.json.mock.calls[0][0]).toEqual({response: 'ran'});
});
it('will import using basePath and relative path', async () => {
const callback = await moduleImporter('./middleware.ts', __dirname);
const req = {
json: jest.fn()
};
const res = {};
const next = () => jest.fn();
callback(req, res, next);
expect(req.json.mock.calls[0][0]).toEqual({response: 'ran'});
});