@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.
- package/CHANGELOG.md +13 -0
- package/bin/eyes-setup.js +21 -21
- package/dist/browser/spec-driver.js +2 -5
- package/index.d.ts +7 -6
- package/index.js +2 -2
- package/package.json +13 -11
- package/src/browser/commands.js +79 -84
- package/src/browser/eyesCheckMapping.js +77 -71
- package/src/browser/eyesOpenMapping.js +28 -32
- package/src/browser/makeSend.js +5 -10
- package/src/browser/refer.js +28 -28
- package/src/browser/sendRequest.js +6 -6
- package/src/browser/socket.js +72 -73
- package/src/browser/socketCommands.js +34 -45
- package/src/browser/spec-driver.ts +33 -41
- package/src/plugin/concurrencyMsg.js +4 -4
- package/src/plugin/config.js +16 -17
- package/src/plugin/configParams.js +3 -3
- package/src/plugin/defaultPort.js +1 -1
- package/src/plugin/errorDigest.js +27 -35
- package/src/plugin/getErrorsAndDiffs.js +11 -11
- package/src/plugin/handleTestResults.js +16 -19
- package/src/plugin/hooks.js +12 -12
- package/src/plugin/isGlobalHooksSupported.js +6 -7
- package/src/plugin/pluginExport.js +38 -43
- package/src/plugin/server.js +50 -53
- package/src/plugin/startPlugin.js +9 -9
- package/src/plugin/webSocket.js +63 -64
- package/src/setup/addEyesCommands.js +12 -12
- package/src/setup/addEyesCypressPlugin.js +6 -6
- package/src/setup/getCypressPaths.js +28 -32
- package/src/setup/getCypressVersion.js +7 -9
- package/src/setup/getFilePath.js +8 -8
- package/src/setup/handleCommands.js +11 -11
- package/src/setup/handlePlugin.js +10 -10
- package/src/setup/handleTypeScript.js +8 -8
- package/src/setup/isCommandsDefined.js +3 -3
- package/src/setup/isPluginDefined.js +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict'
|
|
2
2
|
|
|
3
3
|
const colors = {
|
|
4
4
|
green: '\x1b[32m',
|
|
@@ -6,7 +6,7 @@ const colors = {
|
|
|
6
6
|
teal: '\x1b[38;5;86m',
|
|
7
7
|
orange: '\x1b[38;5;214m',
|
|
8
8
|
reset: '\x1b[0m',
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
10
|
|
|
11
11
|
const formatByStatus = {
|
|
12
12
|
Passed: {
|
|
@@ -24,73 +24,65 @@ const formatByStatus = {
|
|
|
24
24
|
symbol: '\u26A0',
|
|
25
25
|
title: tests => `Diffs detected - ${tests} tests`,
|
|
26
26
|
},
|
|
27
|
-
}
|
|
27
|
+
}
|
|
28
28
|
|
|
29
29
|
function errorDigest({passed, failed, diffs, logger, isInteractive}) {
|
|
30
|
-
logger.log('errorDigest: diff errors', diffs)
|
|
31
|
-
logger.log('errorDigest: test errors', failed)
|
|
30
|
+
logger.log('errorDigest: diff errors', diffs)
|
|
31
|
+
logger.log('errorDigest: test errors', failed)
|
|
32
32
|
|
|
33
|
-
const testResultsUrl = diffs.length ? colorify(diffs[0].url
|
|
34
|
-
const testResultsPrefix = testResultsUrl ? 'See details at:' : ''
|
|
35
|
-
const footer = testResultsUrl
|
|
36
|
-
? `\n${indent()}${colorify(testResultsPrefix)} ${testResultsUrl}`
|
|
37
|
-
: '';
|
|
33
|
+
const testResultsUrl = diffs.length ? colorify(` ${diffs[0].url} `, 'teal') : '' // the space around the url is for the link to be clickable in the cypress run
|
|
34
|
+
const testResultsPrefix = testResultsUrl ? 'See details at:' : ''
|
|
35
|
+
const footer = testResultsUrl ? `\n${indent()}${colorify(testResultsPrefix)}${testResultsUrl}` : ''
|
|
38
36
|
return (
|
|
39
37
|
colorify('Eyes-Cypress detected diffs or errors during execution of visual tests.') +
|
|
40
|
-
colorify(` ${testResultsPrefix}
|
|
38
|
+
colorify(` ${testResultsPrefix}${testResultsUrl}`) +
|
|
41
39
|
testResultsToString(passed, 'Passed') +
|
|
42
40
|
testResultsToString(diffs, 'Unresolved') +
|
|
43
41
|
testResultsToString(failed, 'Failed') +
|
|
44
42
|
footer +
|
|
45
43
|
'\n\n'
|
|
46
|
-
)
|
|
44
|
+
)
|
|
47
45
|
|
|
48
46
|
function testResultsToString(testResultsArr, category) {
|
|
49
|
-
const {color, title, symbol, chalkFunction} = formatByStatus[category]
|
|
47
|
+
const {color, title, symbol, chalkFunction} = formatByStatus[category]
|
|
50
48
|
const results = testResultsArr.reduce((acc, testResults) => {
|
|
51
49
|
if (!testResults.isEmpty) {
|
|
52
|
-
const error = hasError(testResults) ? stringifyError(testResults) : undefined
|
|
53
|
-
acc.push(
|
|
54
|
-
`${colorify(symbol, color)} ${colorify(error || stringifyTestResults(testResults))}`,
|
|
55
|
-
);
|
|
50
|
+
const error = hasError(testResults) ? stringifyError(testResults) : undefined
|
|
51
|
+
acc.push(`${colorify(symbol, color)} ${colorify(error || stringifyTestResults(testResults))}`)
|
|
56
52
|
}
|
|
57
|
-
return acc
|
|
58
|
-
}, [])
|
|
53
|
+
return acc
|
|
54
|
+
}, [])
|
|
59
55
|
|
|
60
|
-
const coloredTitle = results.length
|
|
61
|
-
|
|
62
|
-
: '';
|
|
63
|
-
return testResultsSection(coloredTitle, results);
|
|
56
|
+
const coloredTitle = results.length ? colorify(title(results.length), color, chalkFunction) : ''
|
|
57
|
+
return testResultsSection(coloredTitle, results)
|
|
64
58
|
}
|
|
65
59
|
|
|
66
60
|
function colorify(msg, color = 'reset') {
|
|
67
|
-
return isInteractive ? msg : `${colors[color]}${msg}${colors.reset}
|
|
61
|
+
return isInteractive ? msg : `${colors[color]}${msg}${colors.reset}`
|
|
68
62
|
}
|
|
69
63
|
}
|
|
70
64
|
|
|
71
65
|
function stringifyTestResults(testResults) {
|
|
72
|
-
const hostDisplaySize = testResults.hostDisplaySize
|
|
73
|
-
const viewport = hostDisplaySize ? `[${hostDisplaySize.width}x${hostDisplaySize.height}]` : ''
|
|
74
|
-
const testName = `${testResults.name} ${viewport}
|
|
75
|
-
return testName + (testResults.error ? ` : ${testResults.error}` : '')
|
|
66
|
+
const hostDisplaySize = testResults.hostDisplaySize
|
|
67
|
+
const viewport = hostDisplaySize ? `[${hostDisplaySize.width}x${hostDisplaySize.height}]` : ''
|
|
68
|
+
const testName = `${testResults.name} ${viewport}`
|
|
69
|
+
return testName + (testResults.error ? ` : ${testResults.error}` : '')
|
|
76
70
|
}
|
|
77
71
|
|
|
78
72
|
function testResultsSection(title, results) {
|
|
79
|
-
return results.length ? `${indent()}${title}${indent(3)}${results.join(indent(3))}` : ''
|
|
73
|
+
return results.length ? `${indent()}${title}${indent(3)}${results.join(indent(3))}` : ''
|
|
80
74
|
}
|
|
81
75
|
|
|
82
76
|
function stringifyError(testResults) {
|
|
83
|
-
return testResults.error
|
|
84
|
-
? stringifyTestResults(testResults)
|
|
85
|
-
: `[Eyes test not started] : ${testResults}`;
|
|
77
|
+
return testResults.error ? stringifyTestResults(testResults) : `[Eyes test not started] : ${testResults}`
|
|
86
78
|
}
|
|
87
79
|
|
|
88
80
|
function indent(spaces = 2) {
|
|
89
|
-
return `\n ${' '.repeat(spaces)}
|
|
81
|
+
return `\n ${' '.repeat(spaces)}`
|
|
90
82
|
}
|
|
91
83
|
|
|
92
84
|
function hasError(testResult) {
|
|
93
|
-
return testResult.error || testResult instanceof Error
|
|
85
|
+
return testResult.error || testResult instanceof Error
|
|
94
86
|
}
|
|
95
87
|
|
|
96
|
-
module.exports = errorDigest
|
|
88
|
+
module.exports = errorDigest
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict'
|
|
2
2
|
function getErrorsAndDiffs(testResultsArr) {
|
|
3
3
|
return testResultsArr.reduce(
|
|
4
4
|
({failed, diffs, passed}, testResults) => {
|
|
5
5
|
if (testResults instanceof Error || testResults.error) {
|
|
6
|
-
failed.push(testResults)
|
|
6
|
+
failed.push(testResults)
|
|
7
7
|
} else {
|
|
8
|
-
const testStatus = testResults.status
|
|
8
|
+
const testStatus = testResults.status
|
|
9
9
|
if (testStatus === 'Passed') {
|
|
10
|
-
passed.push(testResults)
|
|
10
|
+
passed.push(testResults)
|
|
11
11
|
} else {
|
|
12
12
|
if (testStatus === 'Unresolved') {
|
|
13
13
|
if (testResults.isNew) {
|
|
14
14
|
testResults.error = new Error(
|
|
15
15
|
`${testResults.name}. Please approve the new baseline at ${testResults.url}`,
|
|
16
|
-
)
|
|
17
|
-
failed.push(testResults)
|
|
16
|
+
)
|
|
17
|
+
failed.push(testResults)
|
|
18
18
|
} else {
|
|
19
|
-
diffs.push(testResults)
|
|
19
|
+
diffs.push(testResults)
|
|
20
20
|
}
|
|
21
21
|
} else if (testStatus === 'Failed') {
|
|
22
|
-
failed.push(testResults)
|
|
22
|
+
failed.push(testResults)
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
return {failed, diffs, passed}
|
|
27
|
+
return {failed, diffs, passed}
|
|
28
28
|
},
|
|
29
29
|
{failed: [], diffs: [], passed: []},
|
|
30
|
-
)
|
|
30
|
+
)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
module.exports = getErrorsAndDiffs
|
|
33
|
+
module.exports = getErrorsAndDiffs
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
const errorDigest = require('./errorDigest')
|
|
2
|
-
const {makeLogger} = require('@applitools/logger')
|
|
3
|
-
const getErrorsAndDiffs = require('./getErrorsAndDiffs')
|
|
4
|
-
const {promisify} = require('util')
|
|
5
|
-
const fs = require('fs')
|
|
6
|
-
const writeFile = promisify(fs.writeFile)
|
|
7
|
-
const {formatters} = require('@applitools/core')
|
|
8
|
-
const {resolve} = require('path')
|
|
1
|
+
const errorDigest = require('./errorDigest')
|
|
2
|
+
const {makeLogger} = require('@applitools/logger')
|
|
3
|
+
const getErrorsAndDiffs = require('./getErrorsAndDiffs')
|
|
4
|
+
const {promisify} = require('util')
|
|
5
|
+
const fs = require('fs')
|
|
6
|
+
const writeFile = promisify(fs.writeFile)
|
|
7
|
+
const {formatters} = require('@applitools/core')
|
|
8
|
+
const {resolve} = require('path')
|
|
9
9
|
|
|
10
10
|
function printTestResults(testResultsArr) {
|
|
11
11
|
const logger = makeLogger({
|
|
12
12
|
level: testResultsArr.resultConfig.showLogs ? 'info' : 'silent',
|
|
13
13
|
label: 'eyes',
|
|
14
|
-
})
|
|
15
|
-
if (!testResultsArr.testResults) return
|
|
16
|
-
const {passed, failed, diffs} = getErrorsAndDiffs(testResultsArr.testResults)
|
|
14
|
+
})
|
|
15
|
+
if (!testResultsArr.testResults) return
|
|
16
|
+
const {passed, failed, diffs} = getErrorsAndDiffs(testResultsArr.testResults)
|
|
17
17
|
if ((failed.length || diffs.length) && !!testResultsArr.resultConfig.eyesFailCypressOnDiff) {
|
|
18
18
|
throw new Error(
|
|
19
19
|
errorDigest({
|
|
@@ -23,16 +23,13 @@ function printTestResults(testResultsArr) {
|
|
|
23
23
|
logger,
|
|
24
24
|
isInteractive: !testResultsArr.resultConfig.isTextTerminal,
|
|
25
25
|
}),
|
|
26
|
-
)
|
|
26
|
+
)
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
function handleBatchResultsFile(results, tapFileConfig) {
|
|
30
|
-
const fileName = tapFileConfig.tapFileName || `${new Date().toISOString()}-eyes.tap
|
|
31
|
-
const tapFile = resolve(tapFileConfig.tapDirPath, fileName)
|
|
32
|
-
return writeFile(
|
|
33
|
-
tapFile,
|
|
34
|
-
formatters.toHierarchicTAPString(results, {includeSubTests: false, markNewAsPassed: true}),
|
|
35
|
-
);
|
|
30
|
+
const fileName = tapFileConfig.tapFileName || `${new Date().toISOString()}-eyes.tap`
|
|
31
|
+
const tapFile = resolve(tapFileConfig.tapDirPath, fileName)
|
|
32
|
+
return writeFile(tapFile, formatters.toHierarchicTAPString(results, {includeSubTests: false, markNewAsPassed: true}))
|
|
36
33
|
}
|
|
37
34
|
|
|
38
|
-
module.exports = {printTestResults, handleBatchResultsFile}
|
|
35
|
+
module.exports = {printTestResults, handleBatchResultsFile}
|
package/src/plugin/hooks.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
const handleTestResults = require('./handleTestResults')
|
|
1
|
+
'use strict'
|
|
2
|
+
const handleTestResults = require('./handleTestResults')
|
|
3
3
|
|
|
4
4
|
function makeGlobalRunHooks({closeManager, closeBatches, closeUniversalServer}) {
|
|
5
5
|
return {
|
|
6
6
|
'before:run': ({config}) => {
|
|
7
|
-
if (!config.isTextTerminal) return
|
|
7
|
+
if (!config.isTextTerminal) return
|
|
8
8
|
},
|
|
9
9
|
|
|
10
10
|
'after:run': async ({config}) => {
|
|
11
11
|
try {
|
|
12
|
-
if (!config.isTextTerminal) return
|
|
13
|
-
const summaries = await closeManager()
|
|
12
|
+
if (!config.isTextTerminal) return
|
|
13
|
+
const summaries = await closeManager()
|
|
14
14
|
|
|
15
|
-
let testResults
|
|
15
|
+
let testResults
|
|
16
16
|
for (const summary of summaries) {
|
|
17
|
-
testResults = summary.results.map(({testResults}) => testResults)
|
|
17
|
+
testResults = summary.results.map(({testResults}) => testResults)
|
|
18
18
|
}
|
|
19
19
|
if (!config.appliConfFile.dontCloseBatches) {
|
|
20
20
|
await closeBatches({
|
|
@@ -22,20 +22,20 @@ function makeGlobalRunHooks({closeManager, closeBatches, closeUniversalServer})
|
|
|
22
22
|
serverUrl: config.appliConfFile.serverUrl,
|
|
23
23
|
proxy: config.appliConfFile.proxy,
|
|
24
24
|
apiKey: config.appliConfFile.apiKey,
|
|
25
|
-
})
|
|
25
|
+
})
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
if (config.appliConfFile.tapDirPath) {
|
|
29
29
|
await handleTestResults.handleBatchResultsFile(testResults, {
|
|
30
30
|
tapDirPath: config.appliConfFile.tapDirPath,
|
|
31
31
|
tapFileName: config.appliConfFile.tapFileName,
|
|
32
|
-
})
|
|
32
|
+
})
|
|
33
33
|
}
|
|
34
34
|
} finally {
|
|
35
|
-
await closeUniversalServer()
|
|
35
|
+
await closeUniversalServer()
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
|
-
}
|
|
38
|
+
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
module.exports = makeGlobalRunHooks
|
|
41
|
+
module.exports = makeGlobalRunHooks
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
const CYPRESS_SUPPORTED_VERSION = '6.2.0'
|
|
2
|
-
const CYPRESS_NO_FLAG_VERSION = '6.7.0'
|
|
1
|
+
const CYPRESS_SUPPORTED_VERSION = '6.2.0'
|
|
2
|
+
const CYPRESS_NO_FLAG_VERSION = '6.7.0'
|
|
3
3
|
|
|
4
4
|
function isGlobalHooksSupported(config) {
|
|
5
|
-
const {version, experimentalRunEvents} = config
|
|
5
|
+
const {version, experimentalRunEvents} = config
|
|
6
6
|
|
|
7
7
|
return (
|
|
8
8
|
parseFloat(version, 10) >= parseFloat(CYPRESS_NO_FLAG_VERSION, 10) ||
|
|
9
|
-
(parseFloat(version, 10) >= parseFloat(CYPRESS_SUPPORTED_VERSION, 10) &&
|
|
10
|
-
|
|
11
|
-
);
|
|
9
|
+
(parseFloat(version, 10) >= parseFloat(CYPRESS_SUPPORTED_VERSION, 10) && !!experimentalRunEvents)
|
|
10
|
+
)
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
module.exports = isGlobalHooksSupported
|
|
13
|
+
module.exports = isGlobalHooksSupported
|
|
@@ -1,99 +1,94 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
const isGlobalHooksSupported = require('./isGlobalHooksSupported')
|
|
3
|
-
const {presult} = require('@applitools/functional-commons')
|
|
4
|
-
const makeGlobalRunHooks = require('./hooks')
|
|
1
|
+
'use strict'
|
|
2
|
+
const isGlobalHooksSupported = require('./isGlobalHooksSupported')
|
|
3
|
+
const {presult} = require('@applitools/functional-commons')
|
|
4
|
+
const makeGlobalRunHooks = require('./hooks')
|
|
5
5
|
|
|
6
6
|
function makePluginExport({startServer, eyesConfig}) {
|
|
7
7
|
return function pluginExport(pluginModule) {
|
|
8
|
-
let eyesServer, pluginModuleExports, pluginExportsE2E, pluginExportsComponent
|
|
8
|
+
let eyesServer, pluginModuleExports, pluginExportsE2E, pluginExportsComponent
|
|
9
9
|
const pluginExports =
|
|
10
|
-
pluginModule.exports && pluginModule.exports.default
|
|
11
|
-
? pluginModule.exports.default
|
|
12
|
-
: pluginModule.exports;
|
|
10
|
+
pluginModule.exports && pluginModule.exports.default ? pluginModule.exports.default : pluginModule.exports
|
|
13
11
|
|
|
14
12
|
if (pluginExports.component) {
|
|
15
|
-
pluginExportsComponent = pluginExports.component.setupNodeEvents
|
|
13
|
+
pluginExportsComponent = pluginExports.component.setupNodeEvents
|
|
16
14
|
}
|
|
17
15
|
if (pluginExports.e2e) {
|
|
18
|
-
pluginExportsE2E = pluginExports.e2e.setupNodeEvents
|
|
16
|
+
pluginExportsE2E = pluginExports.e2e.setupNodeEvents
|
|
19
17
|
}
|
|
20
18
|
if (!pluginExports.e2e && !pluginExports.component) {
|
|
21
|
-
pluginModuleExports = pluginExports
|
|
19
|
+
pluginModuleExports = pluginExports
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
const setupNodeEvents = async function(...args) {
|
|
25
|
-
const {server, port, closeManager, closeBatches, closeUniversalServer} = await startServer()
|
|
26
|
-
eyesServer = server
|
|
22
|
+
const setupNodeEvents = async function (...args) {
|
|
23
|
+
const {server, port, closeManager, closeBatches, closeUniversalServer} = await startServer()
|
|
24
|
+
eyesServer = server
|
|
27
25
|
|
|
28
|
-
const globalHooks = makeGlobalRunHooks({closeManager, closeBatches, closeUniversalServer})
|
|
26
|
+
const globalHooks = makeGlobalRunHooks({closeManager, closeBatches, closeUniversalServer})
|
|
29
27
|
|
|
30
|
-
const [origOn, config] = args
|
|
28
|
+
const [origOn, config] = args
|
|
31
29
|
|
|
32
30
|
if (!pluginModuleExports) {
|
|
33
|
-
pluginModuleExports =
|
|
34
|
-
config.testingType === 'e2e' ? pluginExportsE2E : pluginExportsComponent;
|
|
31
|
+
pluginModuleExports = config.testingType === 'e2e' ? pluginExportsE2E : pluginExportsComponent
|
|
35
32
|
}
|
|
36
33
|
|
|
37
|
-
const isGlobalHookCalledFromUserHandlerMap = new Map()
|
|
38
|
-
eyesConfig.eyesIsGlobalHooksSupported = isGlobalHooksSupported(config)
|
|
39
|
-
let moduleExportsResult = {}
|
|
34
|
+
const isGlobalHookCalledFromUserHandlerMap = new Map()
|
|
35
|
+
eyesConfig.eyesIsGlobalHooksSupported = isGlobalHooksSupported(config)
|
|
36
|
+
let moduleExportsResult = {}
|
|
40
37
|
// in case setupNodeEvents is not defined in cypress.config file
|
|
41
38
|
if (typeof pluginModuleExports === 'function') {
|
|
42
|
-
moduleExportsResult = await pluginModuleExports(onThatCallsUserDefinedHandler, config)
|
|
39
|
+
moduleExportsResult = await pluginModuleExports(onThatCallsUserDefinedHandler, config)
|
|
43
40
|
}
|
|
44
41
|
if (eyesConfig.eyesIsGlobalHooksSupported) {
|
|
45
42
|
for (const [eventName, eventHandler] of Object.entries(globalHooks)) {
|
|
46
43
|
if (!isGlobalHookCalledFromUserHandlerMap.get(eventName)) {
|
|
47
|
-
origOn.call(this, eventName, eventHandler)
|
|
44
|
+
origOn.call(this, eventName, eventHandler)
|
|
48
45
|
}
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
48
|
|
|
52
|
-
return Object.assign({}, eyesConfig, {eyesPort: port}, moduleExportsResult)
|
|
49
|
+
return Object.assign({}, eyesConfig, {eyesPort: port}, moduleExportsResult)
|
|
53
50
|
|
|
54
51
|
// This piece of code exists because at the point of writing, Cypress does not support multiple event handlers:
|
|
55
52
|
// https://github.com/cypress-io/cypress/issues/5240#issuecomment-948277554
|
|
56
53
|
// So we wrap Cypress' `on` function in order to wrap the user-defined handler. This way we can call our own handler
|
|
57
54
|
// in addition to the user's handler
|
|
58
55
|
function onThatCallsUserDefinedHandler(eventName, handler) {
|
|
59
|
-
const isRunEvent = eventName === 'before:run' || eventName === 'after:run'
|
|
60
|
-
let handlerToCall = handler
|
|
56
|
+
const isRunEvent = eventName === 'before:run' || eventName === 'after:run'
|
|
57
|
+
let handlerToCall = handler
|
|
61
58
|
if (eyesConfig.eyesIsGlobalHooksSupported && isRunEvent) {
|
|
62
|
-
handlerToCall = handlerThatCallsUserDefinedHandler
|
|
63
|
-
isGlobalHookCalledFromUserHandlerMap.set(eventName, true)
|
|
59
|
+
handlerToCall = handlerThatCallsUserDefinedHandler
|
|
60
|
+
isGlobalHookCalledFromUserHandlerMap.set(eventName, true)
|
|
64
61
|
}
|
|
65
|
-
return origOn.call(this, eventName, handlerToCall)
|
|
62
|
+
return origOn.call(this, eventName, handlerToCall)
|
|
66
63
|
|
|
67
64
|
async function handlerThatCallsUserDefinedHandler() {
|
|
68
|
-
const [err] = await presult(
|
|
69
|
-
|
|
70
|
-
);
|
|
71
|
-
await handler.apply(this, arguments);
|
|
65
|
+
const [err] = await presult(Promise.resolve(globalHooks[eventName].apply(this, arguments)))
|
|
66
|
+
await handler.apply(this, arguments)
|
|
72
67
|
if (err) {
|
|
73
|
-
throw err
|
|
68
|
+
throw err
|
|
74
69
|
}
|
|
75
70
|
}
|
|
76
71
|
}
|
|
77
|
-
}
|
|
72
|
+
}
|
|
78
73
|
|
|
79
74
|
if (pluginExports.component) {
|
|
80
|
-
pluginExports.component.setupNodeEvents = setupNodeEvents
|
|
75
|
+
pluginExports.component.setupNodeEvents = setupNodeEvents
|
|
81
76
|
}
|
|
82
77
|
if (pluginExports.e2e) {
|
|
83
|
-
pluginExports.e2e.setupNodeEvents = setupNodeEvents
|
|
78
|
+
pluginExports.e2e.setupNodeEvents = setupNodeEvents
|
|
84
79
|
}
|
|
85
80
|
if (!pluginExports.component && !pluginExports.e2e) {
|
|
86
81
|
if (pluginModule.exports.default) {
|
|
87
|
-
pluginModule.exports.default = setupNodeEvents
|
|
82
|
+
pluginModule.exports.default = setupNodeEvents
|
|
88
83
|
} else {
|
|
89
|
-
pluginModule.exports = setupNodeEvents
|
|
84
|
+
pluginModule.exports = setupNodeEvents
|
|
90
85
|
}
|
|
91
86
|
}
|
|
92
87
|
|
|
93
88
|
return function getCloseServer() {
|
|
94
|
-
return eyesServer.close()
|
|
95
|
-
}
|
|
96
|
-
}
|
|
89
|
+
return eyesServer.close()
|
|
90
|
+
}
|
|
91
|
+
}
|
|
97
92
|
}
|
|
98
93
|
|
|
99
|
-
module.exports = makePluginExport
|
|
94
|
+
module.exports = makePluginExport
|
package/src/plugin/server.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
const connectSocket = require('./webSocket')
|
|
3
|
-
const {makeServerProcess} = require('@applitools/eyes-universal')
|
|
4
|
-
const handleTestResults = require('./handleTestResults')
|
|
5
|
-
const path = require('path')
|
|
6
|
-
const fs = require('fs')
|
|
7
|
-
const semverLt = require('semver/functions/lt')
|
|
8
|
-
const {Server: HttpsServer} = require('https')
|
|
9
|
-
const {Server: WSServer} = require('ws')
|
|
10
|
-
const which = require('which')
|
|
1
|
+
'use strict'
|
|
2
|
+
const connectSocket = require('./webSocket')
|
|
3
|
+
const {makeServerProcess} = require('@applitools/eyes-universal')
|
|
4
|
+
const handleTestResults = require('./handleTestResults')
|
|
5
|
+
const path = require('path')
|
|
6
|
+
const fs = require('fs')
|
|
7
|
+
const semverLt = require('semver/functions/lt')
|
|
8
|
+
const {Server: HttpsServer} = require('https')
|
|
9
|
+
const {Server: WSServer} = require('ws')
|
|
10
|
+
const which = require('which')
|
|
11
11
|
|
|
12
12
|
function makeStartServer({logger}) {
|
|
13
13
|
return async function startServer() {
|
|
14
|
-
const key = fs.readFileSync(path.resolve(__dirname, '../pem/server.key'))
|
|
15
|
-
const cert = fs.readFileSync(path.resolve(__dirname, '../pem/server.cert'))
|
|
16
|
-
let port
|
|
14
|
+
const key = fs.readFileSync(path.resolve(__dirname, '../pem/server.key'))
|
|
15
|
+
const cert = fs.readFileSync(path.resolve(__dirname, '../pem/server.cert'))
|
|
16
|
+
let port
|
|
17
17
|
|
|
18
18
|
const https = new HttpsServer({
|
|
19
19
|
key,
|
|
20
20
|
cert,
|
|
21
|
-
})
|
|
21
|
+
})
|
|
22
22
|
await https.listen(0, err => {
|
|
23
23
|
if (err) {
|
|
24
|
-
logger.log('error starting plugin server', err)
|
|
24
|
+
logger.log('error starting plugin server', err)
|
|
25
25
|
} else {
|
|
26
|
-
logger.log(`plugin server running at port: ${https.address().port}`)
|
|
27
|
-
port = https.address().port
|
|
26
|
+
logger.log(`plugin server running at port: ${https.address().port}`)
|
|
27
|
+
port = https.address().port
|
|
28
28
|
}
|
|
29
|
-
})
|
|
29
|
+
})
|
|
30
30
|
|
|
31
|
-
const wss = new WSServer({server: https, path: '/eyes', maxPayload: 254 * 1024 * 1024})
|
|
31
|
+
const wss = new WSServer({server: https, path: '/eyes', maxPayload: 254 * 1024 * 1024})
|
|
32
32
|
|
|
33
|
-
wss.on('close', () => https.close())
|
|
33
|
+
wss.on('close', () => https.close())
|
|
34
34
|
|
|
35
35
|
const forkOptions = {
|
|
36
36
|
detached: true,
|
|
37
|
-
}
|
|
37
|
+
}
|
|
38
38
|
|
|
39
|
-
const cypressVersion = require('cypress/package.json').version
|
|
39
|
+
const cypressVersion = require('cypress/package.json').version
|
|
40
40
|
|
|
41
41
|
// `cypress` version below `7.0.0` has an old Electron version which not support async shell process.
|
|
42
42
|
// By passing `execPath` with the node process cwd it will switch the `node` process to be the like the OS have
|
|
43
43
|
// and will not use the unsupported `Cypress Helper.app` with the not supported shell process Electron
|
|
44
44
|
if (semverLt(cypressVersion, '7.0.0')) {
|
|
45
|
-
forkOptions.execPath = await which('node')
|
|
45
|
+
forkOptions.execPath = await which('node')
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
const {port: universalPort, close: closeUniversalServer} = await makeServerProcess({
|
|
@@ -51,27 +51,27 @@ function makeStartServer({logger}) {
|
|
|
51
51
|
forkOptions,
|
|
52
52
|
singleton: false,
|
|
53
53
|
portResolutionMode: 'random',
|
|
54
|
-
})
|
|
54
|
+
})
|
|
55
55
|
|
|
56
|
-
const managers = []
|
|
57
|
-
let socketWithUniversal
|
|
56
|
+
const managers = []
|
|
57
|
+
let socketWithUniversal
|
|
58
58
|
|
|
59
59
|
wss.on('connection', socketWithClient => {
|
|
60
|
-
socketWithUniversal = connectSocket(`ws://localhost:${universalPort}/eyes`)
|
|
60
|
+
socketWithUniversal = connectSocket(`ws://localhost:${universalPort}/eyes`)
|
|
61
61
|
|
|
62
62
|
socketWithUniversal.setPassthroughListener(message => {
|
|
63
|
-
logger.log('<== ', message.toString().slice(0, 1000))
|
|
64
|
-
const {name, payload} = JSON.parse(message)
|
|
63
|
+
logger.log('<== ', message.toString().slice(0, 1000))
|
|
64
|
+
const {name, payload} = JSON.parse(message)
|
|
65
65
|
if (name === 'Core.makeManager') {
|
|
66
|
-
managers.push({manager: payload.result, socketWithUniversal})
|
|
66
|
+
managers.push({manager: payload.result, socketWithUniversal})
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
socketWithClient.send(message.toString())
|
|
70
|
-
})
|
|
69
|
+
socketWithClient.send(message.toString())
|
|
70
|
+
})
|
|
71
71
|
|
|
72
72
|
socketWithClient.on('message', message => {
|
|
73
|
-
const msg = JSON.parse(message)
|
|
74
|
-
logger.log('==> ', message.toString().slice(0, 1000))
|
|
73
|
+
const msg = JSON.parse(message)
|
|
74
|
+
logger.log('==> ', message.toString().slice(0, 1000))
|
|
75
75
|
if (msg.name === 'Core.makeSDK') {
|
|
76
76
|
const newMessage = Buffer.from(
|
|
77
77
|
JSON.stringify({
|
|
@@ -80,30 +80,27 @@ function makeStartServer({logger}) {
|
|
|
80
80
|
payload: Object.assign(msg.payload, {cwd: process.cwd()}),
|
|
81
81
|
}),
|
|
82
82
|
'utf-8',
|
|
83
|
-
)
|
|
84
|
-
socketWithUniversal.send(newMessage)
|
|
83
|
+
)
|
|
84
|
+
socketWithUniversal.send(newMessage)
|
|
85
85
|
} else if (msg.name === 'Test.printTestResults') {
|
|
86
86
|
try {
|
|
87
|
-
if (
|
|
88
|
-
msg.payload.resultConfig.tapDirPath &&
|
|
89
|
-
msg.payload.resultConfig.shouldCreateTapFile
|
|
90
|
-
) {
|
|
87
|
+
if (msg.payload.resultConfig.tapDirPath && msg.payload.resultConfig.shouldCreateTapFile) {
|
|
91
88
|
handleTestResults.handleBatchResultsFile(msg.payload.testResults, {
|
|
92
89
|
tapFileName: msg.payload.resultConfig.tapFileName,
|
|
93
90
|
tapDirPath: msg.payload.resultConfig.tapDirPath,
|
|
94
|
-
})
|
|
91
|
+
})
|
|
95
92
|
}
|
|
96
93
|
handleTestResults.printTestResults({
|
|
97
94
|
testResults: msg.payload.testResults,
|
|
98
95
|
resultConfig: msg.payload.resultConfig,
|
|
99
|
-
})
|
|
96
|
+
})
|
|
100
97
|
socketWithClient.send(
|
|
101
98
|
JSON.stringify({
|
|
102
99
|
name: 'Test.printTestResults',
|
|
103
100
|
key: msg.key,
|
|
104
101
|
payload: {result: 'success'},
|
|
105
102
|
}),
|
|
106
|
-
)
|
|
103
|
+
)
|
|
107
104
|
} catch (ex) {
|
|
108
105
|
socketWithClient.send(
|
|
109
106
|
JSON.stringify({
|
|
@@ -111,13 +108,13 @@ function makeStartServer({logger}) {
|
|
|
111
108
|
key: msg.key,
|
|
112
109
|
payload: {result: ex.message.toString()},
|
|
113
110
|
}),
|
|
114
|
-
)
|
|
111
|
+
)
|
|
115
112
|
}
|
|
116
113
|
} else {
|
|
117
|
-
socketWithUniversal.send(message)
|
|
114
|
+
socketWithUniversal.send(message)
|
|
118
115
|
}
|
|
119
|
-
})
|
|
120
|
-
})
|
|
116
|
+
})
|
|
117
|
+
})
|
|
121
118
|
|
|
122
119
|
return {
|
|
123
120
|
server: wss,
|
|
@@ -125,7 +122,7 @@ function makeStartServer({logger}) {
|
|
|
125
122
|
closeManager,
|
|
126
123
|
closeBatches,
|
|
127
124
|
closeUniversalServer,
|
|
128
|
-
}
|
|
125
|
+
}
|
|
129
126
|
|
|
130
127
|
function closeManager() {
|
|
131
128
|
return Promise.all(
|
|
@@ -135,15 +132,15 @@ function makeStartServer({logger}) {
|
|
|
135
132
|
throwErr: false,
|
|
136
133
|
}),
|
|
137
134
|
),
|
|
138
|
-
)
|
|
135
|
+
)
|
|
139
136
|
}
|
|
140
137
|
function closeBatches(settings) {
|
|
141
138
|
if (socketWithUniversal)
|
|
142
139
|
return socketWithUniversal.request('Core.closeBatches', {settings}).catch(err => {
|
|
143
|
-
logger.log('@@@', err)
|
|
144
|
-
})
|
|
140
|
+
logger.log('@@@', err)
|
|
141
|
+
})
|
|
145
142
|
}
|
|
146
|
-
}
|
|
143
|
+
}
|
|
147
144
|
}
|
|
148
145
|
|
|
149
|
-
module.exports = makeStartServer
|
|
146
|
+
module.exports = makeStartServer
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
const makePluginExport = require('./pluginExport')
|
|
3
|
-
const makeConfig = require('./config')
|
|
4
|
-
const makeStartServer = require('./server')
|
|
5
|
-
const {makeLogger} = require('@applitools/logger')
|
|
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
6
|
|
|
7
|
-
const {config, eyesConfig} = makeConfig()
|
|
8
|
-
const logger = makeLogger({level: config.showLogs ? 'info' : 'silent', label: 'eyes'})
|
|
7
|
+
const {config, eyesConfig} = makeConfig()
|
|
8
|
+
const logger = makeLogger({level: config.showLogs ? 'info' : 'silent', label: 'eyes'})
|
|
9
9
|
|
|
10
|
-
const startServer = makeStartServer({logger})
|
|
10
|
+
const startServer = makeStartServer({logger})
|
|
11
11
|
|
|
12
12
|
module.exports = makePluginExport({
|
|
13
13
|
startServer,
|
|
14
14
|
eyesConfig: Object.assign({}, eyesConfig, {appliConfFile: config}),
|
|
15
|
-
})
|
|
15
|
+
})
|