http-proxy-middleware 0.17.0 → 0.17.3
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/CHANGELOG.md +12 -0
- package/README.md +21 -6
- package/lib/handlers.js +13 -1
- package/lib/index.js +33 -10
- package/lib/logger.js +2 -2
- package/package.json +16 -12
- package/.editorconfig +0 -18
- package/.jscsrc +0 -8
- package/.npmignore +0 -28
- package/.travis.yml +0 -16
- package/CONTRIBUTING.md +0 -61
- package/ISSUE_TEMPLATE.md +0 -21
- package/examples/README.md +0 -33
- package/examples/browser-sync/index.js +0 -29
- package/examples/connect/index.js +0 -29
- package/examples/express/index.js +0 -28
- package/examples/websocket/index.html +0 -96
- package/examples/websocket/index.js +0 -41
- package/recipes/README.md +0 -110
- package/recipes/basic.md +0 -32
- package/recipes/context-matching.md +0 -99
- package/recipes/corporate-proxy.md +0 -21
- package/recipes/delay.md +0 -37
- package/recipes/logLevel.md +0 -40
- package/recipes/logProvider.md +0 -77
- package/recipes/modify-post.md +0 -74
- package/recipes/pathRewrite.md +0 -93
- package/recipes/proxy-events.md +0 -74
- package/recipes/router.md +0 -83
- package/recipes/servers.md +0 -252
- package/recipes/shorthand.md +0 -63
- package/recipes/virtual-hosts.md +0 -18
- package/recipes/websocket.md +0 -41
- package/test/e2e/_utils.js +0 -21
- package/test/e2e/http-proxy-middleware.spec.js +0 -672
- package/test/e2e/path-rewriter.spec.js +0 -98
- package/test/e2e/router.spec.js +0 -128
- package/test/e2e/websocket.spec.js +0 -150
- package/test/unit/_libs.js +0 -8
- package/test/unit/config-factory.spec.js +0 -154
- package/test/unit/context-matcher.spec.js +0 -250
- package/test/unit/handlers.spec.js +0 -126
- package/test/unit/logger.spec.js +0 -259
- package/test/unit/path-rewriter.spec.js +0 -143
- package/test/unit/router.spec.js +0 -136
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
var expect = require('chai').expect;
|
|
2
|
-
var contextMatcher = require('./_libs').contextMatcher;
|
|
3
|
-
|
|
4
|
-
describe('Context Matching', function() {
|
|
5
|
-
|
|
6
|
-
describe('String path matching', function() {
|
|
7
|
-
var result;
|
|
8
|
-
|
|
9
|
-
describe('Single path matching', function() {
|
|
10
|
-
it('should match all paths', function() {
|
|
11
|
-
result = contextMatcher.match('', 'http://localhost/api/foo/bar');
|
|
12
|
-
expect(result).to.be.true;
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should match all paths starting with forward-slash', function() {
|
|
16
|
-
result = contextMatcher.match('/', 'http://localhost/api/foo/bar');
|
|
17
|
-
expect(result).to.be.true;
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should return true when the context is present in url', function() {
|
|
21
|
-
result = contextMatcher.match('/api', 'http://localhost/api/foo/bar');
|
|
22
|
-
expect(result).to.be.true;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should return false when the context is not present in url', function() {
|
|
26
|
-
result = contextMatcher.match('/abc', 'http://localhost/api/foo/bar');
|
|
27
|
-
expect(result).to.be.false;
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should return false when the context is present half way in url', function() {
|
|
31
|
-
result = contextMatcher.match('/foo', 'http://localhost/api/foo/bar');
|
|
32
|
-
expect(result).to.be.false;
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should return false when the context does not start with /', function() {
|
|
36
|
-
result = contextMatcher.match('api', 'http://localhost/api/foo/bar');
|
|
37
|
-
expect(result).to.be.false;
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('Multi path matching', function() {
|
|
42
|
-
it('should return true when the context is present in url', function() {
|
|
43
|
-
result = contextMatcher.match(['/api'], 'http://localhost/api/foo/bar');
|
|
44
|
-
expect(result).to.be.true;
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should return true when the context is present in url', function() {
|
|
48
|
-
result = contextMatcher.match(['/api', '/ajax'], 'http://localhost/ajax/foo/bar');
|
|
49
|
-
expect(result).to.be.true;
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should return false when the context does not match url', function() {
|
|
53
|
-
result = contextMatcher.match(['/api', '/ajax'], 'http://localhost/foo/bar');
|
|
54
|
-
expect(result).to.be.false;
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should return false when empty array provided', function() {
|
|
58
|
-
result = contextMatcher.match([], 'http://localhost/api/foo/bar');
|
|
59
|
-
expect(result).to.be.false;
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('Wildcard path matching', function() {
|
|
65
|
-
describe('Single glob', function() {
|
|
66
|
-
var url;
|
|
67
|
-
|
|
68
|
-
beforeEach(function() {
|
|
69
|
-
url = 'http://localhost/api/foo/bar.html';
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe('url-path matching', function() {
|
|
73
|
-
it('should match any path', function() {
|
|
74
|
-
expect(contextMatcher.match('**', url)).to.be.true;
|
|
75
|
-
expect(contextMatcher.match('/**', url)).to.be.true;
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should only match paths starting with "/api" ', function() {
|
|
79
|
-
expect(contextMatcher.match('/api/**', url)).to.be.true;
|
|
80
|
-
expect(contextMatcher.match('/ajax/**', url)).to.be.false;
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('should only match paths starting with "foo" folder in it ', function() {
|
|
84
|
-
expect(contextMatcher.match('**/foo/**', url)).to.be.true;
|
|
85
|
-
expect(contextMatcher.match('**/invalid/**', url)).to.be.false;
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('file matching', function() {
|
|
90
|
-
it('should match any path, file and extension', function() {
|
|
91
|
-
expect(contextMatcher.match('**', url)).to.be.true;
|
|
92
|
-
expect(contextMatcher.match('**/*', url)).to.be.true;
|
|
93
|
-
expect(contextMatcher.match('**/*.*', url)).to.be.true;
|
|
94
|
-
expect(contextMatcher.match('/**', url)).to.be.true;
|
|
95
|
-
expect(contextMatcher.match('/**.*', url)).to.be.true;
|
|
96
|
-
expect(contextMatcher.match('/**/*', url)).to.be.true;
|
|
97
|
-
expect(contextMatcher.match('/**/*.*', url)).to.be.true;
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('should only match .html files', function() {
|
|
101
|
-
expect(contextMatcher.match('**/*.html', url)).to.be.true;
|
|
102
|
-
expect(contextMatcher.match('/**.html', url)).to.be.true;
|
|
103
|
-
expect(contextMatcher.match('/**/*.html', url)).to.be.true;
|
|
104
|
-
expect(contextMatcher.match('/**.htm', url)).to.be.false;
|
|
105
|
-
expect(contextMatcher.match('/**.jpg', url)).to.be.false;
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should only match .html under root path', function() {
|
|
109
|
-
var pattern = '/*.html';
|
|
110
|
-
expect(contextMatcher.match(pattern, 'http://localhost/index.html')).to.be.true;
|
|
111
|
-
expect(contextMatcher.match(pattern, 'http://localhost/some/path/index.html')).to.be.false;
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should ignore query params', function() {
|
|
115
|
-
expect(contextMatcher.match('/**/*.php', 'http://localhost/a/b/c.php?d=e&e=f')).to.be.true;
|
|
116
|
-
expect(contextMatcher.match('/**/*.php?*', 'http://localhost/a/b/c.php?d=e&e=f')).to.be.false;
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('should only match any file in root path', function() {
|
|
120
|
-
expect(contextMatcher.match('/*', 'http://localhost/bar.html')).to.be.true;
|
|
121
|
-
expect(contextMatcher.match('/*.*', 'http://localhost/bar.html')).to.be.true;
|
|
122
|
-
expect(contextMatcher.match('/*', 'http://localhost/foo/bar.html')).to.be.false;
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('should only match .html file is in root path', function() {
|
|
126
|
-
expect(contextMatcher.match('/*.html', 'http://localhost/bar.html')).to.be.true;
|
|
127
|
-
expect(contextMatcher.match('/*.html', 'http://localhost/api/foo/bar.html')).to.be.false;
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('should only match .html files in "foo" folder', function() {
|
|
131
|
-
expect(contextMatcher.match('**/foo/*.html', url)).to.be.true;
|
|
132
|
-
expect(contextMatcher.match('**/bar/*.html', url)).to.be.false;
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('should not match .html files', function() {
|
|
136
|
-
expect(contextMatcher.match('!**/*.html', url)).to.be.false;
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
describe('Multi glob matching', function() {
|
|
142
|
-
|
|
143
|
-
describe('Multiple patterns', function() {
|
|
144
|
-
it('should return true when both path patterns match', function() {
|
|
145
|
-
var pattern = ['/api/**','/ajax/**'];
|
|
146
|
-
expect(contextMatcher.match(pattern, 'http://localhost/api/foo/bar.json')).to.be.true;
|
|
147
|
-
expect(contextMatcher.match(pattern, 'http://localhost/ajax/foo/bar.json')).to.be.true;
|
|
148
|
-
expect(contextMatcher.match(pattern, 'http://localhost/rest/foo/bar.json')).to.be.false;
|
|
149
|
-
});
|
|
150
|
-
it('should return true when both file extensions pattern match', function() {
|
|
151
|
-
var pattern = ['/**.html','/**.jpeg'];
|
|
152
|
-
expect(contextMatcher.match(pattern, 'http://localhost/api/foo/bar.html')).to.be.true;
|
|
153
|
-
expect(contextMatcher.match(pattern, 'http://localhost/api/foo/bar.jpeg')).to.be.true;
|
|
154
|
-
expect(contextMatcher.match(pattern, 'http://localhost/api/foo/bar.gif')).to.be.false;
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
describe('Negation patterns', function() {
|
|
159
|
-
it('should not match file extension', function() {
|
|
160
|
-
var url = 'http://localhost/api/foo/bar.html';
|
|
161
|
-
expect(contextMatcher.match(['**', '!**/*.html'], url)).to.be.false;
|
|
162
|
-
expect(contextMatcher.match(['**', '!**/*.json'], url)).to.be.true;
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
describe('Use function for matching', function() {
|
|
169
|
-
testFunctionAsContext = function(val) {
|
|
170
|
-
return contextMatcher.match(fn, 'http://localhost/api/foo/bar');
|
|
171
|
-
|
|
172
|
-
function fn(path, req) {
|
|
173
|
-
return val;
|
|
174
|
-
};
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
describe('truthy', function() {
|
|
178
|
-
it('should match when function returns true', function() {
|
|
179
|
-
expect(testFunctionAsContext(true)).to.be.ok;
|
|
180
|
-
expect(testFunctionAsContext('true')).to.be.ok;
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
describe('falsy', function() {
|
|
185
|
-
it('should not match when function returns falsy value', function() {
|
|
186
|
-
expect(testFunctionAsContext()).to.not.be.ok;
|
|
187
|
-
expect(testFunctionAsContext(undefined)).to.not.be.ok;
|
|
188
|
-
expect(testFunctionAsContext(false)).to.not.be.ok;
|
|
189
|
-
expect(testFunctionAsContext('')).to.not.be.ok;
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
describe('Test invalid contexts', function() {
|
|
196
|
-
var testContext;
|
|
197
|
-
|
|
198
|
-
beforeEach(function() {
|
|
199
|
-
testContext = function(context) {
|
|
200
|
-
return function() {
|
|
201
|
-
contextMatcher.match(context, 'http://localhost/api/foo/bar');
|
|
202
|
-
};
|
|
203
|
-
};
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
describe('Throw error', function() {
|
|
207
|
-
it('should throw error with undefined', function() {
|
|
208
|
-
expect(testContext(undefined)).to.throw(Error);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it('should throw error with null', function() {
|
|
212
|
-
expect(testContext(null)).to.throw(Error);
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it('should throw error with object literal', function() {
|
|
216
|
-
expect(testContext({})).to.throw(Error);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it('should throw error with integers', function() {
|
|
220
|
-
expect(testContext(123)).to.throw(Error);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('should throw error with mixed string and glob pattern', function() {
|
|
224
|
-
expect(testContext(['/api', '!*.html'])).to.throw(Error);
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
describe('Do not throw error', function() {
|
|
229
|
-
it('should not throw error with string', function() {
|
|
230
|
-
expect(testContext('/123')).not.to.throw(Error);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('should not throw error with Array', function() {
|
|
234
|
-
expect(testContext(['/123'])).not.to.throw(Error);
|
|
235
|
-
});
|
|
236
|
-
it('should not throw error with glob', function() {
|
|
237
|
-
expect(testContext('/**')).not.to.throw(Error);
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it('should not throw error with Array of globs', function() {
|
|
241
|
-
expect(testContext(['/**', '!*.html'])).not.to.throw(Error);
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it('should not throw error with Function', function() {
|
|
245
|
-
expect(testContext(function() {})).not.to.throw(Error);
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
});
|
|
250
|
-
});
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
var expect = require('chai').expect;
|
|
2
|
-
var handlers = require('./_libs').handlers;
|
|
3
|
-
|
|
4
|
-
describe('handlers factory', function() {
|
|
5
|
-
var handlersMap;
|
|
6
|
-
|
|
7
|
-
it('should return default handlers when no handlers are provided', function() {
|
|
8
|
-
handlersMap = handlers.getHandlers();
|
|
9
|
-
expect(handlersMap.error).to.be.a('function');
|
|
10
|
-
expect(handlersMap.close).to.be.a('function');
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
describe('custom handlers', function() {
|
|
14
|
-
beforeEach(function() {
|
|
15
|
-
var fnCustom = function() {
|
|
16
|
-
return 42;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
var proxyOptions = {
|
|
20
|
-
target: 'http://www.example.org',
|
|
21
|
-
onError: fnCustom,
|
|
22
|
-
onOpen: fnCustom,
|
|
23
|
-
onClose: fnCustom,
|
|
24
|
-
onProxyReq: fnCustom,
|
|
25
|
-
onProxyReqWs: fnCustom,
|
|
26
|
-
onProxyRes: fnCustom,
|
|
27
|
-
onDummy: fnCustom,
|
|
28
|
-
foobar: fnCustom
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
handlersMap = handlers.getHandlers(proxyOptions);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should only return http-proxy handlers', function() {
|
|
35
|
-
expect(handlersMap.error).to.be.a('function');
|
|
36
|
-
expect(handlersMap.open).to.be.a('function');
|
|
37
|
-
expect(handlersMap.close).to.be.a('function');
|
|
38
|
-
expect(handlersMap.proxyReq).to.be.a('function');
|
|
39
|
-
expect(handlersMap.proxyReqWs).to.be.a('function');
|
|
40
|
-
expect(handlersMap.proxyRes).to.be.a('function');
|
|
41
|
-
expect(handlersMap.dummy).to.be.undefined;
|
|
42
|
-
expect(handlersMap.foobar).to.be.undefined;
|
|
43
|
-
expect(handlersMap.target).to.be.undefined;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should use the provided custom handlers', function() {
|
|
47
|
-
expect(handlersMap.error()).to.equal(42);
|
|
48
|
-
expect(handlersMap.open()).to.equal(42);
|
|
49
|
-
expect(handlersMap.close()).to.equal(42);
|
|
50
|
-
expect(handlersMap.proxyReq()).to.equal(42);
|
|
51
|
-
expect(handlersMap.proxyReqWs()).to.equal(42);
|
|
52
|
-
expect(handlersMap.proxyRes()).to.equal(42);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('default proxy error handler', function() {
|
|
59
|
-
|
|
60
|
-
var mockError = {
|
|
61
|
-
code: 'ECONNREFUSED'
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
var mockReq = {
|
|
65
|
-
headers: {
|
|
66
|
-
host: 'localhost:3000'
|
|
67
|
-
},
|
|
68
|
-
url: '/api'
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
var proxyOptions = {
|
|
72
|
-
target: {
|
|
73
|
-
host: 'localhost.dev'
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
var httpErrorCode;
|
|
78
|
-
var errorMessage;
|
|
79
|
-
|
|
80
|
-
var mockRes = {
|
|
81
|
-
writeHead: function(v) {
|
|
82
|
-
httpErrorCode = v;
|
|
83
|
-
return v;
|
|
84
|
-
},
|
|
85
|
-
end: function(v) {
|
|
86
|
-
errorMessage = v;
|
|
87
|
-
return v;
|
|
88
|
-
},
|
|
89
|
-
headersSent: false
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
var proxyError;
|
|
93
|
-
|
|
94
|
-
beforeEach(function() {
|
|
95
|
-
var handlersMap = handlers.getHandlers();
|
|
96
|
-
proxyError = handlersMap.error;
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
afterEach(function() {
|
|
100
|
-
httpErrorCode = undefined;
|
|
101
|
-
errorMessage = undefined;
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should set the http status code to: 500', function() {
|
|
105
|
-
proxyError(mockError, mockReq, mockRes, proxyOptions);
|
|
106
|
-
expect(httpErrorCode).to.equal(500);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('should end the response and return error message', function() {
|
|
110
|
-
proxyError(mockError, mockReq, mockRes, proxyOptions);
|
|
111
|
-
expect(errorMessage).to.equal('Error occured while trying to proxy to: localhost:3000/api');
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should not set the http status code to: 500 if headers have already been sent', function() {
|
|
115
|
-
mockRes.headersSent = true;
|
|
116
|
-
proxyError(mockError, mockReq, mockRes, proxyOptions);
|
|
117
|
-
expect(httpErrorCode).to.equal(undefined);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('should end the response and return error message', function() {
|
|
121
|
-
mockRes.headersSent = true;
|
|
122
|
-
proxyError(mockError, mockReq, mockRes, proxyOptions);
|
|
123
|
-
expect(errorMessage).to.equal('Error occured while trying to proxy to: localhost:3000/api');
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
});
|
package/test/unit/logger.spec.js
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
var expect = require('chai').expect;
|
|
2
|
-
var Logger = require('./_libs').Logger;
|
|
3
|
-
var getArrow = Logger.getArrow;
|
|
4
|
-
|
|
5
|
-
describe('Logger', function() {
|
|
6
|
-
var logger;
|
|
7
|
-
var logMessage, debugMessage, infoMessage, warnMessage, errorMessage;
|
|
8
|
-
|
|
9
|
-
beforeEach(function() {
|
|
10
|
-
logMessage = undefined;
|
|
11
|
-
debugMessage = undefined;
|
|
12
|
-
infoMessage = undefined;
|
|
13
|
-
warnMessage = undefined;
|
|
14
|
-
errorMessage = undefined;
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
beforeEach(function() {
|
|
18
|
-
logger = Logger.getInstance();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
beforeEach(function() {
|
|
22
|
-
logger.setProvider(function(provider) {
|
|
23
|
-
provider.log = function(message) {logMessage = message;};
|
|
24
|
-
provider.debug = function(message) {debugMessage = message;};
|
|
25
|
-
provider.info = function(message) {infoMessage = message;};
|
|
26
|
-
provider.warn = function(message) {warnMessage = message;};
|
|
27
|
-
provider.error = function(message) {errorMessage = message;};
|
|
28
|
-
|
|
29
|
-
return provider;
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe('logging with different levels', function() {
|
|
34
|
-
beforeEach(function() {
|
|
35
|
-
logger.log('log');
|
|
36
|
-
logger.debug('debug');
|
|
37
|
-
logger.info('info');
|
|
38
|
-
logger.warn('warn');
|
|
39
|
-
logger.error('error');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('level: debug', function() {
|
|
43
|
-
beforeEach(function() {
|
|
44
|
-
logger.setLevel('debug');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should log .log() messages', function() {
|
|
48
|
-
expect(logMessage).to.equal('log');
|
|
49
|
-
});
|
|
50
|
-
it('should log .debug() messages', function() {
|
|
51
|
-
expect(debugMessage).to.equal('debug');
|
|
52
|
-
});
|
|
53
|
-
it('should log .info() messages', function() {
|
|
54
|
-
expect(infoMessage).to.equal('info');
|
|
55
|
-
});
|
|
56
|
-
it('should log .warn() messages', function() {
|
|
57
|
-
expect(warnMessage).to.equal('warn');
|
|
58
|
-
});
|
|
59
|
-
it('should log .error() messages', function() {
|
|
60
|
-
expect(errorMessage).to.equal('error');
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('level: info', function() {
|
|
65
|
-
beforeEach(function() {
|
|
66
|
-
logger.setLevel('info');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should log .log() messages', function() {
|
|
70
|
-
expect(logMessage).to.equal('log');
|
|
71
|
-
});
|
|
72
|
-
it('should not log .debug() messages', function() {
|
|
73
|
-
expect(debugMessage).to.equal(undefined);
|
|
74
|
-
});
|
|
75
|
-
it('should log .info() messages', function() {
|
|
76
|
-
expect(infoMessage).to.equal('info');
|
|
77
|
-
});
|
|
78
|
-
it('should log .warn() messages', function() {
|
|
79
|
-
expect(warnMessage).to.equal('warn');
|
|
80
|
-
});
|
|
81
|
-
it('should log .error() messages', function() {
|
|
82
|
-
expect(errorMessage).to.equal('error');
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe('level: warn', function() {
|
|
87
|
-
beforeEach(function() {
|
|
88
|
-
logger.setLevel('warn');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should log .log() messages', function() {
|
|
92
|
-
expect(logMessage).to.equal('log');
|
|
93
|
-
});
|
|
94
|
-
it('should not log .debug() messages', function() {
|
|
95
|
-
expect(debugMessage).to.equal(undefined);
|
|
96
|
-
});
|
|
97
|
-
it('should not log .info() messages', function() {
|
|
98
|
-
expect(infoMessage).to.equal(undefined);
|
|
99
|
-
});
|
|
100
|
-
it('should log .warn() messages', function() {
|
|
101
|
-
expect(warnMessage).to.equal('warn');
|
|
102
|
-
});
|
|
103
|
-
it('should log .error() messages', function() {
|
|
104
|
-
expect(errorMessage).to.equal('error');
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
describe('level: error', function() {
|
|
109
|
-
beforeEach(function() {
|
|
110
|
-
logger.setLevel('error');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('should log .log() messages', function() {
|
|
114
|
-
expect(logMessage).to.equal('log');
|
|
115
|
-
});
|
|
116
|
-
it('should not log .debug() messages', function() {
|
|
117
|
-
expect(debugMessage).to.equal(undefined);
|
|
118
|
-
});
|
|
119
|
-
it('should not log .info() messages', function() {
|
|
120
|
-
expect(infoMessage).to.equal(undefined);
|
|
121
|
-
});
|
|
122
|
-
it('should log .warn() messages', function() {
|
|
123
|
-
expect(warnMessage).to.equal(undefined);
|
|
124
|
-
});
|
|
125
|
-
it('should log .error() messages', function() {
|
|
126
|
-
expect(errorMessage).to.equal('error');
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe('level: silent', function() {
|
|
131
|
-
beforeEach(function() {
|
|
132
|
-
logger.setLevel('silent');
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('should log .log() messages', function() {
|
|
136
|
-
expect(logMessage).to.equal('log');
|
|
137
|
-
});
|
|
138
|
-
it('should not log .debug() messages', function() {
|
|
139
|
-
expect(debugMessage).to.equal(undefined);
|
|
140
|
-
});
|
|
141
|
-
it('should not log .info() messages', function() {
|
|
142
|
-
expect(infoMessage).to.equal(undefined);
|
|
143
|
-
});
|
|
144
|
-
it('should not log .warn() messages', function() {
|
|
145
|
-
expect(warnMessage).to.equal(undefined);
|
|
146
|
-
});
|
|
147
|
-
it('should not log .error() messages', function() {
|
|
148
|
-
expect(errorMessage).to.equal(undefined);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
describe('Interpolation', function() {
|
|
153
|
-
// make sure all messages are logged
|
|
154
|
-
beforeEach(function() {
|
|
155
|
-
logger.setLevel('debug');
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
beforeEach(function() {
|
|
159
|
-
logger.log('log %s %s', 123, 456);
|
|
160
|
-
logger.debug('debug %s %s', 123, 456);
|
|
161
|
-
logger.info('info %s %s', 123, 456);
|
|
162
|
-
logger.warn('warn %s %s', 123, 456);
|
|
163
|
-
logger.error('error %s %s', 123, 456);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('should interpolate .log() messages', function() {
|
|
167
|
-
expect(logMessage).to.equal('log 123 456');
|
|
168
|
-
});
|
|
169
|
-
it('should interpolate .debug() messages', function() {
|
|
170
|
-
expect(debugMessage).to.equal('debug 123 456');
|
|
171
|
-
});
|
|
172
|
-
it('should interpolate .info() messages', function() {
|
|
173
|
-
expect(infoMessage).to.equal('info 123 456');
|
|
174
|
-
});
|
|
175
|
-
it('should interpolate .warn() messages', function() {
|
|
176
|
-
expect(warnMessage).to.equal('warn 123 456');
|
|
177
|
-
});
|
|
178
|
-
it('should interpolate .error() messages', function() {
|
|
179
|
-
expect(errorMessage).to.equal('error 123 456');
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
describe('Erroneous usage.', function() {
|
|
185
|
-
var fn;
|
|
186
|
-
|
|
187
|
-
describe('Log provider is not a function', function() {
|
|
188
|
-
beforeEach(function() {
|
|
189
|
-
fn = function() {
|
|
190
|
-
logger.setProvider({});
|
|
191
|
-
};
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('should throw an error', function() {
|
|
195
|
-
expect(fn).to.throw(Error);
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
describe('Invalid logLevel', function() {
|
|
200
|
-
beforeEach(function() {
|
|
201
|
-
fn = function() {
|
|
202
|
-
logger.setLevel('foo');
|
|
203
|
-
};
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('should throw an error', function() {
|
|
207
|
-
expect(fn).to.throw(Error);
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
describe('getArrow', function() {
|
|
216
|
-
var arrow;
|
|
217
|
-
// scenario = [originalPath, newPath, originalTarget, newTarget]
|
|
218
|
-
|
|
219
|
-
describe('default arrow', function() {
|
|
220
|
-
beforeEach(function() {
|
|
221
|
-
arrow = getArrow('/api', '/api', 'localhost:1337', 'localhost:1337');
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('should return arrow: "->"', function() {
|
|
225
|
-
expect(arrow).to.equal('->');
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
describe('"pathRewrite" arrow', function() {
|
|
230
|
-
beforeEach(function() {
|
|
231
|
-
arrow = getArrow('/api', '/rest', 'localhost:1337', 'localhost:1337');
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it('should return arrow: "~>"', function() {
|
|
235
|
-
expect(arrow).to.equal('~>');
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
describe('"proxyTable" arrow', function() {
|
|
240
|
-
beforeEach(function() {
|
|
241
|
-
arrow = getArrow('/api', '/api', 'localhost:1337', 'localhost:8888');
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it('should return arrow: "=>"', function() {
|
|
245
|
-
expect(arrow).to.equal('=>');
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
describe('"pathRewrite" + "proxyTable" arrow', function() {
|
|
250
|
-
beforeEach(function() {
|
|
251
|
-
arrow = getArrow('/api', '/rest', 'localhost:1337', 'localhost:8888');
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('should return arrow: "≈>"', function() {
|
|
255
|
-
expect(arrow).to.equal('≈>');
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
});
|