Skip to content

Commit 460f15a

Browse files
knagaitsevevilebottnawi
authored andcommitted
test(e2e): More e2e test improvements (#2163)
1 parent bc7005e commit 460f15a

File tree

7 files changed

+48
-15
lines changed

7 files changed

+48
-15
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ node_modules
1414
.eslintcache
1515

1616
test/fixtures/reload-config/main.css
17+
test/fixtures/reload-config-2/main.css
1718
!/test/fixtures/contentbase-config/public/node_modules

client-src/clients/SockJSClient.js

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ module.exports = class SockJSClient extends BaseClient {
1010
constructor(url) {
1111
super();
1212
this.sock = new SockJS(url);
13+
14+
this.sock.onerror = (err) => {
15+
// TODO: use logger to log the error event once client and client-src
16+
// are reorganized to have the same directory structure
17+
};
1318
}
1419

1520
static getClientPath(options) {

client-src/clients/WebsocketClient.js

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ module.exports = class WebsocketClient extends BaseClient {
1111
constructor(url) {
1212
super();
1313
this.client = new WebSocket(url.replace(/^http/, 'ws'));
14+
15+
this.client.onerror = (err) => {
16+
// TODO: use logger to log the error event once client and client-src
17+
// are reorganized to have the same directory structure
18+
};
1419
}
1520

1621
static getClientPath(options) {

test/e2e/ClientOptions.test.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const [port1, port2, port3] = require('../ports-map').ClientOptions;
1010
const { beforeBrowserCloseDelay } = require('../helpers/puppeteer-constants');
1111

1212
describe('Client code', () => {
13-
function startProxy(port) {
13+
function startProxy(port, cb) {
1414
const proxy = express();
1515
proxy.use(
1616
'/',
@@ -20,7 +20,7 @@ describe('Client code', () => {
2020
changeOrigin: true,
2121
})
2222
);
23-
return proxy.listen(port);
23+
return proxy.listen(port, cb);
2424
}
2525

2626
beforeAll((done) => {
@@ -45,8 +45,8 @@ describe('Client code', () => {
4545
describe('behind a proxy', () => {
4646
let proxy;
4747

48-
beforeAll(() => {
49-
proxy = startProxy(port2);
48+
beforeAll((done) => {
49+
proxy = startProxy(port2, done);
5050
});
5151

5252
afterAll((done) => {
@@ -55,15 +55,14 @@ describe('Client code', () => {
5555
});
5656
});
5757

58-
it('responds with a 200', (done) => {
59-
{
60-
const req = request(`http://localhost:${port2}`);
61-
req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done);
62-
}
63-
{
64-
const req = request(`http://localhost:${port1}`);
65-
req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done);
66-
}
58+
it('responds with a 200 on proxy port', (done) => {
59+
const req = request(`http://localhost:${port2}`);
60+
req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done);
61+
});
62+
63+
it('responds with a 200 on non-proxy port', (done) => {
64+
const req = request(`http://localhost:${port1}`);
65+
req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done);
6766
});
6867

6968
it('requests websocket through the proxy with proper port number', (done) => {

test/e2e/Progress.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
*/
66
const fs = require('fs');
77
const { resolve } = require('path');
8-
const reloadConfig = require('../fixtures/reload-config/webpack.config');
8+
const reloadConfig = require('../fixtures/reload-config-2/webpack.config');
99
const runBrowser = require('../helpers/run-browser');
1010
const port = require('../ports-map').Progress;
1111
const {
1212
reloadReadyDelay,
1313
completeReloadDelay,
1414
} = require('../helpers/puppeteer-constants');
1515

16-
const cssFilePath = resolve(__dirname, '../fixtures/reload-config/main.css');
16+
const cssFilePath = resolve(__dirname, '../fixtures/reload-config-2/main.css');
1717

1818
describe('client progress', () => {
1919
let testServer;

test/fixtures/reload-config-2/foo.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict';
2+
3+
// eslint-disable-next-line import/no-unresolved
4+
require('./main.css');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
module.exports = {
4+
mode: 'development',
5+
context: __dirname,
6+
entry: './foo.js',
7+
output: {
8+
path: '/',
9+
},
10+
module: {
11+
rules: [
12+
{
13+
test: /\.css$/,
14+
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
15+
},
16+
],
17+
},
18+
node: false,
19+
};

0 commit comments

Comments
 (0)