@applitools/eyes-cypress 3.28.0 → 3.28.2

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/bin/eyes-setup.js +21 -21
  3. package/dist/browser/spec-driver.js +2 -5
  4. package/index.d.ts +7 -6
  5. package/index.js +2 -2
  6. package/package.json +13 -11
  7. package/src/browser/commands.js +79 -84
  8. package/src/browser/eyesCheckMapping.js +77 -71
  9. package/src/browser/eyesOpenMapping.js +28 -32
  10. package/src/browser/makeSend.js +5 -10
  11. package/src/browser/refer.js +28 -28
  12. package/src/browser/sendRequest.js +6 -6
  13. package/src/browser/socket.js +72 -73
  14. package/src/browser/socketCommands.js +34 -45
  15. package/src/browser/spec-driver.ts +33 -41
  16. package/src/plugin/concurrencyMsg.js +4 -4
  17. package/src/plugin/config.js +16 -17
  18. package/src/plugin/configParams.js +3 -3
  19. package/src/plugin/defaultPort.js +1 -1
  20. package/src/plugin/errorDigest.js +27 -35
  21. package/src/plugin/getErrorsAndDiffs.js +11 -11
  22. package/src/plugin/handleTestResults.js +16 -19
  23. package/src/plugin/hooks.js +12 -12
  24. package/src/plugin/isGlobalHooksSupported.js +6 -7
  25. package/src/plugin/pluginExport.js +38 -43
  26. package/src/plugin/server.js +50 -53
  27. package/src/plugin/startPlugin.js +9 -9
  28. package/src/plugin/webSocket.js +63 -64
  29. package/src/setup/addEyesCommands.js +12 -12
  30. package/src/setup/addEyesCypressPlugin.js +6 -6
  31. package/src/setup/getCypressPaths.js +28 -32
  32. package/src/setup/getCypressVersion.js +7 -9
  33. package/src/setup/getFilePath.js +8 -8
  34. package/src/setup/handleCommands.js +11 -11
  35. package/src/setup/handlePlugin.js +10 -10
  36. package/src/setup/handleTypeScript.js +8 -8
  37. package/src/setup/isCommandsDefined.js +3 -3
  38. package/src/setup/isPluginDefined.js +3 -3
@@ -1,9 +1,9 @@
1
1
  /* global Node */
2
2
  function eyesCheckMapValues({args, refer}) {
3
3
  if (typeof args === `string`) {
4
- args = {tag: args};
4
+ args = {tag: args}
5
5
  }
6
- const config = args; // just did it for having less git changes at this moment
6
+ const config = args // just did it for having less git changes at this moment
7
7
  const mappedValues = [
8
8
  'tag',
9
9
  'scriptHooks',
@@ -16,10 +16,10 @@ function eyesCheckMapValues({args, refer}) {
16
16
  'region',
17
17
  'selector',
18
18
  'element',
19
- ];
19
+ ]
20
20
 
21
- let regionSettings = {};
22
- let shadowDomSettings = {};
21
+ let regionSettings = {}
22
+ let shadowDomSettings = {}
23
23
  const checkSettings = {
24
24
  name: config.tag,
25
25
  hooks: config.scriptHooks,
@@ -29,7 +29,7 @@ function eyesCheckMapValues({args, refer}) {
29
29
  layoutRegions: convertPaddedRegion(config.layout),
30
30
  contentRegions: convertPaddedRegion(config.content),
31
31
  accessibilityRegions: convertAccessabilityRegions(config.accessibility),
32
- };
32
+ }
33
33
 
34
34
  if (config.target === 'region') {
35
35
  if (!Array.isArray(config.selector)) {
@@ -37,12 +37,12 @@ function eyesCheckMapValues({args, refer}) {
37
37
  if (isHTMLElement(config.element)) {
38
38
  regionSettings = {
39
39
  region: Object.assign(refer.ref(config.element), {type: 'element'}),
40
- };
40
+ }
41
41
  } else {
42
42
  // JQuery element
43
43
  regionSettings = {
44
44
  region: Object.assign(refer.ref(config.element[0]), {type: 'element'}),
45
- };
45
+ }
46
46
  }
47
47
  } else if (
48
48
  config.region &&
@@ -58,114 +58,121 @@ function eyesCheckMapValues({args, refer}) {
58
58
  width: config.region.width,
59
59
  height: config.region.height,
60
60
  },
61
- };
61
+ }
62
62
  } else if (!config.hasOwnProperty('selector')) {
63
63
  regionSettings = {
64
64
  region: config.region,
65
- };
65
+ }
66
66
  } else {
67
67
  regionSettings = {
68
68
  region: config.selector,
69
- };
69
+ }
70
70
  }
71
71
  } else {
72
- const selectors = config.selector;
72
+ const selectors = config.selector
73
73
  for (let i = selectors.length - 1; i > -1; i--) {
74
74
  if (i === selectors.length - 1) {
75
- shadowDomSettings['shadow'] = selectors[i].selector;
75
+ shadowDomSettings['shadow'] = selectors[i].selector
76
76
  } else {
77
- const prevSettings = Object.assign({}, shadowDomSettings);
78
- shadowDomSettings['selector'] = selectors[i].selector;
77
+ const prevSettings = Object.assign({}, shadowDomSettings)
78
+ shadowDomSettings['selector'] = selectors[i].selector
79
79
  if (!prevSettings.hasOwnProperty('selector')) {
80
- shadowDomSettings['shadow'] = prevSettings.shadow;
80
+ shadowDomSettings['shadow'] = prevSettings.shadow
81
81
  } else {
82
- shadowDomSettings['shadow'] = prevSettings;
82
+ shadowDomSettings['shadow'] = prevSettings
83
83
  }
84
84
  }
85
85
  }
86
- regionSettings = {region: shadowDomSettings};
86
+ regionSettings = {region: shadowDomSettings}
87
87
  }
88
88
  }
89
89
 
90
90
  for (const val of mappedValues) {
91
91
  if (config.hasOwnProperty(val)) {
92
- delete config[val];
92
+ delete config[val]
93
93
  }
94
94
  }
95
95
 
96
- return Object.assign({}, checkSettings, regionSettings, config);
96
+ return Object.assign({}, checkSettings, regionSettings, config)
97
97
 
98
98
  // #region helper functions
99
99
 
100
100
  function convertPaddedRegion(regions) {
101
- if (!regions) return;
102
- if (!Array.isArray(regions)) regions = [regions];
103
- let resRegions = [];
101
+ if (!regions) return
102
+ if (!Array.isArray(regions)) regions = [regions]
103
+ let resRegions = []
104
104
  for (const region of regions) {
105
105
  if (region.element || isHTMLElement(region) || region.jquery) {
106
106
  if (region.padding || region.regionId) {
107
- let currRefElements = refElements(region.element);
107
+ let currRefElements = refElements(region.element)
108
108
  for (const refElement of currRefElements) {
109
- let curr = {region: refElement};
109
+ let curr = {region: refElement}
110
110
  if (region.padding) {
111
- curr.padding = region.padding;
111
+ curr.padding = region.padding
112
112
  }
113
113
  if (region.regionId) {
114
- curr.regionId = region.regionId;
114
+ curr.regionId = region.regionId
115
115
  }
116
- resRegions.push(curr);
116
+ resRegions.push(curr)
117
117
  }
118
118
  } else {
119
- resRegions = [...resRegions, ...refElements(region)];
119
+ resRegions = [...resRegions, ...refElements(region)]
120
120
  }
121
121
  } else {
122
122
  if (region.selector && !region.type) {
123
- region.region = region.selector;
124
- delete region.selector;
123
+ region.region = region.selector
124
+ delete region.selector
125
125
  }
126
- resRegions.push(region);
126
+ resRegions.push(region)
127
127
  }
128
128
  }
129
- return resRegions;
129
+ return resRegions
130
130
  }
131
131
 
132
132
  function convertAccessabilityRegions(accessibilityRegions) {
133
- if (!accessibilityRegions) return accessibilityRegions;
134
- const accessibility = [];
133
+ if (!accessibilityRegions) return accessibilityRegions
134
+ if (!Array.isArray(accessibilityRegions)) {
135
+ accessibilityRegions = [accessibilityRegions]
136
+ }
137
+ const accessibility = []
135
138
 
136
139
  accessibilityRegions.map(region => {
137
140
  const accessabilityRegion = {
138
141
  type: region.accessibilityType,
139
- };
142
+ }
140
143
  if (region.hasOwnProperty('selector')) {
141
- accessabilityRegion.region = region.selector;
142
- accessibility.push(accessabilityRegion);
144
+ accessabilityRegion.region = region.selector
145
+ accessibility.push(accessabilityRegion)
143
146
  } else if (region.hasOwnProperty('element')) {
144
- const elements = refElements(region.element);
147
+ const elements = refElements(region.element)
148
+ delete region['element']
145
149
  for (const element of elements) {
146
- accessibility.push(Object.assign({}, accessabilityRegion, {region: element}));
150
+ accessibility.push(Object.assign({}, region, accessabilityRegion, {region: element}))
147
151
  }
148
152
  } else if (region.hasOwnProperty('region')) {
149
- region.type = region.region.accessibilityType;
150
- delete region.region.accessibilityType;
151
- accessibility.push(region);
153
+ region.type = region.region.accessibilityType
154
+ delete region.region.accessibilityType
155
+ accessibility.push(region)
152
156
  } else {
153
157
  accessabilityRegion.region = {
154
158
  y: region.top,
155
159
  x: region.left,
156
160
  width: region.width,
157
161
  height: region.height,
158
- };
159
- accessibility.push(accessabilityRegion);
162
+ }
163
+ accessibility.push(accessabilityRegion)
160
164
  }
161
- });
165
+ })
162
166
 
163
- return accessibility;
167
+ return accessibility
164
168
  }
165
169
 
166
170
  function convertFloatingRegion(floatingRegions) {
167
- if (!floatingRegions) return floatingRegions;
168
- const floating = [];
171
+ if (!floatingRegions) return floatingRegions
172
+ if (!Array.isArray(floatingRegions)) {
173
+ floatingRegions = [floatingRegions]
174
+ }
175
+ const floating = []
169
176
 
170
177
  for (const region of floatingRegions) {
171
178
  const floatingRegion = {
@@ -173,49 +180,48 @@ function eyesCheckMapValues({args, refer}) {
173
180
  maxLeftOffset: region.maxLeftOffset || 0,
174
181
  maxUpOffset: region.maxUpOffset || 0,
175
182
  maxRightOffset: region.maxRightOffset || 0,
176
- };
183
+ }
177
184
  if (region.hasOwnProperty('selector')) {
178
- floatingRegion.region = region.selector;
179
- floating.push(floatingRegion);
185
+ floatingRegion.region = region.selector
186
+ floating.push(floatingRegion)
180
187
  } else if (region.hasOwnProperty('element')) {
181
- const elements = refElements(region.element);
188
+ const elements = refElements(region.element)
189
+ delete region['element']
182
190
  for (const element of elements) {
183
- floating.push(Object.assign({}, floatingRegion, {region: element}));
191
+ floating.push(Object.assign({}, region, floatingRegion, {region: element}))
184
192
  }
185
193
  } else if (region.hasOwnProperty('region')) {
186
- floating.push(region);
194
+ floating.push(region)
187
195
  } else {
188
196
  floatingRegion.region = {
189
197
  y: region.top,
190
198
  x: region.left,
191
199
  width: region.width,
192
200
  height: region.height,
193
- };
194
- floating.push(floatingRegion);
201
+ }
202
+ floating.push(floatingRegion)
195
203
  }
196
204
  }
197
- return floating;
205
+ return floating
198
206
  }
199
207
 
200
208
  function refElements(regions) {
201
- if (!regions) return regions;
202
- if (!Array.isArray(regions)) regions = [regions];
203
- const elements = [];
209
+ if (!regions) return regions
210
+ if (!Array.isArray(regions)) regions = [regions]
211
+ const elements = []
204
212
  for (const region of regions) {
205
213
  if (isHTMLElement(region)) {
206
- elements.push(Object.assign(refer.ref(region), {type: 'element'}));
214
+ elements.push(Object.assign(refer.ref(region), {type: 'element'}))
207
215
  } else if (region.jquery) {
208
- region.each(function() {
216
+ region.each(function () {
209
217
  // there's a small chance that `this` is not an HTML element. So we just verify it.
210
- elements.push(
211
- isHTMLElement(this) ? Object.assign(refer.ref(this), {type: 'element'}) : this,
212
- );
213
- });
218
+ elements.push(isHTMLElement(this) ? Object.assign(refer.ref(this), {type: 'element'}) : this)
219
+ })
214
220
  } else {
215
- elements.push(region);
221
+ elements.push(region)
216
222
  }
217
223
  }
218
- return elements;
224
+ return elements
219
225
  }
220
226
 
221
227
  // #endregion
@@ -224,7 +230,7 @@ function eyesCheckMapValues({args, refer}) {
224
230
  function isHTMLElement(element) {
225
231
  // Avoiding instanceof here since the element might come from an iframe, and `instanceof HTMLElement` would fail.
226
232
  // This check looks naive, but if anyone passes something like {nodeType: 1} as a region, then I'm fine with them crashing :)
227
- return element.nodeType && element.nodeType === Node.ELEMENT_NODE;
233
+ return element.nodeType && element.nodeType === Node.ELEMENT_NODE
228
234
  }
229
235
 
230
- module.exports = {eyesCheckMapValues};
236
+ module.exports = {eyesCheckMapValues}
@@ -1,22 +1,22 @@
1
1
  const batchPropertiesRetriever = (args, appliConfFile) => {
2
- return function(prop, nestedProp) {
3
- nestedProp = nestedProp || prop;
2
+ return function (prop, nestedProp) {
3
+ nestedProp = nestedProp || prop
4
4
  if (args.hasOwnProperty(prop)) {
5
- return args[prop];
5
+ return args[prop]
6
6
  } else if (args.batch && args.batch.hasOwnProperty(nestedProp)) {
7
- return args.batch[nestedProp];
7
+ return args.batch[nestedProp]
8
8
  } else if (appliConfFile.hasOwnProperty(prop)) {
9
- return appliConfFile[prop];
9
+ return appliConfFile[prop]
10
10
  } else if (appliConfFile.batch && appliConfFile.batch.hasOwnProperty(nestedProp)) {
11
- return appliConfFile.batch[nestedProp];
11
+ return appliConfFile.batch[nestedProp]
12
12
  }
13
- return undefined;
14
- };
15
- };
13
+ return undefined
14
+ }
15
+ }
16
16
  function eyesOpenMapValues({args, appliConfFile, testName, shouldUseBrowserHooks}) {
17
- let browsersInfo = args.browser || appliConfFile.browser;
18
- let accessibilitySettings = args.accessibilityValidation || appliConfFile.accessibilityValidation;
19
- const batchProperties = batchPropertiesRetriever(args, appliConfFile);
17
+ let browsersInfo = args.browser || appliConfFile.browser
18
+ let accessibilitySettings = args.accessibilityValidation || appliConfFile.accessibilityValidation
19
+ const batchProperties = batchPropertiesRetriever(args, appliConfFile)
20
20
  const batch = {
21
21
  id: batchProperties('batchId', 'id'),
22
22
  name: batchProperties('batchName', 'name'),
@@ -25,10 +25,10 @@ function eyesOpenMapValues({args, appliConfFile, testName, shouldUseBrowserHooks
25
25
  properties:
26
26
  (args.batch ? args.batch.properties : undefined) ||
27
27
  (appliConfFile.batch ? appliConfFile.batch.properties : undefined),
28
- };
28
+ }
29
29
  for (let prop in batch) {
30
30
  if (typeof batch[prop] === 'undefined') {
31
- delete batch[prop];
31
+ delete batch[prop]
32
32
  }
33
33
  }
34
34
 
@@ -43,15 +43,15 @@ function eyesOpenMapValues({args, appliConfFile, testName, shouldUseBrowserHooks
43
43
  'batchName',
44
44
  'batchId',
45
45
  'batchSequenceName',
46
- ];
46
+ ]
47
47
 
48
48
  if (browsersInfo) {
49
49
  if (Array.isArray(browsersInfo)) {
50
50
  for (const [index, value] of browsersInfo.entries()) {
51
- browsersInfo[index] = fillDefaultBrowserName(value);
51
+ browsersInfo[index] = fillDefaultBrowserName(value)
52
52
  }
53
53
  } else {
54
- browsersInfo = [fillDefaultBrowserName(browsersInfo)];
54
+ browsersInfo = [fillDefaultBrowserName(browsersInfo)]
55
55
  }
56
56
  }
57
57
 
@@ -62,15 +62,15 @@ function eyesOpenMapValues({args, appliConfFile, testName, shouldUseBrowserHooks
62
62
  useDom: args.useDom || appliConfFile.useDom,
63
63
  enablePatterns: args.enablePatterns || appliConfFile.enablePatterns,
64
64
  ignoreDisplacements: args.ignoreDisplacements || appliConfFile.ignoreDisplacements,
65
- };
65
+ }
66
66
 
67
- const appliConfFileCopy = {...appliConfFile};
67
+ const appliConfFileCopy = {...appliConfFile}
68
68
  for (const val of mappedValues) {
69
69
  if (args.hasOwnProperty(val)) {
70
- delete args[val];
70
+ delete args[val]
71
71
  }
72
72
  if (appliConfFileCopy.hasOwnProperty(val)) {
73
- delete appliConfFileCopy[val];
73
+ delete appliConfFileCopy[val]
74
74
  }
75
75
  }
76
76
 
@@ -79,27 +79,23 @@ function eyesOpenMapValues({args, appliConfFile, testName, shouldUseBrowserHooks
79
79
  browsersInfo,
80
80
  defaultMatchSettings,
81
81
  batch,
82
- };
82
+ }
83
83
 
84
- return Object.assign(
85
- {testName, dontCloseBatches: !shouldUseBrowserHooks},
86
- appliConfFileCopy,
87
- mappedArgs,
88
- );
84
+ return Object.assign({testName, dontCloseBatches: !shouldUseBrowserHooks}, appliConfFileCopy, mappedArgs)
89
85
  }
90
86
 
91
87
  function fillDefaultBrowserName(browser) {
92
88
  if (!browser.iosDeviceInfo && !browser.chromeEmulationInfo) {
93
89
  if (!browser.name) {
94
- browser.name = 'chrome';
90
+ browser.name = 'chrome'
95
91
  }
96
92
  if (browser.deviceName) {
97
- browser = {chromeEmulationInfo: browser};
93
+ browser = {chromeEmulationInfo: browser}
98
94
  }
99
- return browser;
95
+ return browser
100
96
  } else {
101
- return browser;
97
+ return browser
102
98
  }
103
99
  }
104
100
 
105
- module.exports = {eyesOpenMapValues};
101
+ module.exports = {eyesOpenMapValues}
@@ -1,18 +1,13 @@
1
- 'use strict';
1
+ 'use strict'
2
2
 
3
3
  function makeSend(port, fetch) {
4
- return function send({
5
- command,
6
- data,
7
- method = 'POST',
8
- headers = {'Content-Type': 'application/json'},
9
- }) {
4
+ return function send({command, data, method = 'POST', headers = {'Content-Type': 'application/json'}}) {
10
5
  return fetch(`https://localhost:${port}/eyes/${command}`, {
11
6
  method,
12
7
  body: headers['Content-Type'] === 'application/json' ? JSON.stringify(data) : data,
13
8
  headers,
14
- });
15
- };
9
+ })
10
+ }
16
11
  }
17
12
 
18
- module.exports = makeSend;
13
+ module.exports = makeSend
@@ -1,70 +1,70 @@
1
1
  /* global Node */
2
2
 
3
- const uuid = require('uuid');
4
- const REF_ID = 'applitools-ref-id';
3
+ const uuid = require('uuid')
4
+ const REF_ID = 'applitools-ref-id'
5
5
 
6
6
  class Refer {
7
7
  constructor() {
8
- this.store = new Map();
9
- this.relation = new Map();
8
+ this.store = new Map()
9
+ this.relation = new Map()
10
10
  }
11
11
 
12
12
  isRef(ref) {
13
- return Boolean(ref && ref[REF_ID]);
13
+ return Boolean(ref && ref[REF_ID])
14
14
  }
15
15
 
16
16
  check(value) {
17
- if (!value) return;
17
+ if (!value) return
18
18
  if (value.nodeType === Node.ELEMENT_NODE) {
19
- return 'element';
19
+ return 'element'
20
20
  } else if (value.nodeType === Node.DOCUMENT_NODE || value.ownerDocument) {
21
- return 'context';
21
+ return 'context'
22
22
  } else if (value.constructor && value.constructor.name === 'Window') {
23
- return 'driver';
23
+ return 'driver'
24
24
  }
25
25
  }
26
26
 
27
27
  ref(value, parentRef) {
28
- const refType = this.check(value);
28
+ const refType = this.check(value)
29
29
  if (refType) {
30
- const ref = uuid.v4();
31
- this.store.set(ref, value);
30
+ const ref = uuid.v4()
31
+ this.store.set(ref, value)
32
32
  if (parentRef) {
33
- let childRefs = this.relation.get(parentRef[REF_ID]);
33
+ let childRefs = this.relation.get(parentRef[REF_ID])
34
34
  if (!childRefs) {
35
- childRefs = new Set();
36
- this.relation.set(parentRef[REF_ID], childRefs);
35
+ childRefs = new Set()
36
+ this.relation.set(parentRef[REF_ID], childRefs)
37
37
  }
38
- childRefs.add({[REF_ID]: ref});
38
+ childRefs.add({[REF_ID]: ref})
39
39
  }
40
- return {[REF_ID]: ref, type: refType};
40
+ return {[REF_ID]: ref, type: refType}
41
41
  } else if (Array.isArray(value)) {
42
- return value.map(value => this.ref(value, parentRef));
42
+ return value.map(value => this.ref(value, parentRef))
43
43
  } else if (typeof value === 'object' && value !== null) {
44
44
  return Object.entries(value).reduce((obj, [key, value]) => {
45
- return Object.assign(obj, {[key]: this.ref(value, parentRef)});
46
- }, {});
45
+ return Object.assign(obj, {[key]: this.ref(value, parentRef)})
46
+ }, {})
47
47
  } else {
48
- return value;
48
+ return value
49
49
  }
50
50
  }
51
51
 
52
52
  deref(ref) {
53
53
  if (this.isRef(ref)) {
54
- return this.store.get(ref[REF_ID]);
54
+ return this.store.get(ref[REF_ID])
55
55
  } else {
56
- return ref;
56
+ return ref
57
57
  }
58
58
  }
59
59
 
60
60
  destroy(ref) {
61
- if (!this.isRef(ref)) return;
62
- const childRefs = this.relation.get(ref[REF_ID]);
61
+ if (!this.isRef(ref)) return
62
+ const childRefs = this.relation.get(ref[REF_ID])
63
63
  if (childRefs) {
64
- childRefs.forEach(childRef => this.destroy(childRef));
64
+ childRefs.forEach(childRef => this.destroy(childRef))
65
65
  }
66
- this.store.delete(ref[REF_ID]);
66
+ this.store.delete(ref[REF_ID])
67
67
  }
68
68
  }
69
69
 
70
- module.exports = Refer;
70
+ module.exports = Refer
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ 'use strict'
2
2
 
3
3
  function makeSendRequest(send) {
4
4
  return function sendRequest(args) {
@@ -6,11 +6,11 @@ function makeSendRequest(send) {
6
6
  .then(resp => resp.json())
7
7
  .then(body => {
8
8
  if (!body.success) {
9
- throw new Error(body.error);
9
+ throw new Error(body.error)
10
10
  }
11
- return body.result;
12
- });
13
- };
11
+ return body.result
12
+ })
13
+ }
14
14
  }
15
15
 
16
- module.exports = makeSendRequest;
16
+ module.exports = makeSendRequest