@applitools/eyes-cypress 3.24.0-beta.5 → 3.25.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +2191 -2195
  2. package/LICENSE +25 -25
  3. package/README.md +803 -782
  4. package/bin/eyes-setup.js +21 -21
  5. package/commands.js +2 -2
  6. package/dist/browser/spec-driver.js +110 -106
  7. package/dist/plugin/handler.js +55 -55
  8. package/eyes-index.d.ts +34 -34
  9. package/index.js +2 -2
  10. package/package.json +98 -97
  11. package/src/browser/commands.js +188 -188
  12. package/src/browser/eyesCheckMapping.js +104 -103
  13. package/src/browser/eyesOpenMapping.js +60 -60
  14. package/src/browser/makeSend.js +18 -18
  15. package/src/browser/refer.js +57 -57
  16. package/src/browser/sendRequest.js +16 -16
  17. package/src/browser/socket.js +144 -143
  18. package/src/browser/socketCommands.js +81 -81
  19. package/src/browser/spec-driver.ts +117 -111
  20. package/src/pem/server.cert +22 -22
  21. package/src/pem/server.key +27 -27
  22. package/src/plugin/concurrencyMsg.js +8 -8
  23. package/src/plugin/config.js +54 -54
  24. package/src/plugin/defaultPort.js +1 -1
  25. package/src/plugin/errorDigest.js +96 -96
  26. package/src/plugin/getErrorsAndDiffs.js +34 -34
  27. package/src/plugin/handleTestResults.js +35 -39
  28. package/src/plugin/handler.ts +58 -58
  29. package/src/plugin/hooks.js +51 -50
  30. package/src/plugin/isGlobalHooksSupported.js +13 -13
  31. package/src/plugin/pluginExport.js +60 -60
  32. package/src/plugin/server.js +98 -98
  33. package/src/plugin/startPlugin.js +15 -13
  34. package/src/plugin/webSocket.js +130 -130
  35. package/src/setup/addEyesCommands.js +24 -24
  36. package/src/setup/addEyesCypressPlugin.js +15 -15
  37. package/src/setup/getCypressConfig.js +16 -16
  38. package/src/setup/getFilePath.js +22 -22
  39. package/src/setup/handleCommands.js +23 -23
  40. package/src/setup/handlePlugin.js +23 -23
  41. package/src/setup/handleTypeScript.js +21 -21
  42. package/src/setup/isCommandsDefined.js +7 -7
  43. package/src/setup/isPluginDefined.js +7 -7
  44. package/test/fixtures/testAppCopies/.gitignore +1 -1
package/package.json CHANGED
@@ -1,97 +1,98 @@
1
- {
2
- "name": "@applitools/eyes-cypress",
3
- "version": "3.24.0-beta.5",
4
- "main": "index.js",
5
- "license": "SEE LICENSE IN LICENSE",
6
- "bin": {
7
- "eyes-setup": "./bin/eyes-setup.js"
8
- },
9
- "scripts": {
10
- "build": "tsc",
11
- "render": "run(){ npx cypress run --config integrationFolder=test/fixtures/testApp/cypress/render,pluginsFile=test/fixtures/testApp/cypress/plugins/index-render.js,supportFile=test/fixtures/testApp/cypress/support/index-run.js --env url=$1; }; run",
12
- "test:unit": "mocha --no-timeouts 'test/unit/**/*.test.js'",
13
- "test:it": "mocha --no-timeouts 'test/it/**/*.test.js'",
14
- "test:e2e": "mkdir -p test/fixtures/testAppCopies && mocha --no-timeouts 'test/e2e/**/*.test.js'",
15
- "lint": "echo 'lint'",
16
- "test": "yarn test:unit && yarn test:it && yarn test:e2e && yarn lint",
17
- "cypress": "cypress open --config-file test/fixtures/cypress-play.json",
18
- "cypress:new": "node_modules/cypress-new/bin/cypress open --config-file test/fixtures/cypress-play.json",
19
- "cypress:run": "cypress run --config-file test/fixtures/cypress-play.json --spec=test/fixtures/testApp/cypress/integration-play/play.js",
20
- "cypress:run:new": "node_modules/cypress-new/bin/cypress run --config-file test/fixtures/cypress-play.json --spec=test/fixtures/testApp/cypress/integration-play/play.js",
21
- "cypress:play": "cd test/fixtures/testApp && cypress run --config integrationFolder=cypress/integration-play,pluginsFile=cypress/plugins/index-play.js,supportFile=cypress/support/index-run.js --spec=cypress/integration-play/play.js",
22
- "preversion": "bongo preversion --skip-deps",
23
- "version": "bongo version",
24
- "postversion": "bongo postversion --skip-release-notification",
25
- "deps": "bongo deps",
26
- "generate:tests": "coverage-tests generate",
27
- "test:coverage": "cd test/coverage/generic && cypress run ; cd -",
28
- "test:coverage-custom": "cd test/coverage/generic && cypress run --config integrationFolder=cypress/integration-custom/",
29
- "prepublish:setup": "sudo apt-get install xvfb"
30
- },
31
- "files": [
32
- "src",
33
- "dist",
34
- "bin",
35
- "index.js",
36
- "commands.js",
37
- "eyes-index.d.ts"
38
- ],
39
- "types": "./eyes-index.d.ts",
40
- "engines": {
41
- "node": ">=8.0.0"
42
- },
43
- "repository": {
44
- "type": "git",
45
- "url": "git://github.com/applitools/eyes.sdk.javascript1.git",
46
- "directory": "packages/eyes-cypress"
47
- },
48
- "dependencies": {
49
- "@applitools/dom-snapshot": "4.5.12",
50
- "@applitools/eyes-universal": "1.1.1-beta.1",
51
- "@applitools/functional-commons": "1.6.0",
52
- "@applitools/logger": "1.0.11",
53
- "@applitools/visual-grid-client": "15.9.0",
54
- "body-parser": "1.19.0",
55
- "chalk": "3.0.0",
56
- "cors": "2.8.5",
57
- "express": "4.17.1",
58
- "lodash.flatten": "4.4.0",
59
- "uuid": "8.3.2",
60
- "ws": "8.5.0"
61
- },
62
- "devDependencies": {
63
- "@applitools/scripts": "1.1.0",
64
- "@applitools/sdk-coverage-tests": "^2.3.18",
65
- "@applitools/sdk-release-kit": "0.13.11",
66
- "@applitools/snaptdout": "1.0.1",
67
- "@applitools/test-server": "1.0.8",
68
- "@applitools/types": "^1.1.0",
69
- "@applitools/utils": "1.2.13",
70
- "@types/node": "17.0.13",
71
- "@types/ws": "^8.2.2",
72
- "@typescript-eslint/eslint-plugin": "^5.10.2",
73
- "@typescript-eslint/parser": "^5.10.2",
74
- "chai": "4.2.0",
75
- "chai-spies": "1.0.0",
76
- "cookie-parser": "1.4.4",
77
- "cypress": "6.5.0",
78
- "cypress-new": "npm:cypress@9",
79
- "eslint": "6.8.0",
80
- "eslint-plugin-mocha-no-only": "1.1.0",
81
- "eslint-plugin-node": "7.0.1",
82
- "eslint-plugin-prettier": "2.7.0",
83
- "husky": "4.3.8",
84
- "lodash.omit": "4.5.0",
85
- "mocha": "8.0.1",
86
- "morgan": "1.9.1",
87
- "ncp": "2.0.0",
88
- "node-fetch": "2.6.0",
89
- "prettier": "1.19.1",
90
- "typescript": "3.9.2"
91
- },
92
- "husky": {
93
- "hooks": {
94
- "pre-push": "yarn bongo lint"
95
- }
96
- }
97
- }
1
+ {
2
+ "name": "@applitools/eyes-cypress",
3
+ "version": "3.25.0",
4
+ "main": "index.js",
5
+ "license": "SEE LICENSE IN LICENSE",
6
+ "bin": {
7
+ "eyes-setup": "./bin/eyes-setup.js"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "render": "run(){ npx cypress run --config integrationFolder=test/fixtures/testApp/cypress/render,pluginsFile=test/fixtures/testApp/cypress/plugins/index-render.js,supportFile=test/fixtures/testApp/cypress/support/index-run.js --env url=$1; }; run",
12
+ "test:unit": "mocha --no-timeouts 'test/unit/**/*.test.js'",
13
+ "test:it": "mocha --no-timeouts 'test/it/**/*.test.js'",
14
+ "test:e2e": "mkdir -p test/fixtures/testAppCopies && mocha --no-timeouts 'test/e2e/**/*.test.js'",
15
+ "lint": "eslint \"**/*.js\"",
16
+ "test": "yarn test:unit && yarn test:it && yarn test:e2e && yarn test:coverage",
17
+ "cypress": "cypress open --config-file test/fixtures/cypress-play.json",
18
+ "cypress:new": "node_modules/cypress-new/bin/cypress open --config-file test/fixtures/cypress-play.json",
19
+ "cypress:run": "cypress run --config-file test/fixtures/cypress-play.json --spec=test/fixtures/testApp/cypress/integration-play/play.js",
20
+ "cypress:run:new": "node_modules/cypress-new/bin/cypress run --config-file test/fixtures/cypress-play.json --spec=test/fixtures/testApp/cypress/integration-play/play.js",
21
+ "cypress:play": "cd test/fixtures/testApp && cypress run --config integrationFolder=cypress/integration-play,pluginsFile=cypress/plugins/index-play.js,supportFile=cypress/support/index-run.js --spec=cypress/integration-play/play.js",
22
+ "preversion": "yarn build && bongo preversion --skip-deps",
23
+ "version": "bongo version",
24
+ "postversion": "bongo postversion --skip-release-notification",
25
+ "deps": "bongo deps",
26
+ "generate:tests": "coverage-tests generate",
27
+ "test:coverage": "yarn generate:tests && cd test/coverage/generic && unset APPLITOOLS_API_KEY && APPLITOOLS_BATCH_NAME='JS Coverage Tests: eyes-selenium' APPLITOOLS_BATCH_ID=$(uuidgen) cypress run ; cd -",
28
+ "prepublish:setup": "sudo apt-get install xvfb"
29
+ },
30
+ "files": [
31
+ "src",
32
+ "dist",
33
+ "bin",
34
+ "index.js",
35
+ "commands.js",
36
+ "eyes-index.d.ts"
37
+ ],
38
+ "types": "./eyes-index.d.ts",
39
+ "engines": {
40
+ "node": ">=8.0.0"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git://github.com/applitools/eyes.sdk.javascript1.git",
45
+ "directory": "packages/eyes-cypress"
46
+ },
47
+ "dependencies": {
48
+ "@applitools/dom-snapshot": "4.5.12",
49
+ "@applitools/eyes-api": "1.2.0",
50
+ "@applitools/eyes-universal": "2.0.1",
51
+ "@applitools/functional-commons": "1.6.0",
52
+ "@applitools/logger": "1.0.11",
53
+ "@applitools/visual-grid-client": "15.10.1",
54
+ "body-parser": "1.19.0",
55
+ "chalk": "3.0.0",
56
+ "cors": "2.8.5",
57
+ "express": "4.17.1",
58
+ "lodash.flatten": "4.4.0",
59
+ "uuid": "8.3.2",
60
+ "ws": "8.5.0"
61
+ },
62
+ "devDependencies": {
63
+ "@applitools/scripts": "1.1.0",
64
+ "@applitools/sdk-coverage-tests": "^2.3.18",
65
+ "@applitools/sdk-release-kit": "0.13.11",
66
+ "@applitools/snaptdout": "1.0.1",
67
+ "@applitools/test-server": "1.0.8",
68
+ "@applitools/test-utils": "1.1.5",
69
+ "@applitools/types": "^1.2.2",
70
+ "@applitools/utils": "1.2.13",
71
+ "@types/node": "17.0.13",
72
+ "@types/ws": "^8.2.2",
73
+ "@typescript-eslint/eslint-plugin": "^5.10.2",
74
+ "@typescript-eslint/parser": "^5.10.2",
75
+ "chai": "4.2.0",
76
+ "chai-spies": "1.0.0",
77
+ "cookie-parser": "1.4.4",
78
+ "cypress": "6.5.0",
79
+ "cypress-new": "npm:cypress@9",
80
+ "eslint": "8.10.0",
81
+ "eslint-plugin-mocha-no-only": "1.1.0",
82
+ "eslint-plugin-node": "7.0.1",
83
+ "eslint-plugin-prettier": "2.7.0",
84
+ "husky": "4.3.8",
85
+ "lodash.omit": "4.5.0",
86
+ "mocha": "8.0.1",
87
+ "morgan": "1.9.1",
88
+ "ncp": "2.0.0",
89
+ "node-fetch": "2.6.0",
90
+ "prettier": "1.19.1",
91
+ "typescript": "3.9.2"
92
+ },
93
+ "husky": {
94
+ "hooks": {
95
+ "pre-push": "yarn bongo lint"
96
+ }
97
+ }
98
+ }
@@ -1,188 +1,188 @@
1
- /* global Cypress,cy,after,navigator */
2
- 'use strict';
3
- const spec = require('../../dist/browser/spec-driver');
4
- const Refer = require('./refer');
5
- const Socket = require('./socket');
6
- const {socketCommands} = require('./socketCommands');
7
- const {eyesOpenMapValues} = require('./eyesOpenMapping');
8
- const {eyesCheckMapValues} = require('./eyesCheckMapping');
9
-
10
- const refer = new Refer(value => {
11
- if (!value || !value.constructor || !value.constructor.name) return false;
12
- const name = value.constructor.name;
13
- return name === 'HTMLDocument' || name === 'Window' || value.ownerDocument;
14
- });
15
- const socket = new Socket();
16
- const throwErr = Cypress.config('failCypressOnDiff');
17
- socketCommands(socket, refer);
18
- let connectedToUniversal = false;
19
-
20
- let manager,
21
- eyes,
22
- closePromiseArr = [];
23
-
24
- function getGlobalConfigProperty(prop) {
25
- const property = Cypress.config(prop);
26
- const shouldParse = ['eyesBrowser', 'eyesLayoutBreakpoints'];
27
- return property ? (shouldParse.includes(prop) ? JSON.parse(property) : property) : undefined;
28
- }
29
-
30
- const shouldUseBrowserHooks =
31
- !getGlobalConfigProperty('eyesIsDisabled') &&
32
- (getGlobalConfigProperty('isInteractive') ||
33
- !getGlobalConfigProperty('eyesIsGlobalHooksSupported'));
34
-
35
- Cypress.Commands.add('eyesGetAllTestResults', () => {
36
- return cy.then({timeout: 86400000}, async () => {
37
- if (isCurrentTestDisabled) {
38
- isCurrentTestDisabled = false;
39
- return;
40
- }
41
- await Promise.all(closePromiseArr);
42
- const summary = await socket.request('EyesManager.closeManager', {manager, throwErr});
43
- return summary // TODO delete this line
44
-
45
-
46
- // // TODO wrap with TestResultSummary class
47
- // const deleteTest = ({testId, batchId, secretToken}) => {
48
- // const {serverUrl, proxy, apiKey} = Cypress.config('appliConfFile')
49
- // return socket.request('Core.deleteTest', {testId, batchId, secretToken, serverUrl, proxy, apiKey})
50
- // }
51
-
52
- // return new TestResultsSummary({summary, deleteTest})
53
- });
54
- });
55
-
56
-
57
- // class TestResultSummary {
58
- // constructor({summary, deleteTest}) {
59
- // // same as in eyes-api
60
- // }
61
- // }
62
-
63
-
64
- if (shouldUseBrowserHooks) {
65
- after(() => {
66
- if (!manager) return;
67
- return cy.then({timeout: 86400000}, async () => {
68
- if (isCurrentTestDisabled) {
69
- isCurrentTestDisabled = false;
70
- return;
71
- }
72
- const resultConfig = {
73
- showLogs: Cypress.config('appliConfFile').showLogs,
74
- eyesFailCypressOnDiff: Cypress.config('eyesFailCypressOnDiff'),
75
- isTextTerminal: Cypress.config('isTextTerminal'),
76
- tapDirPath: Cypress.config('appliConfFile').tapDirPath,
77
- tapFileName: Cypress.config('appliConfFile').tapFileName,
78
- };
79
- await Promise.all(closePromiseArr);
80
- const summary = await socket.request('EyesManager.closeManager', {manager, throwErr});
81
- const testResults = summary.results.map(({testResults}) => testResults)
82
- const message = await socket.request('Test.printTestResults', {testResults, resultConfig});
83
- if (
84
- !!getGlobalConfigProperty('eyesFailCypressOnDiff') &&
85
- message &&
86
- message.includes('Eyes-Cypress detected diffs or errors')
87
- ) {
88
- throw new Error(message);
89
- }
90
- });
91
- });
92
- }
93
-
94
- let isCurrentTestDisabled;
95
-
96
- Cypress.Commands.add('eyesOpen', function(args = {}) {
97
- Cypress.log({name: 'Eyes: open'});
98
- Cypress.config('eyesOpenArgs', args);
99
- const {title: testName} = this.currentTest || this.test || Cypress.currentTest;
100
-
101
- if (Cypress.config('eyesIsDisabled') && args.isDisabled === false) {
102
- throw new Error(
103
- `Eyes-Cypress is disabled by an env variable or in the applitools.config.js file, but the "${testName}" test was passed isDisabled:false. A single test cannot be enabled when Eyes.Cypress is disabled through the global configuration. Please remove "isDisabled:false" from cy.eyesOpen() for this test, or enable Eyes.Cypress in the global configuration, either by unsetting the APPLITOOLS_IS_DISABLED env var, or by deleting 'isDisabled' from the applitools.config.js file.`,
104
- );
105
- }
106
- isCurrentTestDisabled = getGlobalConfigProperty('eyesIsDisabled') || args.isDisabled;
107
- if (isCurrentTestDisabled) return;
108
-
109
- return cy.then({timeout: 86400000}, async () => {
110
- setRootContext();
111
- const driver = refer.ref(cy.state('window').document);
112
-
113
- if (!connectedToUniversal) {
114
- socket.connect(`ws://localhost:${Cypress.config('eyesPort')}/eyes`);
115
- connectedToUniversal = true;
116
- socket.emit('Core.makeSDK', {
117
- name: 'eyes.cypress',
118
- version: require('../../package.json').version,
119
- commands: Object.keys(spec).concat(['isSelector', 'isDriver', 'isElement']), // TODO fix spec.isSelector and spec.isDriver and spec.isElement in driver utils
120
- cwd: process.cwd(),
121
- });
122
-
123
- manager =
124
- manager ||
125
- (await socket.request(
126
- 'Core.makeManager',
127
- Object.assign(
128
- {},
129
- {concurrency: Cypress.config('eyesTestConcurrency')},
130
- {legacy: false, type: 'vg'},
131
- ),
132
- ));
133
- }
134
-
135
- const appliConfFile = Cypress.config('appliConfFile');
136
- const config = eyesOpenMapValues({
137
- args,
138
- appliConfFile,
139
- testName,
140
- shouldUseBrowserHooks,
141
- defaultBrowser: {
142
- width: Cypress.config('viewportWidth'),
143
- height: Cypress.config('viewportHeight'),
144
- name: 'chrome',
145
- },
146
- });
147
- eyes = await socket.request('EyesManager.openEyes', {manager, driver, config});
148
- });
149
- });
150
-
151
- Cypress.Commands.add('eyesCheckWindow', args =>
152
- cy.then({timeout: 86400000}, () => {
153
- if (isCurrentTestDisabled) return;
154
-
155
- setRootContext();
156
-
157
- Cypress.log({name: 'Eyes: check window'});
158
-
159
- const checkSettings = eyesCheckMapValues({args});
160
-
161
- return socket.request('Eyes.check', {
162
- eyes,
163
- settings: checkSettings,
164
- });
165
- }),
166
- );
167
-
168
- Cypress.Commands.add('eyesClose', () => {
169
- return cy.then({timeout: 86400000}, () => {
170
- if (isCurrentTestDisabled) return;
171
-
172
- Cypress.log({name: 'Eyes: close'});
173
- if (isCurrentTestDisabled) {
174
- isCurrentTestDisabled = false;
175
- return;
176
- }
177
-
178
- // intentionally not returning the result in order to not wait on the close promise
179
- const p = socket.request('Eyes.close', {eyes, throwErr: false}).catch(err => {
180
- console.log('Error in cy.eyesClose', err);
181
- });
182
- closePromiseArr.push(p);
183
- });
184
- });
185
-
186
- function setRootContext() {
187
- cy.state('window').document['applitools-marker'] = 'root-context';
188
- }
1
+ /* global Cypress,cy,after */
2
+ 'use strict';
3
+ const spec = require('../../dist/browser/spec-driver');
4
+ const Refer = require('./refer');
5
+ const Socket = require('./socket');
6
+ const {socketCommands} = require('./socketCommands');
7
+ const {eyesOpenMapValues} = require('./eyesOpenMapping');
8
+ const {eyesCheckMapValues} = require('./eyesCheckMapping');
9
+ const {TestResultsSummary} = require('@applitools/eyes-api');
10
+
11
+ const refer = new Refer(value => {
12
+ if (!value || !value.constructor || !value.constructor.name) return false;
13
+ const name = value.constructor.name;
14
+ return name === 'HTMLDocument' || name === 'Window' || value.ownerDocument;
15
+ });
16
+ const socket = new Socket();
17
+ const throwErr = Cypress.config('failCypressOnDiff');
18
+ socketCommands(socket, refer);
19
+ let connectedToUniversal = false;
20
+
21
+ let manager,
22
+ eyes,
23
+ closePromiseArr = [];
24
+
25
+ function getGlobalConfigProperty(prop) {
26
+ const property = Cypress.config(prop);
27
+ const shouldParse = ['eyesBrowser', 'eyesLayoutBreakpoints'];
28
+ return property ? (shouldParse.includes(prop) ? JSON.parse(property) : property) : undefined;
29
+ }
30
+
31
+ const shouldUseBrowserHooks =
32
+ !getGlobalConfigProperty('eyesIsDisabled') &&
33
+ (getGlobalConfigProperty('isInteractive') ||
34
+ !getGlobalConfigProperty('eyesIsGlobalHooksSupported'));
35
+
36
+ Cypress.Commands.add('eyesGetAllTestResults', () => {
37
+ Cypress.log({name: 'Eyes: getAllTestResults'});
38
+ return cy.then({timeout: 86400000}, async () => {
39
+ if (isCurrentTestDisabled) {
40
+ isCurrentTestDisabled = false;
41
+ return;
42
+ }
43
+ await Promise.all(closePromiseArr);
44
+ const summary = await socket.request('EyesManager.closeManager', {manager, throwErr});
45
+
46
+ const deleteTest = ({testId, batchId, secretToken}) => {
47
+ const {serverUrl, proxy, apiKey} = Cypress.config('appliConfFile');
48
+ return socket.request('Core.deleteTest', {
49
+ settings: {
50
+ testId,
51
+ batchId,
52
+ secretToken,
53
+ serverUrl,
54
+ proxy,
55
+ apiKey,
56
+ },
57
+ });
58
+ };
59
+
60
+ return new TestResultsSummary({summary, deleteTest});
61
+ });
62
+ });
63
+
64
+ if (shouldUseBrowserHooks) {
65
+ after(() => {
66
+ if (!manager) return;
67
+ return cy.then({timeout: 86400000}, async () => {
68
+ if (isCurrentTestDisabled) {
69
+ isCurrentTestDisabled = false;
70
+ return;
71
+ }
72
+ const resultConfig = {
73
+ showLogs: Cypress.config('appliConfFile').showLogs,
74
+ eyesFailCypressOnDiff: Cypress.config('eyesFailCypressOnDiff'),
75
+ isTextTerminal: Cypress.config('isTextTerminal'),
76
+ tapDirPath: Cypress.config('appliConfFile').tapDirPath,
77
+ tapFileName: Cypress.config('appliConfFile').tapFileName,
78
+ };
79
+ await Promise.all(closePromiseArr);
80
+ const summary = await socket.request('EyesManager.closeManager', {manager, throwErr});
81
+ const testResults = summary.results.map(({testResults}) => testResults);
82
+ const message = await socket.request('Test.printTestResults', {testResults, resultConfig});
83
+ if (
84
+ !!getGlobalConfigProperty('eyesFailCypressOnDiff') &&
85
+ message &&
86
+ message.includes('Eyes-Cypress detected diffs or errors')
87
+ ) {
88
+ throw new Error(message);
89
+ }
90
+ });
91
+ });
92
+ }
93
+
94
+ let isCurrentTestDisabled;
95
+
96
+ Cypress.Commands.add('eyesOpen', function(args = {}) {
97
+ Cypress.log({name: 'Eyes: open'});
98
+ Cypress.config('eyesOpenArgs', args);
99
+ const {title: testName} = this.currentTest || this.test || Cypress.currentTest;
100
+
101
+ if (Cypress.config('eyesIsDisabled') && args.isDisabled === false) {
102
+ throw new Error(
103
+ `Eyes-Cypress is disabled by an env variable or in the applitools.config.js file, but the "${testName}" test was passed isDisabled:false. A single test cannot be enabled when Eyes.Cypress is disabled through the global configuration. Please remove "isDisabled:false" from cy.eyesOpen() for this test, or enable Eyes.Cypress in the global configuration, either by unsetting the APPLITOOLS_IS_DISABLED env var, or by deleting 'isDisabled' from the applitools.config.js file.`,
104
+ );
105
+ }
106
+ isCurrentTestDisabled = getGlobalConfigProperty('eyesIsDisabled') || args.isDisabled;
107
+ if (isCurrentTestDisabled) return;
108
+
109
+ return cy.then({timeout: 86400000}, async () => {
110
+ setRootContext();
111
+ const driver = refer.ref(cy.state('window').document);
112
+
113
+ if (!connectedToUniversal) {
114
+ socket.connect(`ws://localhost:${Cypress.config('eyesPort')}/eyes`);
115
+ connectedToUniversal = true;
116
+ socket.emit('Core.makeSDK', {
117
+ name: 'eyes.cypress',
118
+ version: require('../../package.json').version,
119
+ commands: Object.keys(spec).concat(['isSelector', 'isDriver', 'isElement']), // TODO fix spec.isSelector and spec.isDriver and spec.isElement in driver utils
120
+ cwd: process.cwd(),
121
+ });
122
+
123
+ manager =
124
+ manager ||
125
+ (await socket.request(
126
+ 'Core.makeManager',
127
+ Object.assign(
128
+ {},
129
+ {concurrency: Cypress.config('eyesTestConcurrency')},
130
+ {legacy: false, type: 'vg'},
131
+ ),
132
+ ));
133
+ }
134
+
135
+ const appliConfFile = Cypress.config('appliConfFile');
136
+ const config = eyesOpenMapValues({
137
+ args,
138
+ appliConfFile,
139
+ testName,
140
+ shouldUseBrowserHooks,
141
+ defaultBrowser: {
142
+ width: Cypress.config('viewportWidth'),
143
+ height: Cypress.config('viewportHeight'),
144
+ name: 'chrome',
145
+ },
146
+ });
147
+ eyes = await socket.request('EyesManager.openEyes', {manager, driver, config});
148
+ });
149
+ });
150
+
151
+ Cypress.Commands.add('eyesCheckWindow', args =>
152
+ cy.then({timeout: 86400000}, () => {
153
+ if (isCurrentTestDisabled) return;
154
+
155
+ setRootContext();
156
+
157
+ Cypress.log({name: 'Eyes: check window'});
158
+
159
+ const checkSettings = eyesCheckMapValues({args});
160
+
161
+ return socket.request('Eyes.check', {
162
+ eyes,
163
+ settings: checkSettings,
164
+ });
165
+ }),
166
+ );
167
+
168
+ Cypress.Commands.add('eyesClose', () => {
169
+ return cy.then({timeout: 86400000}, () => {
170
+ if (isCurrentTestDisabled) return;
171
+
172
+ Cypress.log({name: 'Eyes: close'});
173
+ if (isCurrentTestDisabled) {
174
+ isCurrentTestDisabled = false;
175
+ return;
176
+ }
177
+
178
+ // intentionally not returning the result in order to not wait on the close promise
179
+ const p = socket.request('Eyes.close', {eyes, throwErr: false}).catch(err => {
180
+ console.log('Error in cy.eyesClose', err);
181
+ });
182
+ closePromiseArr.push(p);
183
+ });
184
+ });
185
+
186
+ function setRootContext() {
187
+ cy.state('window').document['applitools-marker'] = 'root-context';
188
+ }