Skip to content

Commit

Permalink
test(client): added clientMode option test (#2078)
Browse files Browse the repository at this point in the history
  • Loading branch information
knagaitsev authored and hiroppy committed Jun 28, 2019
1 parent 764b24e commit f984e53
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/ports-map.js
Expand Up @@ -39,6 +39,7 @@ const portsList = {
WebsocketClient: 1,
WebsocketServer: 1,
ClientMode: 1,
'clientMode-option': 1,
};

let startPort = 8079;
Expand Down
102 changes: 102 additions & 0 deletions test/server/clientMode-option.test.js
@@ -0,0 +1,102 @@
'use strict';

const config = require('../fixtures/simple-config/webpack.config');
const port = require('../ports-map')['clientMode-option'];

describe('clientMode option', () => {
let mockedTestServer;
let testServer;
let getSocketClientPath;

const clientModes = [
{
title: 'as a string ("sockjs")',
clientMode: 'sockjs',
shouldThrow: false,
},
{
title: 'as a path ("sockjs")',
clientMode: require.resolve('../../client-src/clients/SockJSClient'),
shouldThrow: false,
},
{
title: 'as a nonexistent path',
clientMode: '/bad/path/to/implementation',
shouldThrow: true,
},
];

describe('is passed to getSocketClientPath correctly', () => {
beforeEach(() => {
jest.mock('../../lib/utils/getSocketClientPath');
// eslint-disable-next-line global-require
getSocketClientPath = require('../../lib/utils/getSocketClientPath');
});

afterEach((done) => {
jest.resetAllMocks();
jest.resetModules();

mockedTestServer.close(done);
});

clientModes.forEach((data) => {
it(data.title, (done) => {
// eslint-disable-next-line global-require
mockedTestServer = require('../helpers/test-server');
mockedTestServer.start(
config,
{
inline: true,
clientMode: data.clientMode,
port,
},
() => {
expect(getSocketClientPath.mock.calls.length).toEqual(1);
expect(getSocketClientPath.mock.calls[0].length).toEqual(1);
expect(getSocketClientPath.mock.calls[0][0].clientMode).toEqual(
data.clientMode
);
done();
}
);
});
});
});

describe('passed to server', () => {
beforeAll(() => {
jest.unmock('../../lib/utils/getSocketClientPath');
// eslint-disable-next-line global-require
testServer = require('../helpers/test-server');
});

afterEach((done) => {
testServer.close(done);
});

clientModes.forEach((data) => {
it(`${data.title} ${
data.shouldThrow ? 'should throw' : 'should not throw'
}`, (done) => {
const res = () => {
testServer.start(
config,
{
inline: true,
clientMode: data.clientMode,
port,
},
done
);
};
if (data.shouldThrow) {
expect(res).toThrow(/clientMode must be a string/);
done();
} else {
expect(res).not.toThrow();
}
});
});
});
});

0 comments on commit f984e53

Please sign in to comment.