@percy/webdriver-utils 1.27.5-beta.0 → 1.27.6-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ export default class CapabilitiesManager {
2
+ constructor(capabilities) {
3
+ this.capabilities = capabilities;
4
+ }
5
+ }
@@ -0,0 +1,72 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { colors } from '@percy/logger/utils';
4
+ import semver from 'semver';
5
+ export default class CapabilitiesValidator {
6
+ constructor(automateCapabilities, sessionCapabilities) {
7
+ this.automateCapabilities = automateCapabilities;
8
+ this.sessionCapabilities = sessionCapabilities;
9
+ }
10
+ WARN_LOG_LEVEL = 'WARN';
11
+ ERROR_LOG_LEVEL = 'ERROR';
12
+ log(message, errorLevel = this.ERROR_LOG_LEVEL) {
13
+ if (errorLevel === this.WARN_LOG_LEVEL) {
14
+ console.warn(colors.yellow(message));
15
+ } else if (errorLevel === this.ERROR_LOG_LEVEL) {
16
+ console.error(colors.red(message));
17
+ }
18
+ }
19
+ existsInArray(array, value) {
20
+ if (!array || array.length === 0) return false;
21
+ return array.some(element => {
22
+ return element === value;
23
+ });
24
+ }
25
+ validateBrowserOSVersions() {
26
+ var _this$sessionCapabili, _this$sessionCapabili2;
27
+ const cwd = process.cwd();
28
+ const excludeBrowserData = JSON.parse(fs.readFileSync(path.join(cwd, 'packages/webdriver-utils/src/util/exclude_browsers.json')));
29
+ let {
30
+ os,
31
+ osVersion,
32
+ browserName,
33
+ browserVersion,
34
+ deviceName
35
+ } = this.automateCapabilities;
36
+ const platform = (_this$sessionCapabili = this.sessionCapabilities) === null || _this$sessionCapabili === void 0 ? void 0 : (_this$sessionCapabili2 = _this$sessionCapabili.platformName) === null || _this$sessionCapabili2 === void 0 ? void 0 : _this$sessionCapabili2.toLowerCase();
37
+ if (!os || !osVersion || !browserName || !browserVersion) {
38
+ this.log('OS/Browser Combination is not supported on Percy');
39
+ throw new Error('OS/Browser Combination is not supported on Percy');
40
+ }
41
+ const isMobile = ['ios', 'android'].includes(platform);
42
+ if (isMobile && !deviceName) {
43
+ this.log('Device capabilities are incorrect or not supported on Percy');
44
+ throw new Error('Device capabilities are incorrect or not supported on Percy');
45
+ }
46
+ if (excludeBrowserData !== null && excludeBrowserData !== void 0 && excludeBrowserData.os[os]) {
47
+ const osData = excludeBrowserData === null || excludeBrowserData === void 0 ? void 0 : excludeBrowserData.os[os];
48
+ if (osData !== null && osData !== void 0 && osData.os_versions) {
49
+ if (this.existsInArray(osData.os_versions, osVersion)) {
50
+ this.log(`${os} ${osVersion} is not supported on Percy`);
51
+ throw new Error(`${os} ${osVersion} is not supported on Percy`);
52
+ }
53
+ }
54
+ if (osData !== null && osData !== void 0 && osData.browsers) {
55
+ const browserData = osData === null || osData === void 0 ? void 0 : osData.browsers[browserName.toLowerCase()];
56
+ if (browserData && browserData.min_version === 'all') {
57
+ this.log(`${browserName} is not supported on Percy`);
58
+ throw new Error(`${browserName} is not supported on Percy`);
59
+ } else if (browserData && parseInt(browserVersion, 10) < parseInt(browserData.min_version, 10)) {
60
+ this.log(`${browserName}: ${browserVersion} is not supported on Percy`);
61
+ throw new Error(`${browserName}: ${browserVersion} is not supported on Percy`);
62
+ }
63
+ }
64
+ if (osData !== null && osData !== void 0 && osData.device_names) {
65
+ if (this.existsInArray(osData === null || osData === void 0 ? void 0 : osData.device_names, deviceName)) {
66
+ this.log(`${deviceName} is not supported on Percy`);
67
+ throw new Error(`${deviceName} is not supported in Percy`);
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,7 @@
1
+ export const SELENIUM_TO_API_OS_MAPPING = {
2
+ MAC: 'OS X',
3
+ WIN8: 'Windows',
4
+ XP: 'Windows',
5
+ WINDOWS: 'Windows',
6
+ ANY: 'OS X'
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/webdriver-utils",
3
- "version": "1.27.5-beta.0",
3
+ "version": "1.27.6-alpha.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "publishConfig": {
11
11
  "access": "public",
12
- "tag": "latest"
12
+ "tag": "alpha"
13
13
  },
14
14
  "engines": {
15
15
  "node": ">=14"
@@ -29,8 +29,8 @@
29
29
  "test:coverage": "yarn test --coverage"
30
30
  },
31
31
  "dependencies": {
32
- "@percy/config": "1.27.5-beta.0",
33
- "@percy/sdk-utils": "1.27.5-beta.0"
32
+ "@percy/config": "1.27.6-alpha.0",
33
+ "@percy/sdk-utils": "1.27.6-alpha.0"
34
34
  },
35
- "gitHead": "5fed59aa21112e7854a414306504ce7243df7365"
35
+ "gitHead": "415a083dc13e9453990b042a41d6676f6618df0c"
36
36
  }