|
1 |
| -var mocks = require('mocks') |
2 |
| - |
3 | 1 | describe('middleware.strip_host', function () {
|
4 |
| - var nextSpy |
5 |
| - var HttpRequestMock = mocks.http.ServerRequest |
6 |
| - |
7 |
| - var createStripHostMiddleware = require('../../../lib/middleware/strip_host').create |
8 |
| - |
9 |
| - var handler = nextSpy = null |
10 |
| - |
11 |
| - beforeEach(function () { |
12 |
| - nextSpy = sinon.spy() |
13 |
| - handler = createStripHostMiddleware(null, null, '/base/path') |
14 |
| - return handler |
15 |
| - }) |
| 2 | + const stripHost = require('../../../lib/middleware/strip_host').stripHost |
16 | 3 |
|
17 |
| - it('should strip request with IP number', function (done) { |
18 |
| - var request = new HttpRequestMock('http://192.12.31.100/base/a.js?123345') |
19 |
| - handler(request, null, nextSpy) |
20 |
| - |
21 |
| - expect(request.normalizedUrl).to.equal('/base/a.js?123345') |
22 |
| - expect(nextSpy).to.have.been.called |
23 |
| - return done() |
| 4 | + it('should strip request with IP number', function () { |
| 5 | + const normalizedUrl = stripHost('http://192.12.31.100/base/a.js?123345') |
| 6 | + expect(normalizedUrl).to.equal('/base/a.js?123345') |
24 | 7 | })
|
25 | 8 |
|
26 |
| - it('should strip request with absoluteURI', function (done) { |
27 |
| - var request = new HttpRequestMock('http://localhost/base/a.js?123345') |
28 |
| - handler(request, null, nextSpy) |
29 |
| - |
30 |
| - expect(request.normalizedUrl).to.equal('/base/a.js?123345') |
31 |
| - expect(nextSpy).to.have.been.called |
32 |
| - return done() |
| 9 | + it('should strip request with absoluteURI', function () { |
| 10 | + const normalizedUrl = stripHost('http://localhost/base/a.js?123345') |
| 11 | + expect(normalizedUrl).to.equal('/base/a.js?123345') |
33 | 12 | })
|
34 | 13 |
|
35 |
| - it('should strip request with absoluteURI and port', function (done) { |
36 |
| - var request = new HttpRequestMock('http://localhost:9876/base/a.js?123345') |
37 |
| - handler(request, null, nextSpy) |
38 |
| - |
39 |
| - expect(request.normalizedUrl).to.equal('/base/a.js?123345') |
40 |
| - expect(nextSpy).to.have.been.called |
41 |
| - return done() |
| 14 | + it('should strip request with absoluteURI and port', function () { |
| 15 | + const normalizedUrl = stripHost('http://localhost:9876/base/a.js?123345') |
| 16 | + expect(normalizedUrl).to.equal('/base/a.js?123345') |
42 | 17 | })
|
43 | 18 |
|
44 |
| - it('should strip request with absoluteURI over HTTPS', function (done) { |
45 |
| - var request = new HttpRequestMock('https://karma-runner.github.io/base/a.js?123345') |
46 |
| - handler(request, null, nextSpy) |
47 |
| - |
48 |
| - expect(request.normalizedUrl).to.equal('/base/a.js?123345') |
49 |
| - expect(nextSpy).to.have.been.called |
50 |
| - return done() |
| 19 | + it('should strip request with absoluteURI over HTTPS', function () { |
| 20 | + const normalizedUrl = stripHost('https://karma-runner.github.io/base/a.js?123345') |
| 21 | + expect(normalizedUrl).to.equal('/base/a.js?123345') |
51 | 22 | })
|
52 | 23 |
|
53 |
| - return it('should return same url as passed one', function (done) { |
54 |
| - var request = new HttpRequestMock('/base/b.js?123345') |
55 |
| - handler(request, null, nextSpy) |
56 |
| - |
57 |
| - expect(request.normalizedUrl).to.equal('/base/b.js?123345') |
58 |
| - expect(nextSpy).to.have.been.called |
59 |
| - return done() |
| 24 | + it('should return same url as passed one', function () { |
| 25 | + const normalizedUrl = stripHost('/base/b.js?123345') |
| 26 | + expect(normalizedUrl).to.equal('/base/b.js?123345') |
60 | 27 | })
|
61 | 28 | })
|
0 commit comments