complete tests
This commit is contained in:
parent
3c5bf74581
commit
e9cd5d8068
11
index.js
11
index.js
@ -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, '/')
|
||||
|
31
test/main.js
31
test/main.js
@ -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
test/root/all-root.js
Normal file
3
test/root/all-root.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = (req, res, next, opts) => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
3
test/root/delete-root.js
Normal file
3
test/root/delete-root.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = (req, res, next, opts) => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
3
test/root/get-root.js
Normal file
3
test/root/get-root.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = (req, res, next, opts) => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
3
test/root/not-root.js
Normal file
3
test/root/not-root.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = (req, res, next, opts) => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
3
test/root/post-root.js
Normal file
3
test/root/post-root.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = (req, res, next, opts) => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
3
test/root/put-root.js
Normal file
3
test/root/put-root.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = (req, res, next, opts) => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
3
test/sub/all-sub.js
Normal file
3
test/sub/all-sub.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = (req, res, next, opts) => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
3
test/sub/delete-sub.js
Normal file
3
test/sub/delete-sub.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = (req, res, next, opts) => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
3
test/sub/get-sub.js
Normal file
3
test/sub/get-sub.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = (req, res, next, opts) => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
0
test/sub/get-sub.lv1.lv2.lv3.js
Normal file
0
test/sub/get-sub.lv1.lv2.lv3.js
Normal file
3
test/sub/not-sub.js
Normal file
3
test/sub/not-sub.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = (req, res, next, opts) => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
3
test/sub/post-sub.js
Normal file
3
test/sub/post-sub.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = (req, res, next, opts) => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
3
test/sub/put-sub.js
Normal file
3
test/sub/put-sub.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = (req, res, next, opts) => {
|
||||
// dummy endpoint: do nothing
|
||||
};
|
Reference in New Issue
Block a user