Skip to content

Commit

Permalink
test(e2e): More e2e test improvements (#2163)
Browse files Browse the repository at this point in the history
  • Loading branch information
knagaitsev authored and evilebottnawi committed Aug 8, 2019
1 parent bc7005e commit 460f15a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -14,4 +14,5 @@ node_modules
.eslintcache

test/fixtures/reload-config/main.css
test/fixtures/reload-config-2/main.css
!/test/fixtures/contentbase-config/public/node_modules
5 changes: 5 additions & 0 deletions client-src/clients/SockJSClient.js
Expand Up @@ -10,6 +10,11 @@ module.exports = class SockJSClient extends BaseClient {
constructor(url) {
super();
this.sock = new SockJS(url);

this.sock.onerror = (err) => {
// TODO: use logger to log the error event once client and client-src
// are reorganized to have the same directory structure
};
}

static getClientPath(options) {
Expand Down
5 changes: 5 additions & 0 deletions client-src/clients/WebsocketClient.js
Expand Up @@ -11,6 +11,11 @@ module.exports = class WebsocketClient extends BaseClient {
constructor(url) {
super();
this.client = new WebSocket(url.replace(/^http/, 'ws'));

this.client.onerror = (err) => {
// TODO: use logger to log the error event once client and client-src
// are reorganized to have the same directory structure
};
}

static getClientPath(options) {
Expand Down
25 changes: 12 additions & 13 deletions test/e2e/ClientOptions.test.js
Expand Up @@ -10,7 +10,7 @@ const [port1, port2, port3] = require('../ports-map').ClientOptions;
const { beforeBrowserCloseDelay } = require('../helpers/puppeteer-constants');

describe('Client code', () => {
function startProxy(port) {
function startProxy(port, cb) {
const proxy = express();
proxy.use(
'/',
Expand All @@ -20,7 +20,7 @@ describe('Client code', () => {
changeOrigin: true,
})
);
return proxy.listen(port);
return proxy.listen(port, cb);
}

beforeAll((done) => {
Expand All @@ -45,8 +45,8 @@ describe('Client code', () => {
describe('behind a proxy', () => {
let proxy;

beforeAll(() => {
proxy = startProxy(port2);
beforeAll((done) => {
proxy = startProxy(port2, done);
});

afterAll((done) => {
Expand All @@ -55,15 +55,14 @@ describe('Client code', () => {
});
});

it('responds with a 200', (done) => {
{
const req = request(`http://localhost:${port2}`);
req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done);
}
{
const req = request(`http://localhost:${port1}`);
req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done);
}
it('responds with a 200 on proxy port', (done) => {
const req = request(`http://localhost:${port2}`);
req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done);
});

it('responds with a 200 on non-proxy port', (done) => {
const req = request(`http://localhost:${port1}`);
req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done);
});

it('requests websocket through the proxy with proper port number', (done) => {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/Progress.test.js
Expand Up @@ -5,15 +5,15 @@
*/
const fs = require('fs');
const { resolve } = require('path');
const reloadConfig = require('../fixtures/reload-config/webpack.config');
const reloadConfig = require('../fixtures/reload-config-2/webpack.config');
const runBrowser = require('../helpers/run-browser');
const port = require('../ports-map').Progress;
const {
reloadReadyDelay,
completeReloadDelay,
} = require('../helpers/puppeteer-constants');

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

describe('client progress', () => {
let testServer;
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/reload-config-2/foo.js
@@ -0,0 +1,4 @@
'use strict';

// eslint-disable-next-line import/no-unresolved
require('./main.css');
19 changes: 19 additions & 0 deletions test/fixtures/reload-config-2/webpack.config.js
@@ -0,0 +1,19 @@
'use strict';

module.exports = {
mode: 'development',
context: __dirname,
entry: './foo.js',
output: {
path: '/',
},
module: {
rules: [
{
test: /\.css$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
},
],
},
node: false,
};

0 comments on commit 460f15a

Please sign in to comment.