|
3 | 3 | var browserSync = require("../../../../index"); |
4 | 4 |
|
5 | 5 | var assert = require("chai").assert; |
6 | | -var sinon = require("sinon"); |
| 6 | +var request = require("supertest"); |
7 | 7 |
|
8 | 8 | describe("E2E httpModule options test", function () { |
9 | 9 |
|
10 | | - this.timeout(15000); |
11 | | - |
12 | | - var bs; |
13 | | - var mockHttpModule, mockHttpServer, createServerSpy, https; |
14 | | - |
15 | | - describe("httpModule undefined", function () { |
16 | | - |
17 | | - before(function (done) { |
18 | | - |
19 | | - browserSync.reset(); |
20 | | - https = require("https"); |
21 | | - |
22 | | - createServerSpy = sinon.spy(https, "createServer"); |
23 | | - |
24 | | - var config = { |
25 | | - server: { |
26 | | - baseDir: "test/fixtures", |
27 | | - }, |
28 | | - https: true, |
29 | | - open: false, |
30 | | - logLevel: "silent" |
31 | | - }; |
32 | | - |
33 | | - bs = browserSync.init(config, done).instance; |
34 | | - }); |
35 | | - |
36 | | - after(function () { |
37 | | - bs.cleanup(); |
38 | | - }); |
39 | | - |
40 | | - it("creates server using the default https module", function () { |
41 | | - sinon.assert.calledOnce(createServerSpy); |
42 | | - }); |
43 | | - |
44 | | - it("should be using the server from the https module", function () { |
45 | | - assert.equal(bs.server instanceof https.Server, true); |
46 | | - }); |
47 | | - }); |
48 | | - |
49 | | - describe("httpModule defined", function () { |
50 | | - |
51 | | - before(function (done) { |
52 | | - |
53 | | - browserSync.reset(); |
54 | | - |
55 | | - mockHttpServer = { |
56 | | - on: function() { }, |
57 | | - listen: function() { }, |
58 | | - listeners: function() { return []; }, |
59 | | - removeAllListeners: function() { }, |
60 | | - close: function() { } |
61 | | - }; |
62 | | - |
63 | | - mockHttpModule = { |
64 | | - createServer: function() { |
65 | | - return mockHttpServer; |
66 | | - } |
67 | | - }; |
68 | | - |
69 | | - createServerSpy = sinon.spy(mockHttpModule, "createServer"); |
70 | | - |
71 | | - var config = { |
72 | | - server: { |
73 | | - baseDir: "test/fixtures", |
74 | | - }, |
75 | | - https: true, |
76 | | - httpModule: mockHttpModule, |
77 | | - open: false, |
78 | | - logLevel: "silent" |
79 | | - }; |
80 | | - |
81 | | - bs = browserSync.init(config, done).instance; |
82 | | - }); |
83 | | - |
84 | | - after(function () { |
85 | | - bs.cleanup(); |
86 | | - }); |
87 | | - |
88 | | - it("creates server using provided httpModule", function () { |
89 | | - sinon.assert.calledOnce(createServerSpy); |
90 | | - }); |
91 | | - |
92 | | - it("should be using the server created by the provided httpModule", function () { |
93 | | - assert.equal(bs.server, mockHttpServer); |
| 10 | + it("creates server using provided httpModule", function (done) { |
| 11 | + |
| 12 | + browserSync.reset(); |
| 13 | + |
| 14 | + var config = { |
| 15 | + server: { |
| 16 | + baseDir: "test/fixtures" |
| 17 | + }, |
| 18 | + https: true, |
| 19 | + httpModule: "http2", |
| 20 | + open: false, |
| 21 | + logLevel: "silent" |
| 22 | + }; |
| 23 | + |
| 24 | + browserSync.init(config, function (err, bs) { |
| 25 | + request(bs.options.getIn(["urls", "local"])) |
| 26 | + .get("/index.html") |
| 27 | + .set("accept", "text/html") |
| 28 | + .expect(200) |
| 29 | + .end(function (err, res) { |
| 30 | + assert.include(res.text, bs.options.get("snippet")); |
| 31 | + bs.cleanup(); |
| 32 | + done(); |
| 33 | + }); |
94 | 34 | }); |
95 | 35 | }); |
96 | 36 | }); |
0 commit comments