complete tests
This commit is contained in:
@@ -11,10 +11,9 @@ module.exports = function (app, modulefolder, opts) {
|
|||||||
for (const f of fs.readdirSync(modulefolder)) {
|
for (const f of fs.readdirSync(modulefolder)) {
|
||||||
const regex = /(.*?)-(.*?)\.js/;
|
const regex = /(.*?)-(.*?)\.js/;
|
||||||
let [, method, url] = regex.exec(f);
|
let [, method, url] = regex.exec(f);
|
||||||
url =
|
url = '/' + url + '/';
|
||||||
'/' +
|
url = url
|
||||||
url
|
.replace(/^\/root/i, '/')
|
||||||
.replace(/^root/i, '')
|
|
||||||
.replace(/\./g, '/')
|
.replace(/\./g, '/')
|
||||||
.replace(/\/+/g, '/');
|
.replace(/\/+/g, '/');
|
||||||
|
|
||||||
|
|||||||
+29
-2
@@ -1,4 +1,4 @@
|
|||||||
const { describe, it } = require('mocha');
|
const { describe, it, beforeEach } = require('mocha');
|
||||||
const expect = require('chai').expect;
|
const expect = require('chai').expect;
|
||||||
|
|
||||||
const requestor = require('../index');
|
const requestor = require('../index');
|
||||||
@@ -23,8 +23,12 @@ const mock = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe('requestor', () => {
|
describe('requestor', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mock.registered = {};
|
||||||
|
});
|
||||||
|
|
||||||
it('should detect all requests on root', () => {
|
it('should detect all requests on root', () => {
|
||||||
requestor(mock, './test/onroot', {});
|
requestor(mock, './test/root', {});
|
||||||
expect(mock.registered).to.have.all.keys([
|
expect(mock.registered).to.have.all.keys([
|
||||||
'post-/',
|
'post-/',
|
||||||
'get-/',
|
'get-/',
|
||||||
@@ -33,4 +37,27 @@ describe('requestor', () => {
|
|||||||
'all-/'
|
'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/'
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res, next, opts) => {
|
||||||
|
// dummy endpoint: do nothing
|
||||||
|
};
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res, next, opts) => {
|
||||||
|
// dummy endpoint: do nothing
|
||||||
|
};
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res, next, opts) => {
|
||||||
|
// dummy endpoint: do nothing
|
||||||
|
};
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res, next, opts) => {
|
||||||
|
// dummy endpoint: do nothing
|
||||||
|
};
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res, next, opts) => {
|
||||||
|
// dummy endpoint: do nothing
|
||||||
|
};
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res, next, opts) => {
|
||||||
|
// dummy endpoint: do nothing
|
||||||
|
};
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res, next, opts) => {
|
||||||
|
// dummy endpoint: do nothing
|
||||||
|
};
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res, next, opts) => {
|
||||||
|
// dummy endpoint: do nothing
|
||||||
|
};
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res, next, opts) => {
|
||||||
|
// dummy endpoint: do nothing
|
||||||
|
};
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res, next, opts) => {
|
||||||
|
// dummy endpoint: do nothing
|
||||||
|
};
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res, next, opts) => {
|
||||||
|
// dummy endpoint: do nothing
|
||||||
|
};
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res, next, opts) => {
|
||||||
|
// dummy endpoint: do nothing
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user