mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-04 05:50:47 -05:00
cli: when running in CI, use a different renderer to prevent ugly stream of stdout updates
This commit is contained in:
@@ -88,3 +88,19 @@ You should probably run these commands:
|
||||
- npm install --save-dev cypress
|
||||
`
|
||||
|
||||
exports['installing in ci 1'] = `Installed version (x.x.x) does not match needed version (1.2.3).
|
||||
|
||||
Installing Cypress (version: 1.2.3)
|
||||
|
||||
[?25l[2m[xx:xx:xx][22m Downloading Cypress [started]
|
||||
[2m[xx:xx:xx][22m Downloading Cypress [completed]
|
||||
[2m[xx:xx:xx][22m Unzipping Cypress [started]
|
||||
[2m[xx:xx:xx][22m Unzipping Cypress [completed]
|
||||
[2m[xx:xx:xx][22m Finishing Installation [started]
|
||||
[2m[xx:xx:xx][22m Finishing Installation [completed]
|
||||
[?25h
|
||||
You can now open Cypress by running: node_modules/.bin/cypress open
|
||||
|
||||
https://on.cypress.io/installing-cypress
|
||||
`
|
||||
|
||||
|
||||
@@ -87,3 +87,8 @@ exports['current version has not been verified 1'] = `[33mIt looks like this is
|
||||
[?25l [32m✔[39m [34m [32mVerified Cypress![34m [90m/path/to/executable/dir[34m[39m
|
||||
[?25h`
|
||||
|
||||
exports['verifying in ci 1'] = `[33mIt looks like this is your first time using Cypress: [36m1.2.3[33m[39m
|
||||
|
||||
[?25l[2m[xx:xx:xx][22m [34m Verifying Cypress can run [90m/path/to/executable/dir[34m[39m [started]
|
||||
[2m[xx:xx:xx][22m [34m Verifying Cypress can run [90m/path/to/executable/dir[34m[39m [completed]
|
||||
[?25h`
|
||||
|
||||
@@ -67,7 +67,7 @@ const downloadAndUnzip = (version) => {
|
||||
logger.log(chalk.yellow(`Installing Cypress ${chalk.gray(`(version: ${version})`)}`))
|
||||
logger.log()
|
||||
|
||||
const progessify = (title, task) => {
|
||||
const progessify = (task, title) => {
|
||||
// return higher order function
|
||||
return (percentComplete, remaining) => {
|
||||
percentComplete = chalk.white(` ${percentComplete}%`)
|
||||
@@ -79,20 +79,29 @@ const downloadAndUnzip = (version) => {
|
||||
}
|
||||
}
|
||||
|
||||
// if we are running in CI then use
|
||||
// the verbose renderer else use
|
||||
// the default
|
||||
const rendererOptions = {
|
||||
renderer: util.isCi() ? 'verbose' : 'default',
|
||||
}
|
||||
|
||||
const tasks = new Listr([
|
||||
{
|
||||
title: util.titleize('Downloading Cypress'),
|
||||
task: (ctx, task) => {
|
||||
// as our download progresses indicate the status
|
||||
options.onProgress = progessify('Downloading Cypress', task)
|
||||
options.onProgress = progessify(task, 'Downloading Cypress')
|
||||
|
||||
return download.start(options)
|
||||
.then((downloadDestination) => {
|
||||
// save the download destination for unzipping
|
||||
ctx.downloadDestination = downloadDestination
|
||||
|
||||
task.title = util.titleize(
|
||||
chalk.green('Downloaded Cypress')
|
||||
util.setTaskTitle(
|
||||
task,
|
||||
util.titleize(chalk.green('Downloaded Cypress')),
|
||||
rendererOptions.renderer
|
||||
)
|
||||
})
|
||||
},
|
||||
@@ -102,12 +111,14 @@ const downloadAndUnzip = (version) => {
|
||||
task: (ctx, task) => {
|
||||
// as our unzip progresses indicate the status
|
||||
options.downloadDestination = ctx.downloadDestination
|
||||
options.onProgress = progessify('Unzipping Cypress', task)
|
||||
options.onProgress = progessify(task, 'Unzipping Cypress')
|
||||
|
||||
return unzip.start(options)
|
||||
.then(() => {
|
||||
task.title = util.titleize(
|
||||
chalk.green('Unzipped Cypress')
|
||||
util.setTaskTitle(
|
||||
task,
|
||||
util.titleize(chalk.green('Unzipped Cypress')),
|
||||
rendererOptions.renderer
|
||||
)
|
||||
})
|
||||
},
|
||||
@@ -123,13 +134,17 @@ const downloadAndUnzip = (version) => {
|
||||
.then(() => {
|
||||
const dir = info.getPathToUserExecutableDir()
|
||||
|
||||
task.title = util.titleize(chalk.green('Finished Installation'), chalk.gray(dir))
|
||||
util.setTaskTitle(
|
||||
task,
|
||||
util.titleize(chalk.green('Finished Installation'), chalk.gray(dir)),
|
||||
rendererOptions.renderer
|
||||
)
|
||||
|
||||
return info.writeInstalledVersion(version)
|
||||
})
|
||||
},
|
||||
},
|
||||
])
|
||||
], rendererOptions)
|
||||
|
||||
// start the tasks!
|
||||
return tasks.run()
|
||||
|
||||
+16
-4
@@ -136,6 +136,14 @@ function testBinary (version) {
|
||||
|
||||
logger.log()
|
||||
|
||||
// if we are running in CI then use
|
||||
// the verbose renderer else use
|
||||
// the default
|
||||
const rendererOptions = {
|
||||
renderer: util.isCi() ? 'verbose' : 'default',
|
||||
}
|
||||
|
||||
|
||||
const tasks = new Listr([
|
||||
{
|
||||
title: util.titleize('Verifying Cypress can run', chalk.gray(dir)),
|
||||
@@ -152,16 +160,20 @@ function testBinary (version) {
|
||||
return writeVerifiedVersion(version)
|
||||
})
|
||||
.then(() => {
|
||||
task.title = util.titleize(
|
||||
chalk.green('Verified Cypress!'),
|
||||
chalk.gray(dir)
|
||||
util.setTaskTitle(
|
||||
task,
|
||||
util.titleize(
|
||||
chalk.green('Verified Cypress!'),
|
||||
chalk.gray(dir)
|
||||
),
|
||||
rendererOptions.renderer
|
||||
)
|
||||
})
|
||||
.catch({ isXvfbError: true }, throwFormErrorText(errors.missingXvfb))
|
||||
.catch({ isVerificationError: true }, throwFormErrorText(errors.missingDependency))
|
||||
},
|
||||
},
|
||||
])
|
||||
], rendererOptions)
|
||||
|
||||
return tasks.run()
|
||||
}
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
const _ = require('lodash')
|
||||
const path = require('path')
|
||||
const isCi = require('is-ci')
|
||||
const chalk = require('chalk')
|
||||
const isInstalledGlobally = require('is-installed-globally')
|
||||
const pkg = require(path.join(__dirname, '..', 'package.json'))
|
||||
const logger = require('./logger')
|
||||
|
||||
const datesRe = /(\d+:\d+:\d+)/g
|
||||
|
||||
module.exports = {
|
||||
isCi () {
|
||||
return isCi
|
||||
},
|
||||
|
||||
cwd () {
|
||||
return process.cwd()
|
||||
},
|
||||
@@ -54,6 +61,17 @@ module.exports = {
|
||||
return (_.isFinite(eta) ? (eta / 1000) : 0).toFixed(0)
|
||||
},
|
||||
|
||||
stripDates (str) {
|
||||
return str.replace(datesRe, 'xx:xx:xx')
|
||||
},
|
||||
|
||||
setTaskTitle (task, title, renderer) {
|
||||
// only update the renderer title when not running in CI
|
||||
if (renderer === 'default') {
|
||||
task.title = title
|
||||
}
|
||||
},
|
||||
|
||||
isInstalledGlobally () {
|
||||
return isInstalledGlobally
|
||||
},
|
||||
|
||||
@@ -213,5 +213,22 @@ describe('install', function () {
|
||||
snapshot('warning installing as global', this.stdout.toString())
|
||||
})
|
||||
})
|
||||
|
||||
describe('when running in CI', function () {
|
||||
beforeEach(function () {
|
||||
this.sandbox.stub(util, 'isCi').returns(true)
|
||||
|
||||
info.getInstalledVersion.resolves('x.x.x')
|
||||
|
||||
return install.start()
|
||||
})
|
||||
|
||||
it('uses verbose renderer', function () {
|
||||
snapshot(
|
||||
'installing in ci',
|
||||
util.stripDates(this.stdout.toString())
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -301,5 +301,25 @@ context('.verify', function () {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when running in CI', function () {
|
||||
beforeEach(function () {
|
||||
this.sandbox.stub(util, 'isCi').returns(true)
|
||||
|
||||
return info.writeInfoFileContents({
|
||||
version: packageVersion,
|
||||
})
|
||||
.then(() => {
|
||||
return verify.start({ force: true })
|
||||
})
|
||||
})
|
||||
|
||||
it('uses verbose renderer', function () {
|
||||
snapshot(
|
||||
'verifying in ci',
|
||||
util.stripDates(this.stdout.toString())
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user