cli: when running in CI, use a different renderer to prevent ugly stream of stdout updates

This commit is contained in:
Brian Mann
2017-09-04 16:24:41 -04:00
parent 76bb95d5fa
commit 335553f94b
7 changed files with 116 additions and 13 deletions
+16
View File
@@ -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[xx:xx:xx] Downloading Cypress [started]
[xx:xx:xx] Downloading Cypress [completed]
[xx:xx:xx] Unzipping Cypress [started]
[xx:xx:xx] Unzipping Cypress [completed]
[xx:xx:xx] Finishing Installation [started]
[xx:xx:xx] Finishing Installation [completed]
[?25h
You can now open Cypress by running: node_modules/.bin/cypress open
https://on.cypress.io/installing-cypress
`
+5
View File
@@ -87,3 +87,8 @@ exports['current version has not been verified 1'] = `It looks like this is
[?25l ✔  Verified Cypress! /path/to/executable/dir
[?25h`
exports['verifying in ci 1'] = `It looks like this is your first time using Cypress: 1.2.3
[?25l[xx:xx:xx]  Verifying Cypress can run /path/to/executable/dir [started]
[xx:xx:xx]  Verifying Cypress can run /path/to/executable/dir [completed]
[?25h`
+24 -9
View File
@@ -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
View File
@@ -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()
}
+18
View File
@@ -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
},
+17
View File
@@ -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())
)
})
})
})
})
+20
View File
@@ -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())
)
})
})
})
})