@contrast/route-coverage 1.35.1 → 1.35.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +10 -7
- package/lib/index.test.js +0 -136
- package/lib/install/express/express4.test.js +0 -418
- package/lib/install/express/express5.test.js +0 -813
- package/lib/install/fastify.test.js +0 -218
- package/lib/install/graphql.test.js +0 -175
- package/lib/install/hapi.test.js +0 -127
- package/lib/install/koa.test.js +0 -152
- package/lib/install/restify.test.js +0 -92
- package/lib/normalized-url-mapper.test.js +0 -50
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const sinon = require('sinon');
|
|
5
|
-
const scopes = require('@contrast/scopes');
|
|
6
|
-
const patcher = require('@contrast/patcher');
|
|
7
|
-
const mocks = require('@contrast/test/mocks');
|
|
8
|
-
|
|
9
|
-
describe('route-coverage restify', function () {
|
|
10
|
-
let core, restify, serverMock, handler, framework;
|
|
11
|
-
|
|
12
|
-
beforeEach(function () {
|
|
13
|
-
core = mocks.core();
|
|
14
|
-
core.logger = mocks.logger();
|
|
15
|
-
core.routeCoverage = mocks.routeCoverage();
|
|
16
|
-
core.scopes = scopes(core);
|
|
17
|
-
core.depHooks = mocks.depHooks();
|
|
18
|
-
core.patcher = patcher(core);
|
|
19
|
-
|
|
20
|
-
handler = sinon.stub();
|
|
21
|
-
serverMock = {
|
|
22
|
-
router: {
|
|
23
|
-
mount (path, method) {
|
|
24
|
-
return {
|
|
25
|
-
path,
|
|
26
|
-
method,
|
|
27
|
-
chain: {
|
|
28
|
-
_stack: [
|
|
29
|
-
handler
|
|
30
|
-
]
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
framework = 'restify';
|
|
38
|
-
restify = {
|
|
39
|
-
createServer: () => serverMock
|
|
40
|
-
};
|
|
41
|
-
core.depHooks.resolve.withArgs({ name: 'restify', version: '>=8 <12' }).yields(restify);
|
|
42
|
-
require('./restify')(core).install();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('does not report a non-existent route', function () {
|
|
46
|
-
const { router } = restify.createServer();
|
|
47
|
-
router.mount();
|
|
48
|
-
expect(core.routeCoverage.discover).not.to.have.been.called;
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('does not report an incomplete route', function () {
|
|
52
|
-
const { router } = restify.createServer();
|
|
53
|
-
router.mount('/foo');
|
|
54
|
-
expect(core.routeCoverage.discover).not.to.have.been.called;
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('does not report an invalid route', function () {
|
|
58
|
-
const { router } = restify.createServer();
|
|
59
|
-
router.mount(42, 'GET');
|
|
60
|
-
expect(core.routeCoverage.discover).not.to.have.been.called;
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('discovers a route', function () {
|
|
64
|
-
const { router } = restify.createServer();
|
|
65
|
-
router.mount('/foo', 'GET');
|
|
66
|
-
|
|
67
|
-
expect(core.routeCoverage.discover).to.have.been.calledWith({
|
|
68
|
-
signature: "server.get('/foo', [Function])",
|
|
69
|
-
url: '/foo',
|
|
70
|
-
normalizedUrl: '/foo',
|
|
71
|
-
method: 'get',
|
|
72
|
-
framework
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('observes a route', async function () {
|
|
77
|
-
const { router } = restify.createServer();
|
|
78
|
-
const route = router.mount('/foo', 'GET');
|
|
79
|
-
const handler = route.chain._stack[0];
|
|
80
|
-
handler({
|
|
81
|
-
url: '/foo?input=bar',
|
|
82
|
-
method: 'GET'
|
|
83
|
-
});
|
|
84
|
-
expect(core.routeCoverage.observe).to.have.been.calledWith({
|
|
85
|
-
signature: "server.get('/foo', [Function])",
|
|
86
|
-
url: '/foo',
|
|
87
|
-
normalizedUrl: '/foo',
|
|
88
|
-
method: 'get',
|
|
89
|
-
framework
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const frameworkRoutingData = require('@contrast/test/data/framework-routing-data');
|
|
5
|
-
const NormalizedUrlMapper = require('./normalized-url-mapper');
|
|
6
|
-
|
|
7
|
-
describe('route-coverage NormalizedUrlMapper', function() {
|
|
8
|
-
const testData = Object.values(frameworkRoutingData()).flatMap((a) => a);
|
|
9
|
-
|
|
10
|
-
describe('.map', function() {
|
|
11
|
-
it('returns null if no discovery events were handled', function() {
|
|
12
|
-
const mapper = new NormalizedUrlMapper();
|
|
13
|
-
[
|
|
14
|
-
'/user/1',
|
|
15
|
-
'/user/2',
|
|
16
|
-
'/user/3',
|
|
17
|
-
'/user/4',
|
|
18
|
-
'/user/1/cart',
|
|
19
|
-
'/user/2/cart',
|
|
20
|
-
'/user/3/cart',
|
|
21
|
-
'/user/4/cart',
|
|
22
|
-
'/products/all',
|
|
23
|
-
'/products/all',
|
|
24
|
-
'/products/1',
|
|
25
|
-
'/products/2',
|
|
26
|
-
'/products/3',
|
|
27
|
-
'/products/4',
|
|
28
|
-
].forEach((uriPath) => {
|
|
29
|
-
expect(mapper.map(uriPath)).to.be.null;
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('returns normalizedUrl mapped from generic uriPath', function() {
|
|
34
|
-
const mapper = new NormalizedUrlMapper();
|
|
35
|
-
testData.forEach((d) => mapper.handleDiscover(d.routeInfo));
|
|
36
|
-
testData.forEach((td) => {
|
|
37
|
-
const { routeInfo, paths, hasMapping } = td;
|
|
38
|
-
|
|
39
|
-
for (const uriPath of paths) {
|
|
40
|
-
// todo - dynamic and regex paths
|
|
41
|
-
if (hasMapping === false) {
|
|
42
|
-
expect(mapper.map(uriPath)).to.be.null;
|
|
43
|
-
} else {
|
|
44
|
-
expect(mapper.map(uriPath)).to.equal(routeInfo.normalizedUrl);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
});
|