Skip to content

Commit 24b3125

Browse files
authored
feat(testing): Add script to check BrowserStack support for current config (#2437)
* add check-browsers script * move script and add yarn command * incorporate PR feedback
1 parent 644b36c commit 24b3125

File tree

4 files changed

+174
-6
lines changed

4 files changed

+174
-6
lines changed

packages/browser/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"devDependencies": {
2525
"@types/md5": "2.1.33",
26+
"btoa": "^1.2.1",
2627
"chai": "^4.1.2",
2728
"chokidar": "^3.0.2",
2829
"jest": "^24.7.1",
@@ -36,6 +37,7 @@
3637
"karma-sinon": "^1.0.5",
3738
"karma-typescript": "^4.0.0",
3839
"karma-typescript-es6-transform": "^4.0.0",
40+
"node-fetch": "^2.6.0",
3941
"npm-run-all": "^4.1.2",
4042
"prettier": "^1.17.0",
4143
"prettier-check": "^2.0.0",
@@ -74,6 +76,7 @@
7476
"test:unit:watch": "karma start test/unit/karma.conf.js --auto-watch --no-single-run",
7577
"test:integration": "test/integration/run.js",
7678
"test:integration:watch": "test/integration/run.js --watch",
79+
"test:integration:checkbrowsers": "node scripts/checkbrowsers.js",
7780
"test:manual": "node test/manual/npm-build.js && rm test/manual/tmp.js",
7881
"size:check": "run-p size:check:es5 size:check:es6",
7982
"size:check:es5": "cat build/bundle.min.js | gzip -9 | wc -c | awk '{$1=$1/1024; print \"ES5: \",$1,\"kB\";}'",
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// Script which checks all browsers in test/integration/browser.js against supported BrowserStack browsers
2+
// Meant to be run manually, by running `yarn test:integration:checkbrowsers` from the command line
3+
4+
const btoa = require('btoa');
5+
const fetch = require('node-fetch');
6+
const localConfigs = require('../test/integration/browsers.js');
7+
8+
const browserstackUsername = process.env.BROWSERSTACK_USERNAME;
9+
const browserstackAccessKey = process.env.BROWSERSTACK_ACCESS_KEY;
10+
11+
const hasCreds = () => {
12+
return browserstackUsername !== undefined && browserstackAccessKey !== undefined;
13+
};
14+
15+
const fetchCurrentData = (username, key) => {
16+
const authKey = btoa(`${username}:${key}`);
17+
18+
return fetch('https://api.browserstack.com/5/browsers?flat=true', {
19+
headers: {
20+
Authorization: `Basic ${authKey}`,
21+
},
22+
}).then(response => {
23+
if (response.status >= 200 && response.status < 300) {
24+
return response.json();
25+
} else {
26+
throw new Error(`Unable to fetch data. Status: ${response.status} ${response.statusText}`);
27+
}
28+
});
29+
};
30+
31+
const isMatchingEntry = (key, localConfig, bsConfig) => {
32+
let localValue = localConfig[key];
33+
let bsValue = bsConfig[key];
34+
35+
// all values are either null, undefined, or strings, so checking truthiness should
36+
// save us from trying to lowercase anything that can't handle it
37+
if (localValue) {
38+
localValue = localValue.toLowerCase();
39+
}
40+
if (bsValue) {
41+
bsValue = bsValue.toLowerCase();
42+
}
43+
44+
if (localValue === bsValue) {
45+
return true;
46+
}
47+
if (key === 'browser_version' && localValue === 'latest') {
48+
return true;
49+
}
50+
51+
return false;
52+
};
53+
54+
const isMatchingConfig = (localConfig, bsConfig) => {
55+
const checkKeys = ['os', 'os_version', 'browser', 'device', 'browser_version'];
56+
57+
// bail on the first non-matching entry
58+
if (checkKeys.some(key => !isMatchingEntry(key, localConfig, bsConfig))) {
59+
return false;
60+
}
61+
62+
// while we're here, if we've found a match on everything else, make sure
63+
// real_mobile is up to date. Now the data *really* matches!
64+
if (localConfig.real_mobile !== bsConfig.real_mobile) {
65+
localConfig.real_mobile_updated = true; // flag for later
66+
localConfig.real_mobile = bsConfig.real_mobile;
67+
}
68+
69+
return true;
70+
};
71+
72+
const isSupported = (localConfig, supportedConfigs) => {
73+
return supportedConfigs.some(supportedConfig => isMatchingConfig(localConfig, supportedConfig));
74+
};
75+
76+
const checkLocalConfigsVsBrowserStack = (localConfigs, bsConfigs) => {
77+
const unsupportedConfigs = [];
78+
const realMobileUpdates = [];
79+
80+
// check each local config against the entire collection of BS configs
81+
for (const configName in localConfigs) {
82+
const localConfig = localConfigs[configName];
83+
84+
console.log(`\nChecking ${configName}`);
85+
86+
if (!isSupported(localConfig, bsConfigs)) {
87+
console.log(' UNSUPPORTED');
88+
unsupportedConfigs.push(configName);
89+
} else if (localConfig.real_mobile_updated) {
90+
console.log(' Supported (but needs real_mobile update)');
91+
realMobileUpdates.push(configName);
92+
} else {
93+
console.log(' Supported!');
94+
}
95+
}
96+
97+
// report on unsupported configs
98+
if (unsupportedConfigs.length) {
99+
console.log('\nFound unsupported browser configurations:');
100+
for (const configName of unsupportedConfigs) {
101+
console.log(`\n${configName}: `, localConfigs[configName]);
102+
}
103+
console.log(
104+
'\nPlease visit https://api.browserstack.com/5/browsers or https://api.browserstack.com/5/browsers?flat=true to choose new configurations.',
105+
);
106+
} else {
107+
console.log('\nAll configurations supported!\n');
108+
}
109+
110+
// report on real_mobile updates
111+
if (realMobileUpdates.length) {
112+
console.log('\nFound supported browser configurations which need real_mobile updated:\n');
113+
for (const configName of realMobileUpdates) {
114+
console.log(configName, 'new real_mobile value: ', localConfigs[configName].real_mobile);
115+
}
116+
}
117+
};
118+
119+
const findUnsupportedConfigs = localConfigs => {
120+
if (!hasCreds()) {
121+
console.warn(
122+
'Unable to find API credentials in env. Please export them as BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY.',
123+
);
124+
return;
125+
}
126+
127+
fetchCurrentData(browserstackUsername, browserstackAccessKey)
128+
.then(data => checkLocalConfigsVsBrowserStack(localConfigs, data))
129+
.catch(err => console.log(err));
130+
};
131+
132+
findUnsupportedConfigs(localConfigs);
Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,60 @@
1+
// To check if all of these browsers are still viable, run
2+
// yarn test:integration:checkbrowsers
3+
14
module.exports = {
25
bs_android_4: {
36
base: "BrowserStack",
4-
browser: "Android",
7+
browser: "Android Browser",
58
device: "Google Nexus 5",
69
os: "android",
710
os_version: "4.4",
811
real_mobile: true,
12+
browser_version: null,
913
},
1014
bs_android_5: {
1115
base: "BrowserStack",
12-
browser: "Android",
16+
browser: "Android Browser",
1317
device: "Google Nexus 9",
1418
os: "android",
1519
os_version: "5.1",
1620
real_mobile: true,
21+
browser_version: null,
1722
},
1823
bs_android_6: {
1924
base: "BrowserStack",
20-
browser: "Android",
25+
browser: "Android Browser",
2126
device: "Samsung Galaxy S7",
2227
os: "android",
2328
os_version: "6.0",
2429
real_mobile: true,
30+
browser_version: null,
2531
},
2632
bs_android_7: {
2733
base: "BrowserStack",
28-
browser: "Android",
34+
browser: "Android Browser",
2935
device: "Samsung Galaxy S8",
3036
os: "android",
3137
os_version: "7.0",
3238
real_mobile: true,
39+
browser_version: null,
3340
},
3441
bs_android_8: {
3542
base: "BrowserStack",
36-
browser: "Android",
43+
browser: "Android Browser",
3744
device: "Samsung Galaxy S9",
3845
os: "android",
3946
os_version: "8.0",
4047
real_mobile: true,
48+
browser_version: null,
4149
},
4250
bs_android_9: {
4351
base: "BrowserStack",
44-
browser: "Android",
52+
browser: "Android Browser",
4553
device: "Samsung Galaxy S9 Plus",
4654
os: "android",
4755
os_version: "9.0",
4856
real_mobile: true,
57+
browser_version: null,
4958
},
5059
bs_ios_11: {
5160
base: "BrowserStack",
@@ -54,6 +63,7 @@ module.exports = {
5463
os: "ios",
5564
os_version: "11.4",
5665
real_mobile: true,
66+
browser_version: null,
5767
},
5868
bs_ios_12: {
5969
base: "BrowserStack",
@@ -62,47 +72,60 @@ module.exports = {
6272
os: "ios",
6373
os_version: "12.1",
6474
real_mobile: true,
75+
browser_version: null,
6576
},
6677
bs_ie10: {
6778
base: "BrowserStack",
6879
browser: "IE",
6980
browser_version: "10.0",
7081
os: "Windows",
7182
os_version: "8",
83+
device: null,
84+
real_mobile: null,
7285
},
7386
bs_ie11: {
7487
base: "BrowserStack",
7588
browser: "IE",
7689
browser_version: "11.0",
7790
os: "Windows",
7891
os_version: "10",
92+
device: null,
93+
real_mobile: null,
7994
},
8095
bs_safari: {
8196
base: "BrowserStack",
8297
browser: "Safari",
8398
browser_version: "latest",
8499
os: "OS X",
85100
os_version: "Mojave",
101+
device: null,
102+
real_mobile: null,
86103
},
87104
bs_edge: {
88105
base: "BrowserStack",
89106
browser: "Edge",
90107
browser_version: "latest",
91108
os: "Windows",
92109
os_version: "10",
110+
device: null,
111+
real_mobile: null,
93112
},
94113
bs_firefox: {
95114
base: "BrowserStack",
96115
browser: "Firefox",
97116
browser_version: "latest",
98117
os: "Windows",
99118
os_version: "10",
119+
device: null,
120+
real_mobile: null,
100121
},
101122
bs_chrome: {
102123
base: "BrowserStack",
103124
browser: "Chrome",
104125
browser_version: "latest",
105126
os: "Windows",
106127
os_version: "10",
128+
device: null,
129+
real_mobile: null,
107130
},
108131
};

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,6 +2842,11 @@ btoa-lite@^1.0.0:
28422842
resolved "https://registry.yarnpkg.com/btoa-lite/-/btoa-lite-1.0.0.tgz#337766da15801210fdd956c22e9c6891ab9d0337"
28432843
integrity sha1-M3dm2hWAEhD92VbCLpxokaudAzc=
28442844

2845+
btoa@^1.2.1:
2846+
version "1.2.1"
2847+
resolved "https://registry.yarnpkg.com/btoa/-/btoa-1.2.1.tgz#01a9909f8b2c93f6bf680ba26131eb30f7fa3d73"
2848+
integrity sha512-SB4/MIGlsiVkMcHmT+pSmIPoNDoHg+7cMzmt3Uxt628MTz2487DKSqK/fuhFBrkuqrYv5UCEnACpF4dTFNKc/g==
2849+
28452850
buffer-alloc-unsafe@^1.1.0:
28462851
version "1.1.0"
28472852
resolved "https://registry.yarnpkg.com/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz#bd7dc26ae2972d0eda253be061dba992349c19f0"
@@ -7896,6 +7901,11 @@ node-fetch@^2.2.0, node-fetch@^2.3.0:
78967901
version "2.3.0"
78977902
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.3.0.tgz#1a1d940bbfb916a1d3e0219f037e89e71f8c5fa5"
78987903

7904+
node-fetch@^2.6.0:
7905+
version "2.6.0"
7906+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
7907+
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==
7908+
78997909
node-forge@^0.7.4:
79007910
version "0.7.6"
79017911
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.7.6.tgz#fdf3b418aee1f94f0ef642cd63486c77ca9724ac"

0 commit comments

Comments
 (0)