@applitools/eyes-cypress 3.22.6 → 3.22.7

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+
6
+ ## 3.22.7 - 2021/11/7
7
+
8
+ - replace legacy logger construction with new
9
+ - Support running user defined run hooks in Cypress
10
+ - Fix cypress tests not being cleaned up
11
+ - Fix duplicate batch start/end events in cypress
12
+ - updated to @applitools/dom-snapshot@4.5.10 (from 4.5.9)
13
+ - updated to @applitools/visual-grid-client@15.8.43 (from 15.8.36)
14
+
5
15
  ## 3.22.6 - 2021/10/18
6
16
 
7
17
  - updated to @applitools/dom-snapshot@4.5.9 (from 4.5.8)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/eyes-cypress",
3
- "version": "3.22.6",
3
+ "version": "3.22.7",
4
4
  "main": "index.js",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "bin": {
@@ -35,12 +35,14 @@
35
35
  },
36
36
  "repository": {
37
37
  "type": "git",
38
- "url": "git://github.com/applitools/eyes.sdk.javascript1.git"
38
+ "url": "git://github.com/applitools/eyes.sdk.javascript1.git",
39
+ "directory": "packages/eyes-cypress"
39
40
  },
40
41
  "dependencies": {
41
- "@applitools/dom-snapshot": "4.5.9",
42
+ "@applitools/dom-snapshot": "4.5.10",
42
43
  "@applitools/functional-commons": "1.6.0",
43
- "@applitools/visual-grid-client": "15.8.36",
44
+ "@applitools/logger": "1.0.5",
45
+ "@applitools/visual-grid-client": "15.8.43",
44
46
  "body-parser": "1.19.0",
45
47
  "chalk": "3.0.0",
46
48
  "cors": "2.8.5",
@@ -49,10 +51,10 @@
49
51
  },
50
52
  "devDependencies": {
51
53
  "@applitools/scripts": "^1.0.1",
52
- "@applitools/sdk-release-kit": "0.13.3",
53
- "@applitools/sdk-shared": "0.9.6",
54
+ "@applitools/sdk-release-kit": "0.13.4",
55
+ "@applitools/sdk-shared": "0.9.7",
54
56
  "@applitools/snaptdout": "1.0.1",
55
- "@applitools/test-server": "1.0.5",
57
+ "@applitools/test-server": "1.0.6",
56
58
  "chai": "^4.2.0",
57
59
  "chai-spies": "^1.0.0",
58
60
  "cookie-parser": "^1.4.4",
@@ -18,7 +18,7 @@ function getGlobalConfigProperty(prop) {
18
18
  const shouldParse = ['eyesBrowser', 'eyesLayoutBreakpoints'];
19
19
  return property ? (shouldParse.includes(prop) ? JSON.parse(property) : property) : undefined;
20
20
  }
21
- if (!getGlobalConfigProperty('eyesIsDisabled') && getGlobalConfigProperty('eyesLegacyHooks')) {
21
+ if (!getGlobalConfigProperty('eyesIsDisabled') && getGlobalConfigProperty('isInteractive')) {
22
22
  const batchEnd = poll(() => {
23
23
  return sendRequest({command: 'batchEnd'});
24
24
  });
@@ -42,7 +42,6 @@ function makeConfig() {
42
42
  eyesFailCypressOnDiff:
43
43
  config.failCypressOnDiff === undefined ? true : !!config.failCypressOnDiff,
44
44
  eyesDisableBrowserFetching: !!config.disableBrowserFetching,
45
- eyesLegacyHooks: true,
46
45
  eyesTestConcurrency: config.testConcurrency || DEFAULT_TEST_CONCURRENCY,
47
46
  };
48
47
 
@@ -4,41 +4,39 @@ const makeHandleBatchResultsFile = require('./makeHandleBatchResultsFile');
4
4
  const getErrorsAndDiffs = require('./getErrorsAndDiffs');
5
5
  const processCloseAndAbort = require('./processCloseAndAbort');
6
6
  const errorDigest = require('./errorDigest');
7
- const {tests} = require('./runningTests');
7
+ const runningTests = require('./runningTests');
8
8
 
9
- function setGlobalRunHooks(on, {visualGridClient, logger, eyesConfig}) {
9
+ function makeGlobalRunHooks({visualGridClient, logger}) {
10
10
  let waitForBatch;
11
11
 
12
- on('before:run', ({config}) => {
13
- const {isTextTerminal, eyesTestConcurrency: testConcurrency} = config;
14
- // ugly but neccessary here - as this is the only place that cypress exposes the run mode on config
15
- if (!isTextTerminal) return;
16
- eyesConfig.eyesLegacyHooks = false;
12
+ return {
13
+ 'before:run': ({config}) => {
14
+ const {isTextTerminal, eyesTestConcurrency: testConcurrency} = config;
15
+ if (!config.isTextTerminal) return;
17
16
 
18
- waitForBatch = makeWaitForBatch({
19
- logger: (logger.extend && logger.extend('waitForBatch')) || console,
20
- testConcurrency,
21
- processCloseAndAbort,
22
- getErrorsAndDiffs,
23
- errorDigest,
24
- isInteractive: !isTextTerminal,
25
- handleBatchResultsFile: makeHandleBatchResultsFile(config),
26
- });
27
- });
17
+ waitForBatch = makeWaitForBatch({
18
+ logger: (logger.extend && logger.extend('waitForBatch')) || console,
19
+ testConcurrency,
20
+ processCloseAndAbort,
21
+ getErrorsAndDiffs,
22
+ errorDigest,
23
+ isInteractive: !isTextTerminal,
24
+ handleBatchResultsFile: makeHandleBatchResultsFile(config),
25
+ });
26
+ },
28
27
 
29
- on('after:run', async ({config}) => {
30
- if (!config.isTextTerminal) return;
28
+ 'after:run': async ({config}) => {
29
+ if (!config.isTextTerminal) return;
31
30
 
32
- try {
33
- // we rely on the fact that `runningTests.reset()` wasn't called
34
- // so that tests that were added in `open` are available here (through `tests` in `runningTests.js`)
35
- await waitForBatch(tests, visualGridClient.closeBatch);
36
- } catch (e) {
37
- if (!!config.eyesFailCypressOnDiff) {
38
- throw e;
31
+ try {
32
+ await waitForBatch(runningTests.tests, visualGridClient.closeBatch);
33
+ } catch (e) {
34
+ if (!!config.eyesFailCypressOnDiff) {
35
+ throw e;
36
+ }
39
37
  }
40
- }
41
- });
38
+ },
39
+ };
42
40
  }
43
41
 
44
- module.exports = setGlobalRunHooks;
42
+ module.exports = makeGlobalRunHooks;
@@ -1,22 +1,38 @@
1
1
  'use strict';
2
- const setGlobalRunHooks = require('./hooks');
3
2
  const shouldSetGlobalHooks = require('./shouldSetGlobalHooks');
3
+ const {presult} = require('@applitools/functional-commons');
4
4
 
5
- function makePluginExport({startServer, eyesConfig, visualGridClient, logger}) {
5
+ function makePluginExport({startServer, eyesConfig, globalHooks}) {
6
6
  return function pluginExport(pluginModule) {
7
7
  let closeEyesServer;
8
8
  const pluginModuleExports = pluginModule.exports;
9
9
  pluginModule.exports = async (...args) => {
10
10
  const {eyesPort, closeServer} = await startServer();
11
11
  closeEyesServer = closeServer;
12
- const moduleExportsResult = await pluginModuleExports(...args);
13
- const [on, config] = args;
12
+ const [origOn, config] = args;
13
+ const moduleExportsResult = await pluginModuleExports(onThatCallsUserDefinedHandler, config);
14
+ return Object.assign({}, eyesConfig, {eyesPort}, moduleExportsResult);
14
15
 
15
- if (shouldSetGlobalHooks({...config, ...eyesConfig})) {
16
- setGlobalRunHooks(on, {visualGridClient, logger, eyesConfig});
17
- }
16
+ // This piece of code exists because at the point of writing, Cypress does not support multiple event handlers:
17
+ // https://github.com/cypress-io/cypress/issues/5240#issuecomment-948277554
18
+ // So we wrap Cypress' `on` function in order to wrap the user-defined handler. This way we can call our own handler
19
+ // in addition to the user's handler
20
+ function onThatCallsUserDefinedHandler(eventName, handler) {
21
+ const isRunEvent = eventName === 'before:run' || eventName === 'after:run';
22
+ const handlerToCall =
23
+ shouldSetGlobalHooks(config) && isRunEvent ? handlerThatCallsUserDefinedHandler : handler;
24
+ return origOn.call(this, eventName, handlerToCall);
18
25
 
19
- return Object.assign({}, eyesConfig, {eyesPort}, moduleExportsResult);
26
+ async function handlerThatCallsUserDefinedHandler() {
27
+ const [err] = await presult(
28
+ Promise.resolve(globalHooks[eventName].apply(this, arguments)),
29
+ );
30
+ await handler.apply(this, arguments);
31
+ if (err) {
32
+ throw err;
33
+ }
34
+ }
35
+ }
20
36
  };
21
37
  return function getCloseServer() {
22
38
  return closeEyesServer;
@@ -9,8 +9,10 @@ const runningTests = {
9
9
  this.tests = [];
10
10
  },
11
11
  async abortTests() {
12
+ const tests = this.tests;
13
+ this.reset();
12
14
  return Promise.all(
13
- this.tests.map(async test => {
15
+ tests.map(async test => {
14
16
  if (test.closePromise) {
15
17
  // this condition doesn't really happen in the code, but it's here for purity. This is used in handlers' batchStart in order to cleanup the state in case a zombie open was called.
16
18
  await test.closePromise;
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
- const {makeVisualGridClient, Logger} = require('@applitools/visual-grid-client');
2
+ const {makeVisualGridClient} = require('@applitools/visual-grid-client');
3
+ const {makeLogger} = require('@applitools/logger');
3
4
  const makeStartServer = require('./server');
4
5
  const makePluginExport = require('./pluginExport');
5
6
  const {startApp} = require('./app');
@@ -8,13 +9,12 @@ const processCloseAndAbort = require('./processCloseAndAbort');
8
9
  const errorDigest = require('./errorDigest');
9
10
  const makeHandlers = require('./handlers');
10
11
  const makeConfig = require('./config');
12
+ const makeGlobalRunHooks = require('./hooks');
11
13
 
12
14
  const {config, eyesConfig} = makeConfig();
13
- const logger = new Logger(config.showLogs, 'eyes');
15
+ const logger = makeLogger({level: config.showLogs ? 'info' : 'silent', label: 'eyes'});
14
16
 
15
- const visualGridClient = makeVisualGridClient(
16
- Object.assign(config, {logger: (logger.extend && logger.extend('vgc')) || logger}),
17
- );
17
+ const visualGridClient = makeVisualGridClient({...config, logger: logger.extend('vgc')});
18
18
 
19
19
  const handlers = makeHandlers({
20
20
  logger,
@@ -25,8 +25,10 @@ const handlers = makeHandlers({
25
25
  errorDigest,
26
26
  });
27
27
 
28
+ const globalHooks = makeGlobalRunHooks({visualGridClient, logger});
29
+
28
30
  const app = startApp({handlers, logger});
29
31
  const startServer = makeStartServer({app, logger});
30
32
  logger.log('eyes-cypress plugin running with config:', config);
31
33
 
32
- module.exports = makePluginExport({startServer, eyesConfig, visualGridClient, logger});
34
+ module.exports = makePluginExport({startServer, eyesConfig, globalHooks});