Skip to content

test(client): added clientMode option test #2078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/ports-map.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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();
}
});
});
});
});