mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-24 07:59:12 -05:00
Do not silence cli commands (#6909)
* always log cache path * cache list always logs * cypress version should always log result
This commit is contained in:
@@ -35,3 +35,23 @@ exports['lib/tasks/cache .list some versions have never been opened 1'] = `
|
||||
│ 2.3.4 │ unknown │
|
||||
└─────────┴──────────────┘
|
||||
`
|
||||
|
||||
exports['cache list with silent log level'] = `
|
||||
┌─────────┬───────────┐
|
||||
│ version │ last used │
|
||||
├─────────┼───────────┤
|
||||
│ 1.2.3 │ unknown │
|
||||
├─────────┼───────────┤
|
||||
│ 2.3.4 │ unknown │
|
||||
└─────────┴───────────┘
|
||||
`
|
||||
|
||||
exports['cache list with warn log level'] = `
|
||||
┌─────────┬───────────┐
|
||||
│ version │ last used │
|
||||
├─────────┼───────────┤
|
||||
│ 1.2.3 │ unknown │
|
||||
├─────────┼───────────┤
|
||||
│ 2.3.4 │ unknown │
|
||||
└─────────┴───────────┘
|
||||
`
|
||||
|
||||
@@ -428,3 +428,13 @@ exports['cli CYPRESS_INTERNAL_ENV allows and warns when staging environment 1']
|
||||
-------
|
||||
|
||||
`
|
||||
|
||||
exports['cli version and binary version with npm log silent'] = `
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: X.Y.Z
|
||||
`
|
||||
|
||||
exports['cli version and binary version with npm log warn'] = `
|
||||
Cypress package version: 1.2.3
|
||||
Cypress binary version: X.Y.Z
|
||||
`
|
||||
|
||||
+2
-2
@@ -154,8 +154,8 @@ function showVersions () {
|
||||
return require('./exec/versions')
|
||||
.getVersions()
|
||||
.then((versions = {}) => {
|
||||
logger.log('Cypress package version:', versions.package)
|
||||
logger.log('Cypress binary version:', versions.binary)
|
||||
logger.always('Cypress package version:', versions.package)
|
||||
logger.always('Cypress binary version:', versions.binary)
|
||||
process.exit(0)
|
||||
})
|
||||
.catch(util.logErrorExit1)
|
||||
|
||||
@@ -26,6 +26,11 @@ const log = (...messages) => {
|
||||
console.log(...messages) // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
const always = (...messages) => {
|
||||
logs.push(messages.join(' '))
|
||||
console.log(...messages) // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
// splits long text into lines and calls log()
|
||||
// on each one to allow easy unit testing for specific message
|
||||
const logLines = (text) => {
|
||||
@@ -46,6 +51,7 @@ module.exports = {
|
||||
log,
|
||||
warn,
|
||||
error,
|
||||
always,
|
||||
logLines,
|
||||
print,
|
||||
reset,
|
||||
|
||||
@@ -15,9 +15,8 @@ const colors = {
|
||||
values: chalk.green,
|
||||
}
|
||||
|
||||
// TODO: rename this function
|
||||
const path = () => {
|
||||
logger.log(state.getCacheDir())
|
||||
const logCachePath = () => {
|
||||
logger.always(state.getCacheDir())
|
||||
|
||||
return undefined
|
||||
}
|
||||
@@ -26,6 +25,10 @@ const clear = () => {
|
||||
return fs.removeAsync(state.getCacheDir())
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects all cached versions, finds when each was used
|
||||
* and prints a table with results to the terminal
|
||||
*/
|
||||
const list = () => {
|
||||
return getCachedVersions()
|
||||
.then((binaries) => {
|
||||
@@ -40,7 +43,7 @@ const list = () => {
|
||||
return table.push([versionString, lastUsed])
|
||||
})
|
||||
|
||||
logger.log(table.toString())
|
||||
logger.always(table.toString())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -84,7 +87,7 @@ const getCachedVersions = () => {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
path,
|
||||
path: logCachePath,
|
||||
clear,
|
||||
list,
|
||||
getCachedVersions,
|
||||
|
||||
@@ -13,6 +13,7 @@ const install = require(`${lib}/tasks/install`)
|
||||
const snapshot = require('../support/snapshot')
|
||||
const debug = require('debug')('test')
|
||||
const execa = require('execa-wrap')
|
||||
const mockedEnv = require('mocked-env')
|
||||
|
||||
describe('cli', () => {
|
||||
require('mocha-banner').register()
|
||||
@@ -131,6 +132,15 @@ describe('cli', () => {
|
||||
})
|
||||
|
||||
context('cypress version', () => {
|
||||
let restoreEnv
|
||||
|
||||
afterEach(() => {
|
||||
if (restoreEnv) {
|
||||
restoreEnv()
|
||||
restoreEnv = null
|
||||
}
|
||||
})
|
||||
|
||||
const binaryDir = '/binary/dir'
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -162,6 +172,38 @@ describe('cli', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('reports package and binary message with npm log silent', (done) => {
|
||||
restoreEnv = mockedEnv({
|
||||
npm_config_loglevel: 'silent',
|
||||
})
|
||||
|
||||
sinon.stub(util, 'pkgVersion').returns('1.2.3')
|
||||
sinon.stub(state, 'getBinaryPkgVersionAsync').resolves('X.Y.Z')
|
||||
|
||||
this.exec('version')
|
||||
process.exit.callsFake(() => {
|
||||
// should not be empty!
|
||||
snapshot('cli version and binary version with npm log silent', logger.print())
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('reports package and binary message with npm log warn', (done) => {
|
||||
restoreEnv = mockedEnv({
|
||||
npm_config_loglevel: 'warn',
|
||||
})
|
||||
|
||||
sinon.stub(util, 'pkgVersion').returns('1.2.3')
|
||||
sinon.stub(state, 'getBinaryPkgVersionAsync').resolves('X.Y.Z')
|
||||
|
||||
this.exec('version')
|
||||
process.exit.callsFake(() => {
|
||||
// should not be empty!
|
||||
snapshot('cli version and binary version with npm log warn', logger.print())
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('handles non-existent binary version', (done) => {
|
||||
sinon.stub(util, 'pkgVersion').returns('1.2.3')
|
||||
sinon.stub(state, 'getBinaryPkgVersionAsync').resolves(null)
|
||||
|
||||
@@ -11,6 +11,7 @@ const moment = require('moment')
|
||||
const stripAnsi = require('strip-ansi')
|
||||
const path = require('path')
|
||||
const termToHtml = require('term-to-html')
|
||||
const mockedEnv = require('mocked-env')
|
||||
|
||||
const outputHtmlFolder = path.join(__dirname, '..', '..', 'html')
|
||||
|
||||
@@ -54,10 +55,15 @@ describe('lib/tasks/cache', () => {
|
||||
mockfs.restore()
|
||||
})
|
||||
|
||||
const defaultSnapshot = () => {
|
||||
const defaultSnapshot = (snapshotName) => {
|
||||
const stdoutAsString = getSnapshotText()
|
||||
const withoutAnsi = stripAnsi(stdoutAsString)
|
||||
|
||||
snapshot(stripAnsi(stdoutAsString))
|
||||
if (snapshotName) {
|
||||
snapshot(snapshotName, withoutAnsi)
|
||||
} else {
|
||||
snapshot(withoutAnsi)
|
||||
}
|
||||
}
|
||||
|
||||
const snapshotWithHtml = async (htmlFilename) => {
|
||||
@@ -72,11 +78,38 @@ describe('lib/tasks/cache', () => {
|
||||
}
|
||||
|
||||
describe('.path', () => {
|
||||
let restoreEnv
|
||||
|
||||
afterEach(() => {
|
||||
if (restoreEnv) {
|
||||
restoreEnv()
|
||||
restoreEnv = null
|
||||
}
|
||||
})
|
||||
|
||||
it('lists path to cache', () => {
|
||||
cache.path()
|
||||
expect(this.stdout.toString()).to.eql('/.cache/Cypress\n')
|
||||
defaultSnapshot()
|
||||
})
|
||||
|
||||
it('lists path to cache with silent npm loglevel', () => {
|
||||
restoreEnv = mockedEnv({
|
||||
npm_config_loglevel: 'silent',
|
||||
})
|
||||
|
||||
cache.path()
|
||||
expect(this.stdout.toString()).to.eql('/.cache/Cypress\n')
|
||||
})
|
||||
|
||||
it('lists path to cache with silent npm warn', () => {
|
||||
restoreEnv = mockedEnv({
|
||||
npm_config_loglevel: 'warn',
|
||||
})
|
||||
|
||||
cache.path()
|
||||
expect(this.stdout.toString()).to.eql('/.cache/Cypress\n')
|
||||
})
|
||||
})
|
||||
|
||||
describe('.clear', () => {
|
||||
@@ -93,6 +126,15 @@ describe('lib/tasks/cache', () => {
|
||||
})
|
||||
|
||||
describe('.list', () => {
|
||||
let restoreEnv
|
||||
|
||||
afterEach(() => {
|
||||
if (restoreEnv) {
|
||||
restoreEnv()
|
||||
restoreEnv = null
|
||||
}
|
||||
})
|
||||
|
||||
it('lists all versions of cached binary', async function () {
|
||||
// unknown access times
|
||||
sinon.stub(state, 'getPathToExecutable').returns('/.cache/Cypress/1.2.3/app/cypress')
|
||||
@@ -102,6 +144,34 @@ describe('lib/tasks/cache', () => {
|
||||
defaultSnapshot()
|
||||
})
|
||||
|
||||
it('lists all versions of cached binary with npm log level silent', async function () {
|
||||
restoreEnv = mockedEnv({
|
||||
npm_config_loglevel: 'silent',
|
||||
})
|
||||
|
||||
// unknown access times
|
||||
sinon.stub(state, 'getPathToExecutable').returns('/.cache/Cypress/1.2.3/app/cypress')
|
||||
|
||||
await cache.list()
|
||||
|
||||
// log output snapshot should have a grid of versions
|
||||
defaultSnapshot('cache list with silent log level')
|
||||
})
|
||||
|
||||
it('lists all versions of cached binary with npm log level warn', async function () {
|
||||
restoreEnv = mockedEnv({
|
||||
npm_config_loglevel: 'warn',
|
||||
})
|
||||
|
||||
// unknown access times
|
||||
sinon.stub(state, 'getPathToExecutable').returns('/.cache/Cypress/1.2.3/app/cypress')
|
||||
|
||||
await cache.list()
|
||||
|
||||
// log output snapshot should have a grid of versions
|
||||
defaultSnapshot('cache list with warn log level')
|
||||
})
|
||||
|
||||
it('lists all versions of cached binary with last access', async function () {
|
||||
sinon.stub(state, 'getPathToExecutable').returns('/.cache/Cypress/1.2.3/app/cypress')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user