mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-06 14:39:48 -06:00
181 lines
3.7 KiB
JavaScript
181 lines
3.7 KiB
JavaScript
const os = require('os')
|
|
const chalk = require('chalk')
|
|
const Promise = require('bluebird')
|
|
const getos = Promise.promisify(require('getos'))
|
|
const { stripIndent, stripIndents } = require('common-tags')
|
|
const { merge } = require('ramda')
|
|
|
|
const util = require('./util')
|
|
|
|
const issuesUrl = 'https://github.com/cypress-io/cypress/issues'
|
|
const docsUrl = 'https://on.cypress.io'
|
|
const requiredDependenciesUrl = `${docsUrl}/required-dependencies`
|
|
|
|
const pkgVersion = util.pkgVersion()
|
|
|
|
// common errors Cypress application can encounter
|
|
const failedDownload = {
|
|
description: 'The Cypress App could not be downloaded.',
|
|
solution: 'Please check network connectivity and try again',
|
|
}
|
|
|
|
const failedToUnzip = {
|
|
description: 'The Cypress App could not be unzipped.',
|
|
solution: stripIndent`
|
|
Search for an existing issue or open a GitHub issue at
|
|
|
|
${issuesUrl}
|
|
`,
|
|
}
|
|
|
|
const missingApp = {
|
|
description: 'No version of Cypress executable is installed.',
|
|
solution: stripIndent`
|
|
\nPlease reinstall Cypress by running: ${chalk.cyan('cypress install')}
|
|
`,
|
|
}
|
|
|
|
const missingXvfb = {
|
|
description: 'Your system is missing the dependency: XVFB',
|
|
solution: stripIndent`
|
|
Install XVFB and run Cypress again.
|
|
|
|
Our CI documentation provides more information how to configure dependencies
|
|
`,
|
|
footer: stripIndent`
|
|
Read our doc on CI dependencies for more information:
|
|
|
|
${requiredDependenciesUrl}
|
|
`,
|
|
}
|
|
|
|
const missingDependency = {
|
|
description: 'We could not run Cypress.',
|
|
// this message is too Linux specific
|
|
solution: stripIndent`
|
|
This is usually caused by a missing library or dependency.
|
|
|
|
The error below should indicate which dependency is missing.
|
|
|
|
${requiredDependenciesUrl}
|
|
`,
|
|
}
|
|
|
|
const versionMismatch = {
|
|
description: 'Installed version does not match package version.',
|
|
solution: 'Install Cypress and verify app again',
|
|
}
|
|
|
|
const unexpected = {
|
|
description: 'An unexpected error occurred while verifying the Cypress executable.',
|
|
solution: stripIndent`
|
|
Please search Cypress documentation for possible solutions:
|
|
|
|
${docsUrl}
|
|
|
|
Check if there is a GitHub issue describing this crash:
|
|
|
|
${issuesUrl}
|
|
|
|
Consider opening a new issue.
|
|
`,
|
|
}
|
|
|
|
const getOsVersion = () => {
|
|
if (os.platform() === 'linux') {
|
|
return getos()
|
|
.then((osInfo) => [osInfo.dist, osInfo.release].join(' - '))
|
|
.catch(() => os.release())
|
|
} else {
|
|
return Promise.resolve(os.release())
|
|
}
|
|
}
|
|
|
|
function getPlatformInfo () {
|
|
return getOsVersion()
|
|
.then((version) => stripIndent`
|
|
Platform: ${os.platform()} (${version})
|
|
Cypress Version: ${pkgVersion}
|
|
`)
|
|
}
|
|
|
|
function addPlatformInformation (info) {
|
|
return getPlatformInfo()
|
|
.then((platform) => merge(info, { platform }))
|
|
}
|
|
|
|
function formErrorText (info, msg) {
|
|
const hr = '----------'
|
|
|
|
return addPlatformInformation(info)
|
|
.then((obj) => {
|
|
const formatted = []
|
|
|
|
function add (msg) {
|
|
formatted.push(
|
|
stripIndents`${msg}`
|
|
)
|
|
}
|
|
|
|
add(`
|
|
${obj.description}
|
|
|
|
${obj.solution}
|
|
|
|
`)
|
|
|
|
if (msg) {
|
|
add(`
|
|
${hr}
|
|
|
|
${msg}
|
|
|
|
`)
|
|
}
|
|
|
|
add(`
|
|
${hr}
|
|
|
|
${obj.platform}
|
|
`)
|
|
|
|
if (obj.footer) {
|
|
add(`
|
|
|
|
${hr}
|
|
|
|
${obj.footer}
|
|
`)
|
|
}
|
|
|
|
return formatted.join('\n')
|
|
})
|
|
}
|
|
|
|
const raise = (text) => {
|
|
const err = new Error(text)
|
|
err.known = true
|
|
throw err
|
|
}
|
|
|
|
const throwFormErrorText = (info) => (msg) => {
|
|
return formErrorText(info, msg)
|
|
.then(raise)
|
|
}
|
|
|
|
module.exports = {
|
|
raise,
|
|
// formError,
|
|
formErrorText,
|
|
throwFormErrorText,
|
|
errors: {
|
|
missingXvfb,
|
|
missingApp,
|
|
missingDependency,
|
|
versionMismatch,
|
|
unexpected,
|
|
failedDownload,
|
|
failedToUnzip,
|
|
},
|
|
}
|