1 | var request = require('supertest');
|
2 | var connect = require('../index');
|
3 | require('mocha');
|
4 |
|
5 | var portCounter = 35000;
|
6 | describe('gulp-connect', function () {
|
7 | describe('Simple', function() {
|
8 | after(function() {
|
9 | connect.serverClose();
|
10 | });
|
11 | it('Explicit /test.txt', function (done) {
|
12 | var port = portCounter++;
|
13 | connect.server({
|
14 | port: port
|
15 | }, function() {
|
16 | request('http://localhost:' + port)
|
17 | .get('/fixtures/simplest/test.txt')
|
18 | .expect(/Hello world/)
|
19 | .expect(200)
|
20 | .end(function (err, res) {
|
21 | done(err);
|
22 | });
|
23 | });
|
24 | });
|
25 | it('Implicit /index.html', function (done) {
|
26 | var port = portCounter++;
|
27 | connect.server({
|
28 | port: port
|
29 | }, function() {
|
30 | request('http://localhost:' + port)
|
31 | .get('/fixtures/simplest/')
|
32 | .expect(/index page/)
|
33 | .expect(200)
|
34 | .end(function (err, res) {
|
35 | done(err);
|
36 | });
|
37 | });
|
38 | })
|
39 | })
|
40 | });
|
41 | describe('Self Start / Stop', function() {
|
42 | after(function() {
|
43 | connect.serverClose();
|
44 | });
|
45 | it('Root string', function (done) {
|
46 | var port = portCounter++;
|
47 | connect.server({
|
48 | port: port,
|
49 | root: __dirname + "/fixtures"
|
50 | });
|
51 | request('http://localhost:' + port)
|
52 | .get('/multiple/app/index.html')
|
53 | .expect(/app test/)
|
54 | .end(function (err, res) {
|
55 | connect.serverClose();
|
56 | if (err) return done(err);
|
57 | done()
|
58 | });
|
59 | });
|
60 | it('Root array', function (done) {
|
61 | var port = portCounter++;
|
62 | connect.server({
|
63 | port: port,
|
64 | root: [__dirname + "/fixtures/multiple/app", __dirname + "/fixtures/multiple/dist"]
|
65 | });
|
66 | request('http://localhost:' + port)
|
67 | .get('/index.html')
|
68 | .expect(/app test/)
|
69 | .expect(200)
|
70 | .end(function (err) {
|
71 | if (err) return done(err);
|
72 | });
|
73 | request('http://localhost:' + port)
|
74 | .get('/dist.html')
|
75 | .expect(/dist test/)
|
76 | .expect(200)
|
77 | .end(function (err) {
|
78 | connect.serverClose();
|
79 | if (err) return done(err);
|
80 | done()
|
81 | });
|
82 | });
|
83 | it('Port test', function (done) {
|
84 | connect.server({
|
85 | root: __dirname + "/fixtures/multiple/app",
|
86 | port: 3333
|
87 | });
|
88 | request('http://localhost:3333')
|
89 | .get('/index.html')
|
90 | .expect(/app test/)
|
91 | .end(function (err) {
|
92 | connect.serverClose();
|
93 | if (err) return done(err);
|
94 | done()
|
95 | });
|
96 | });
|
97 | it('Https test', function (done) {
|
98 |
|
99 | process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
|
100 | var port = portCounter++;
|
101 | connect.server({
|
102 | port: port,
|
103 | root: __dirname + "/fixtures/multiple/app",
|
104 | https: true
|
105 | });
|
106 | request('https://localhost:' + port)
|
107 | .get('/index.html')
|
108 | .expect(/app test/)
|
109 | .end(function (err) {
|
110 | connect.serverClose();
|
111 | if (err) return done(err);
|
112 | done()
|
113 | });
|
114 | });
|
115 | it('Livereload test', function (done) {
|
116 | var port = portCounter++;
|
117 | connect.server({
|
118 | port: port,
|
119 | livereload: true
|
120 | }, function() {
|
121 | request('http://localhost:35729')
|
122 | .get('/')
|
123 | .expect('Content-Type', /json/)
|
124 | .end(function (err) {
|
125 | if (err) return done(err);
|
126 | request('http://localhost:35729')
|
127 | .get('/livereload.js')
|
128 | .expect(200)
|
129 | .end(function (err) {
|
130 | connect.serverClose();
|
131 | if (err) return done(err);
|
132 | done();
|
133 | });
|
134 | });
|
135 | });
|
136 | });
|
137 | it('Livereload https test', function (done) {
|
138 | var port = portCounter++;
|
139 | connect.server({
|
140 | port: port,
|
141 | livereload: true,
|
142 | https: true
|
143 | }, function() {
|
144 | request('https://localhost:35729')
|
145 | .get('/')
|
146 | .expect('Content-Type', /json/)
|
147 | .end(function (err) {
|
148 | if (err) return done(err);
|
149 | request('https://localhost:35729')
|
150 | .get('/livereload.js')
|
151 | .expect(200)
|
152 | .end(function (err) {
|
153 | connect.serverClose();
|
154 | if (err) return done(err);
|
155 | done();
|
156 | });
|
157 | });
|
158 | });
|
159 | });
|
160 | it('Livereload port', function (done) {
|
161 | var port = portCounter++;
|
162 | var liveReloadPort = portCounter++;
|
163 | connect.server({
|
164 | port: port,
|
165 | livereload: {
|
166 | port: liveReloadPort
|
167 | }
|
168 | },
|
169 | function() {
|
170 | request('http://localhost:' + liveReloadPort)
|
171 | .get('/')
|
172 | .expect('Content-Type', /json/)
|
173 | .end(function (err) {
|
174 | connect.serverClose();
|
175 | if (err) return done(err);
|
176 | done();
|
177 | });
|
178 | });
|
179 | });
|
180 | it('livereload closes', function (done) {
|
181 | this.timeout(10000);
|
182 | var port = portCounter++;
|
183 | var liveReloadPort = portCounter++;
|
184 | connect.server({
|
185 | port: port,
|
186 | livereload: {
|
187 | port: liveReloadPort
|
188 | }
|
189 | },
|
190 | function() {
|
191 | request('http://localhost:' + liveReloadPort)
|
192 | .get('/')
|
193 | .expect('Content-Type', /json/)
|
194 | .expect(200)
|
195 | .end(function (err) {
|
196 | if (err) return done(err);
|
197 | connect.serverClose();
|
198 | setTimeout(function() {
|
199 | request('http://localhost:' + liveReloadPort)
|
200 | .get('/')
|
201 | .end(function (err) {
|
202 | if (err) return done();
|
203 | done(new Error("Live reload is still running."));
|
204 | })}, 100);
|
205 | })
|
206 | });
|
207 | });
|
208 | it('Fallback test', function (done) {
|
209 | var port = portCounter++;
|
210 | connect.server({
|
211 | port: port,
|
212 | fallback: __dirname + '/fixtures/simplest/index.html'
|
213 | }, function() {
|
214 | request('http://localhost:' + port)
|
215 | .get('/not/existing/path')
|
216 | .expect(/index page/)
|
217 | .expect('Content-Type', new RegExp('text/html; charset=UTF-8'))
|
218 | .expect(200)
|
219 | .end(function (err, res) {
|
220 | connect.serverClose();
|
221 | if (err) return done(err);
|
222 | done()
|
223 | });
|
224 | });
|
225 | })
|
226 | });
|