@applitools/eyes-cypress 3.23.9 → 3.24.0-beta.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 (56) hide show
  1. package/CHANGELOG.md +2195 -2186
  2. package/LICENSE +25 -25
  3. package/README.md +778 -769
  4. package/bin/eyes-setup.js +21 -21
  5. package/commands.js +2 -2
  6. package/dist/browser/spec-driver.js +104 -0
  7. package/dist/plugin/handler.js +55 -0
  8. package/eyes-index.d.ts +34 -34
  9. package/index.js +2 -2
  10. package/package.json +97 -81
  11. package/src/browser/commands.js +167 -147
  12. package/src/browser/eyesCheckMapping.js +71 -0
  13. package/src/browser/eyesOpenMapping.js +34 -0
  14. package/src/browser/makeSend.js +18 -22
  15. package/src/browser/refer.js +57 -0
  16. package/src/browser/sendRequest.js +16 -16
  17. package/src/browser/socket.js +143 -0
  18. package/src/browser/socketCommands.js +81 -0
  19. package/src/browser/spec-driver.ts +109 -0
  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 -53
  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 +39 -0
  28. package/src/plugin/handler.ts +58 -0
  29. package/src/plugin/hooks.js +49 -42
  30. package/src/plugin/isGlobalHooksSupported.js +13 -13
  31. package/src/plugin/pluginExport.js +60 -57
  32. package/src/plugin/server.js +98 -46
  33. package/src/plugin/startPlugin.js +13 -34
  34. package/src/plugin/webSocket.js +130 -0
  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
  45. package/src/browser/eyesCheckWindow.js +0 -132
  46. package/src/browser/getAllBlobs.js +0 -14
  47. package/src/browser/getBrowserInfo.js +0 -39
  48. package/src/browser/makeHandleCypressViewport.js +0 -22
  49. package/src/browser/poll.js +0 -25
  50. package/src/plugin/app.js +0 -42
  51. package/src/plugin/handlers.js +0 -205
  52. package/src/plugin/makeHandleBatchResultsFile.js +0 -17
  53. package/src/plugin/pollingHandler.js +0 -46
  54. package/src/plugin/processCloseAndAbort.js +0 -33
  55. package/src/plugin/runningTests.js +0 -27
  56. package/src/plugin/waitForBatch.js +0 -33
package/bin/eyes-setup.js CHANGED
@@ -1,21 +1,21 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- const chalk = require('chalk');
5
- const handlePlugin = require('../src/setup/handlePlugin');
6
- const handleCommands = require('../src/setup/handleCommands');
7
- const handleTypeScript = require('../src/setup/handleTypeScript');
8
- const {version} = require('../package');
9
- const cwd = process.cwd();
10
-
11
- console.log(chalk.cyan('Setup eyes-cypress', version));
12
-
13
- try {
14
- handlePlugin(cwd);
15
- handleCommands(cwd);
16
- handleTypeScript(cwd);
17
- } catch (e) {
18
- console.log(chalk.red('Setup error:\n', e));
19
- }
20
-
21
- console.log(chalk.cyan('Setup done!'));
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const chalk = require('chalk');
5
+ const handlePlugin = require('../src/setup/handlePlugin');
6
+ const handleCommands = require('../src/setup/handleCommands');
7
+ const handleTypeScript = require('../src/setup/handleTypeScript');
8
+ const {version} = require('../package');
9
+ const cwd = process.cwd();
10
+
11
+ console.log(chalk.cyan('Setup eyes-cypress', version));
12
+
13
+ try {
14
+ handlePlugin(cwd);
15
+ handleCommands(cwd);
16
+ handleTypeScript(cwd);
17
+ } catch (e) {
18
+ console.log(chalk.red('Setup error:\n', e));
19
+ }
20
+
21
+ console.log(chalk.cyan('Setup done!'));
package/commands.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';
2
- require('./src/browser/commands');
1
+ 'use strict';
2
+ require('./src/browser/commands');
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCookies = exports.getUrl = exports.getTitle = exports.findElements = exports.findElement = exports.transformSelector = exports.setViewportSize = exports.getViewportSize = exports.childContext = exports.parentContext = exports.mainContext = exports.executeScript = void 0;
4
+ function executeScript(context, script, arg) {
5
+ // context = getCurrenctContext(context)
6
+ let scriptToExecute;
7
+ if (script.includes('dom-snapshot') ||
8
+ script.includes('dom-capture') ||
9
+ script.includes('dom-shared')) {
10
+ scriptToExecute = script;
11
+ }
12
+ else {
13
+ const prepScirpt = script.replace('function(arg)', 'function func(arg)');
14
+ scriptToExecute = prepScirpt.concat(' return func(arg)');
15
+ }
16
+ const executor = new context.defaultView.Function('arg', scriptToExecute);
17
+ return executor(arg);
18
+ }
19
+ exports.executeScript = executeScript;
20
+ function mainContext() {
21
+ //@ts-ignore
22
+ return cy.state('window').document;
23
+ }
24
+ exports.mainContext = mainContext;
25
+ function parentContext(context) {
26
+ if (!context)
27
+ return; // because Cypress doesn't support cross origin iframe, then childContext might return null, and then the input to parentContext might be null
28
+ return context === mainContext() ? context : context.defaultView.frameElement.ownerDocument;
29
+ }
30
+ exports.parentContext = parentContext;
31
+ function childContext(_context, element) {
32
+ return element.contentDocument; // null in case of cross origin iframe
33
+ }
34
+ exports.childContext = childContext;
35
+ function getViewportSize() {
36
+ //@ts-ignore
37
+ const currWindow = cy.state('window');
38
+ const viewportSize = {
39
+ width: Math.max(currWindow.document.documentElement.clientWidth || 0, currWindow.innerWidth || 0),
40
+ height: Math.max(currWindow.document.documentElement.clientHeight || 0, currWindow.innerHeight || 0)
41
+ };
42
+ return viewportSize;
43
+ }
44
+ exports.getViewportSize = getViewportSize;
45
+ function setViewportSize(vs) {
46
+ //@ts-ignore
47
+ Cypress.action('cy:viewport:changed', { viewportWidth: vs.size.width, viewportHeight: vs.size.height });
48
+ }
49
+ exports.setViewportSize = setViewportSize;
50
+ function transformSelector(selector) {
51
+ if (selector.hasOwnProperty('selector') && (!selector.hasOwnProperty('type') || selector.type === 'css')) {
52
+ return selector.selector;
53
+ }
54
+ return selector;
55
+ }
56
+ exports.transformSelector = transformSelector;
57
+ function findElement(context, selector, parent) {
58
+ // context = getCurrenctContext(context)
59
+ const root = parent !== null && parent !== void 0 ? parent : context;
60
+ const sel = typeof selector === 'string' ? selector : selector.selector;
61
+ if (typeof selector !== 'string' && selector.type === 'xpath') {
62
+ return context.evaluate(sel, context, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
63
+ }
64
+ else {
65
+ return root.querySelector(sel);
66
+ }
67
+ }
68
+ exports.findElement = findElement;
69
+ function findElements(context, selector, parent) {
70
+ // context = getCurrenctContext(context)
71
+ const root = parent !== null && parent !== void 0 ? parent : context;
72
+ const sel = typeof selector === 'string' ? selector : selector.selector;
73
+ if (typeof selector !== 'string' && selector.type === 'xpath') {
74
+ // TODO return multiple
75
+ return context.evaluate(sel, context, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
76
+ }
77
+ else {
78
+ return root.querySelectorAll(sel);
79
+ }
80
+ }
81
+ exports.findElements = findElements;
82
+ function getTitle(context) {
83
+ // context = getCurrenctContext(context)
84
+ return context.title;
85
+ }
86
+ exports.getTitle = getTitle;
87
+ function getUrl(context) {
88
+ // context = getCurrenctContext(context)
89
+ return context.location.href;
90
+ }
91
+ exports.getUrl = getUrl;
92
+ function getCookies() {
93
+ //@ts-ignore
94
+ return Cypress.automation('get:cookies', {});
95
+ }
96
+ exports.getCookies = getCookies;
97
+ // we need to method to reset the context in case the user called open before visit
98
+ function getCurrenctContext(context) {
99
+ //@ts-ignore
100
+ return (context && context.defaultView) ? context : cy.state('window').document;
101
+ }
102
+ // export function takeScreenshot(page: Driver): Promise<Buffer>;
103
+ // export function visit(page: Driver, url: string): Promise<void>; (??)
104
+ // export function isStaleElementError(err: any): boolean;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeHandler = void 0;
4
+ const http_1 = require("http");
5
+ const ws_1 = require("ws");
6
+ const { name, version } = require('../../package.json'); // TODO is the handshake needed at all?
7
+ const TOKEN_HEADER = 'x-eyes-universal-token';
8
+ const TOKEN = `${name}@${version}`;
9
+ // TODO make default port 0 and return actual port
10
+ async function makeHandler({ port = 31077, singleton = true, lazy = false } = {}) {
11
+ const http = new http_1.Server();
12
+ http.on('request', (request, response) => {
13
+ if (request.url === '/handshake') {
14
+ if (request.headers[TOKEN_HEADER] === TOKEN) {
15
+ response.writeHead(200, { [TOKEN_HEADER]: TOKEN });
16
+ }
17
+ else {
18
+ response.writeHead(400);
19
+ }
20
+ response.end();
21
+ }
22
+ });
23
+ http.listen(port, 'localhost');
24
+ return new Promise((resolve, reject) => {
25
+ http.on('listening', () => {
26
+ const ws = new ws_1.Server({ server: http, path: '/eyes' });
27
+ ws.on('close', () => http.close());
28
+ resolve({ server: ws, port });
29
+ });
30
+ http.on('error', async (err) => {
31
+ if (!lazy && err.code === 'EADDRINUSE') {
32
+ if (singleton && (await isHandshakable(port))) {
33
+ return resolve({ port });
34
+ }
35
+ else {
36
+ return resolve(await makeHandler({ port: port + 1, singleton }));
37
+ }
38
+ }
39
+ reject(err);
40
+ });
41
+ });
42
+ }
43
+ exports.makeHandler = makeHandler;
44
+ async function isHandshakable(port) {
45
+ return new Promise(resolve => {
46
+ const handshake = http_1.request(`http://localhost:${port}/handshake`, {
47
+ headers: { [TOKEN_HEADER]: TOKEN },
48
+ });
49
+ handshake.on('response', ({ statusCode, headers }) => {
50
+ resolve(statusCode === 200 && headers[TOKEN_HEADER] === TOKEN);
51
+ });
52
+ handshake.on('error', () => resolve(false));
53
+ handshake.end();
54
+ });
55
+ }
package/eyes-index.d.ts CHANGED
@@ -1,34 +1,34 @@
1
- /// <reference types="Cypress" />
2
- /// <reference types="@applitools/visual-grid-client" />
3
-
4
- declare namespace Cypress {
5
- interface Chainable {
6
- /**
7
- * Create an Applitools test.
8
- * This will start a session with the Applitools server.
9
- * @example
10
- * cy.eyesOpen({ appName: 'My App' })
11
- */
12
- eyesOpen(options?: Eyes.Open.Options): null // add isDisabled
13
-
14
- /**
15
- * Generate a screenshot of the current page and add it to the Applitools Test.
16
- * @example
17
- * cy.eyesCheckWindow()
18
- *
19
- * OR
20
- *
21
- * cy.eyesCheckWindow({
22
- * target: 'region',
23
- * selector: '.my-element'
24
- * });
25
- */
26
- eyesCheckWindow(config?: Eyes.Check.Options|String): null
27
-
28
- /**
29
- * Close the applitools test and check that all screenshots are valid.
30
- * @example cy.eyesClose()
31
- */
32
- eyesClose(): null
33
- }
34
- }
1
+ /// <reference types="Cypress" />
2
+ /// <reference types="@applitools/visual-grid-client" />
3
+
4
+ declare namespace Cypress {
5
+ interface Chainable {
6
+ /**
7
+ * Create an Applitools test.
8
+ * This will start a session with the Applitools server.
9
+ * @example
10
+ * cy.eyesOpen({ appName: 'My App' })
11
+ */
12
+ eyesOpen(options?: Eyes.Open.Options): null // add isDisabled
13
+
14
+ /**
15
+ * Generate a screenshot of the current page and add it to the Applitools Test.
16
+ * @example
17
+ * cy.eyesCheckWindow()
18
+ *
19
+ * OR
20
+ *
21
+ * cy.eyesCheckWindow({
22
+ * target: 'region',
23
+ * selector: '.my-element'
24
+ * });
25
+ */
26
+ eyesCheckWindow(config?: Eyes.Check.Options|String): null
27
+
28
+ /**
29
+ * Close the applitools test and check that all screenshots are valid.
30
+ * @example cy.eyesClose()
31
+ */
32
+ eyesClose(): null
33
+ }
34
+ }
package/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';
2
- module.exports = require('./src/plugin/startPlugin');
1
+ 'use strict';
2
+ module.exports = require('./src/plugin/startPlugin');
package/package.json CHANGED
@@ -1,81 +1,97 @@
1
- {
2
- "name": "@applitools/eyes-cypress",
3
- "version": "3.23.9",
4
- "main": "index.js",
5
- "license": "SEE LICENSE IN LICENSE",
6
- "bin": {
7
- "eyes-setup": "./bin/eyes-setup.js"
8
- },
9
- "scripts": {
10
- "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",
11
- "test:unit": "mocha --no-timeouts 'test/unit/**/*.test.js'",
12
- "test:it": "mocha --no-timeouts 'test/it/**/*.test.js'",
13
- "test:e2e": "mkdir -p test/fixtures/testAppCopies && mocha --no-timeouts 'test/e2e/**/*.test.js'",
14
- "lint": "eslint '**/*.js'",
15
- "test": "yarn test:unit && yarn test:it && yarn test:e2e && yarn lint",
16
- "cypress": "cd test/fixtures/testApp && cypress open --config integrationFolder=cypress/integration-play,pluginsFile=cypress/plugins/index-play.js,supportFile=cypress/support/index-play.js",
17
- "cypress:run": "cd test/fixtures/testApp && cypress run --config integrationFolder=cypress/integration-run,pluginsFile=cypress/plugins/index-run.js,supportFile=cypress/support/index-run.js",
18
- "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",
19
- "gh:publish": "gh workflow run publish-cypress.yml --ref $(git rev-parse --abbrev-ref HEAD)",
20
- "preversion": "bongo preversion --skip-deps",
21
- "version": "bongo version",
22
- "postversion": "bongo postversion --skip-release-notification",
23
- "deps": "bongo deps",
24
- "prepublish:setup": "sudo apt-get install xvfb"
25
- },
26
- "files": [
27
- "src",
28
- "bin",
29
- "index.js",
30
- "commands.js",
31
- "eyes-index.d.ts"
32
- ],
33
- "types": "./eyes-index.d.ts",
34
- "engines": {
35
- "node": ">=8.0.0"
36
- },
37
- "repository": {
38
- "type": "git",
39
- "url": "git://github.com/applitools/eyes.sdk.javascript1.git",
40
- "directory": "packages/eyes-cypress"
41
- },
42
- "dependencies": {
43
- "@applitools/dom-snapshot": "4.5.12",
44
- "@applitools/functional-commons": "1.6.0",
45
- "@applitools/logger": "1.0.11",
46
- "@applitools/visual-grid-client": "15.9.0",
47
- "body-parser": "1.19.0",
48
- "chalk": "3.0.0",
49
- "cors": "2.8.5",
50
- "express": "4.17.1",
51
- "lodash.flatten": "4.4.0",
52
- "throat": "6.0.1"
53
- },
54
- "devDependencies": {
55
- "@applitools/scripts": "^1.1.0",
56
- "@applitools/sdk-release-kit": "0.13.11",
57
- "@applitools/snaptdout": "1.0.1",
58
- "@applitools/test-server": "1.0.8",
59
- "chai": "^4.2.0",
60
- "chai-spies": "^1.0.0",
61
- "cookie-parser": "^1.4.4",
62
- "cypress": "^6.5.0",
63
- "eslint": "^6.8.0",
64
- "eslint-plugin-mocha-no-only": "^1.1.0",
65
- "eslint-plugin-node": "^7.0.1",
66
- "eslint-plugin-prettier": "^2.7.0",
67
- "husky": "^4.3.8",
68
- "lodash.omit": "^4.5.0",
69
- "mocha": "^8.0.1",
70
- "morgan": "^1.9.1",
71
- "ncp": "^2.0.0",
72
- "node-fetch": "^2.6.7",
73
- "prettier": "^1.19.1",
74
- "typescript": "^3.9.2"
75
- },
76
- "husky": {
77
- "hooks": {
78
- "pre-push": "yarn bongo lint"
79
- }
80
- }
81
- }
1
+ {
2
+ "name": "@applitools/eyes-cypress",
3
+ "version": "3.24.0-beta.2",
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.0",
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
+ }