@applitools/eyes-cypress 3.28.2 → 3.29.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 (40) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +28 -2
  3. package/dist/browser/spec-driver.js +0 -8
  4. package/dist/expose.js +7 -0
  5. package/dist/plugin/concurrencyMsg.js +9 -0
  6. package/dist/plugin/config.js +66 -0
  7. package/dist/plugin/configParams.js +47 -0
  8. package/dist/plugin/errorDigest.js +74 -0
  9. package/dist/plugin/getErrorsAndDiffs.js +31 -0
  10. package/dist/plugin/handleTestResults.js +38 -0
  11. package/dist/plugin/hooks.js +43 -0
  12. package/dist/plugin/index.js +17 -0
  13. package/dist/plugin/isGlobalHooksSupported.js +10 -0
  14. package/dist/plugin/pluginExport.js +104 -0
  15. package/dist/plugin/server.js +117 -0
  16. package/dist/plugin/webSocket.js +129 -0
  17. package/index.js +3 -2
  18. package/package.json +37 -18
  19. package/src/browser/spec-driver.ts +1 -1
  20. package/src/expose.ts +71 -0
  21. package/src/plugin/{concurrencyMsg.js → concurrencyMsg.ts} +1 -1
  22. package/src/plugin/{config.js → config.ts} +6 -15
  23. package/src/plugin/{configParams.js → configParams.ts} +1 -3
  24. package/src/plugin/{errorDigest.js → errorDigest.ts} +34 -38
  25. package/src/plugin/{getErrorsAndDiffs.js → getErrorsAndDiffs.ts} +3 -8
  26. package/src/plugin/{handleTestResults.js → handleTestResults.ts} +17 -12
  27. package/src/plugin/hooks.ts +60 -0
  28. package/src/plugin/index.ts +37 -0
  29. package/src/plugin/isGlobalHooksSupported.ts +11 -0
  30. package/src/plugin/pluginExport.ts +118 -0
  31. package/src/plugin/{server.js → server.ts} +30 -33
  32. package/src/plugin/{webSocket.js → webSocket.ts} +34 -23
  33. package/src/setup/handlePlugin.js +21 -2
  34. package/src/setup/isPluginDefinedESM.js +5 -0
  35. package/index.d.ts +0 -86
  36. package/src/plugin/defaultPort.js +0 -1
  37. package/src/plugin/hooks.js +0 -41
  38. package/src/plugin/isGlobalHooksSupported.js +0 -13
  39. package/src/plugin/pluginExport.js +0 -94
  40. package/src/plugin/startPlugin.js +0 -15
@@ -1,13 +0,0 @@
1
- const CYPRESS_SUPPORTED_VERSION = '6.2.0'
2
- const CYPRESS_NO_FLAG_VERSION = '6.7.0'
3
-
4
- function isGlobalHooksSupported(config) {
5
- const {version, experimentalRunEvents} = config
6
-
7
- return (
8
- parseFloat(version, 10) >= parseFloat(CYPRESS_NO_FLAG_VERSION, 10) ||
9
- (parseFloat(version, 10) >= parseFloat(CYPRESS_SUPPORTED_VERSION, 10) && !!experimentalRunEvents)
10
- )
11
- }
12
-
13
- module.exports = isGlobalHooksSupported
@@ -1,94 +0,0 @@
1
- 'use strict'
2
- const isGlobalHooksSupported = require('./isGlobalHooksSupported')
3
- const {presult} = require('@applitools/functional-commons')
4
- const makeGlobalRunHooks = require('./hooks')
5
-
6
- function makePluginExport({startServer, eyesConfig}) {
7
- return function pluginExport(pluginModule) {
8
- let eyesServer, pluginModuleExports, pluginExportsE2E, pluginExportsComponent
9
- const pluginExports =
10
- pluginModule.exports && pluginModule.exports.default ? pluginModule.exports.default : pluginModule.exports
11
-
12
- if (pluginExports.component) {
13
- pluginExportsComponent = pluginExports.component.setupNodeEvents
14
- }
15
- if (pluginExports.e2e) {
16
- pluginExportsE2E = pluginExports.e2e.setupNodeEvents
17
- }
18
- if (!pluginExports.e2e && !pluginExports.component) {
19
- pluginModuleExports = pluginExports
20
- }
21
-
22
- const setupNodeEvents = async function (...args) {
23
- const {server, port, closeManager, closeBatches, closeUniversalServer} = await startServer()
24
- eyesServer = server
25
-
26
- const globalHooks = makeGlobalRunHooks({closeManager, closeBatches, closeUniversalServer})
27
-
28
- const [origOn, config] = args
29
-
30
- if (!pluginModuleExports) {
31
- pluginModuleExports = config.testingType === 'e2e' ? pluginExportsE2E : pluginExportsComponent
32
- }
33
-
34
- const isGlobalHookCalledFromUserHandlerMap = new Map()
35
- eyesConfig.eyesIsGlobalHooksSupported = isGlobalHooksSupported(config)
36
- let moduleExportsResult = {}
37
- // in case setupNodeEvents is not defined in cypress.config file
38
- if (typeof pluginModuleExports === 'function') {
39
- moduleExportsResult = await pluginModuleExports(onThatCallsUserDefinedHandler, config)
40
- }
41
- if (eyesConfig.eyesIsGlobalHooksSupported) {
42
- for (const [eventName, eventHandler] of Object.entries(globalHooks)) {
43
- if (!isGlobalHookCalledFromUserHandlerMap.get(eventName)) {
44
- origOn.call(this, eventName, eventHandler)
45
- }
46
- }
47
- }
48
-
49
- return Object.assign({}, eyesConfig, {eyesPort: port}, moduleExportsResult)
50
-
51
- // This piece of code exists because at the point of writing, Cypress does not support multiple event handlers:
52
- // https://github.com/cypress-io/cypress/issues/5240#issuecomment-948277554
53
- // So we wrap Cypress' `on` function in order to wrap the user-defined handler. This way we can call our own handler
54
- // in addition to the user's handler
55
- function onThatCallsUserDefinedHandler(eventName, handler) {
56
- const isRunEvent = eventName === 'before:run' || eventName === 'after:run'
57
- let handlerToCall = handler
58
- if (eyesConfig.eyesIsGlobalHooksSupported && isRunEvent) {
59
- handlerToCall = handlerThatCallsUserDefinedHandler
60
- isGlobalHookCalledFromUserHandlerMap.set(eventName, true)
61
- }
62
- return origOn.call(this, eventName, handlerToCall)
63
-
64
- async function handlerThatCallsUserDefinedHandler() {
65
- const [err] = await presult(Promise.resolve(globalHooks[eventName].apply(this, arguments)))
66
- await handler.apply(this, arguments)
67
- if (err) {
68
- throw err
69
- }
70
- }
71
- }
72
- }
73
-
74
- if (pluginExports.component) {
75
- pluginExports.component.setupNodeEvents = setupNodeEvents
76
- }
77
- if (pluginExports.e2e) {
78
- pluginExports.e2e.setupNodeEvents = setupNodeEvents
79
- }
80
- if (!pluginExports.component && !pluginExports.e2e) {
81
- if (pluginModule.exports.default) {
82
- pluginModule.exports.default = setupNodeEvents
83
- } else {
84
- pluginModule.exports = setupNodeEvents
85
- }
86
- }
87
-
88
- return function getCloseServer() {
89
- return eyesServer.close()
90
- }
91
- }
92
- }
93
-
94
- module.exports = makePluginExport
@@ -1,15 +0,0 @@
1
- 'use strict'
2
- const makePluginExport = require('./pluginExport')
3
- const makeConfig = require('./config')
4
- const makeStartServer = require('./server')
5
- const {makeLogger} = require('@applitools/logger')
6
-
7
- const {config, eyesConfig} = makeConfig()
8
- const logger = makeLogger({level: config.showLogs ? 'info' : 'silent', label: 'eyes'})
9
-
10
- const startServer = makeStartServer({logger})
11
-
12
- module.exports = makePluginExport({
13
- startServer,
14
- eyesConfig: Object.assign({}, eyesConfig, {appliConfFile: config}),
15
- })