complete tests

This commit is contained in:
Timo Hocker
2019-12-11 09:56:39 +01:00
parent 3c5bf74581
commit e9cd5d8068
21 changed files with 70 additions and 8 deletions
+5 -6
View File
@@ -11,12 +11,11 @@ module.exports = function (app, modulefolder, opts) {
for (const f of fs.readdirSync(modulefolder)) {
const regex = /(.*?)-(.*?)\.js/;
let [, method, url] = regex.exec(f);
url =
'/' +
url
.replace(/^root/i, '')
.replace(/\./g, '/')
.replace(/\/+/g, '/');
url = '/' + url + '/';
url = url
.replace(/^\/root/i, '/')
.replace(/\./g, '/')
.replace(/\/+/g, '/');
const handler = require(('./' + modulefolder + '/' + f)
.replace(/\/\.\//g, '/')
+29 -2
View File
@@ -1,4 +1,4 @@
const { describe, it } = require('mocha');
const { describe, it, beforeEach } = require('mocha');
const expect = require('chai').expect;
const requestor = require('../index');
@@ -23,8 +23,12 @@ const mock = {
};
describe('requestor', () => {
beforeEach(() => {
mock.registered = {};
});
it('should detect all requests on root', () => {
requestor(mock, './test/onroot', {});
requestor(mock, './test/root', {});
expect(mock.registered).to.have.all.keys([
'post-/',
'get-/',
@@ -33,4 +37,27 @@ describe('requestor', () => {
'all-/'
]);
});
it('should detect requests on root.subfolder', () => {
requestor(mock, './test/root.sub', {});
expect(mock.registered).to.have.all.keys([
'post-/sub/',
'get-/sub/',
'put-/sub/',
'delete-/sub/',
'all-/sub/'
]);
});
it('should detect requests on subfolder', () => {
requestor(mock, './test/sub', {});
expect(mock.registered).to.have.all.keys([
'post-/sub/',
'get-/sub/',
'put-/sub/',
'delete-/sub/',
'all-/sub/',
'get-/sub/lv1/lv2/lv3/'
]);
});
});
+3
View File
@@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};
View File
+3
View File
@@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};