2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-06-15 18:32:21 +00:00
nativefier/src/infer/inferUserAgent.test.js

38 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-05-24 06:34:18 +00:00
import _ from 'lodash';
import inferUserAgent from './inferUserAgent';
const TEST_RESULT = {
darwin:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36',
mas:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36',
win32:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36',
linux:
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36',
};
function testPlatform(platform) {
2018-05-25 05:24:09 +00:00
return expect(inferUserAgent('0.37.1', platform)).resolves.toBe(
TEST_RESULT[platform],
);
2018-05-24 06:34:18 +00:00
}
describe('Infer User Agent', () => {
2018-05-25 05:24:09 +00:00
test('Can infer userAgent for all platforms', async () => {
2018-06-10 18:07:06 +00:00
const testPromises = _.keys(TEST_RESULT).map((platform) =>
testPlatform(platform),
);
2018-05-25 05:24:09 +00:00
await Promise.all(testPromises);
2018-05-24 06:34:18 +00:00
});
2018-05-25 05:24:09 +00:00
test('Connection error will still get a user agent', async () => {
2018-05-24 06:34:18 +00:00
jest.setTimeout(6000);
const TIMEOUT_URL = 'http://www.google.com:81/';
2018-05-25 05:24:09 +00:00
await expect(inferUserAgent('1.6.7', 'darwin', TIMEOUT_URL)).resolves.toBe(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
2018-05-25 05:24:09 +00:00
);
2018-05-24 06:34:18 +00:00
});
});