/
Client.test.js
149 lines (131 loc) · 3.58 KB
/
Client.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
'use strict';
const express = require('express');
const httpProxy = require('http-proxy-middleware');
const request = require('supertest');
const helper = require('./helper');
const config = require('./fixtures/client-config/webpack.config');
const runBrowser = require('./helpers/run-browser');
function startProxy(port) {
const proxy = express();
proxy.use(
'/',
httpProxy({
target: 'http://localhost:9001',
ws: true,
changeOrigin: true,
})
);
return proxy.listen(port);
}
describe('Client code', () => {
beforeAll((done) => {
const options = {
compress: true,
port: 9001,
host: '0.0.0.0',
disableHostCheck: true,
inline: true,
hot: true,
watchOptions: {
poll: true,
},
};
helper.startAwaitingCompilation(config, options, done);
});
afterAll(helper.close);
describe('behind a proxy', () => {
let proxy;
jest.setTimeout(30000);
beforeAll(() => {
proxy = startProxy(9000);
});
afterAll(() => {
proxy.close();
});
it('responds with a 200', (done) => {
const req = request('http://localhost:9000');
req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done);
});
it('requests websocket through the proxy with proper port number', (done) => {
runBrowser().then(({ page, browser }) => {
page
.waitForRequest((requestObj) => requestObj.url().match(/sockjs-node/))
.then((requestObj) => {
expect(requestObj.url()).toMatch(
/^http:\/\/localhost:9000\/sockjs-node/
);
browser.close().then(done);
});
page.goto('http://localhost:9000/main');
});
});
});
});
describe('Client complex inline script path', () => {
beforeAll((done) => {
const options = {
port: 9000,
host: '0.0.0.0',
inline: true,
watchOptions: {
poll: true,
},
public: 'myhost.test',
sockPath: '/foo/test/bar/',
};
helper.startAwaitingCompilation(config, options, done);
});
afterAll(helper.close);
describe('browser client', () => {
jest.setTimeout(30000);
it('uses the correct public hostname and sockPath', (done) => {
runBrowser().then(({ page, browser }) => {
page
.waitForRequest((requestObj) =>
requestObj.url().match(/foo\/test\/bar/)
)
.then((requestObj) => {
expect(requestObj.url()).toMatch(
/^http:\/\/myhost\.test:9000\/foo\/test\/bar/
);
browser.close().then(done);
});
page.goto('http://localhost:9000/main');
});
});
});
});
describe('Client complex inline script path with sockPort', () => {
beforeAll((done) => {
const options = {
port: 9000,
host: '0.0.0.0',
inline: true,
watchOptions: {
poll: true,
},
sockPath: '/foo/test/bar/',
sockPort: 8080,
};
helper.startAwaitingCompilation(config, options, done);
});
afterAll(helper.close);
describe('browser client', () => {
jest.setTimeout(30000);
it('uses the correct sockPort', (done) => {
runBrowser().then(({ page, browser }) => {
page
.waitForRequest((requestObj) =>
requestObj.url().match(/foo\/test\/bar/)
)
.then((requestObj) => {
expect(requestObj.url()).toMatch(
/^http:\/\/localhost:8080\/foo\/test\/bar/
);
browser.close().then(done);
});
page.goto('http://localhost:9000/main');
});
});
});
});