mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-04 14:00:22 -05:00
Verify command 545 (#550)
* find single line with ping value, close #545 * linting
This commit is contained in:
@@ -138,3 +138,12 @@ It looks like this is your first time using Cypress: 1.2.3
|
||||
Opening Cypress...
|
||||
|
||||
`
|
||||
|
||||
exports['verbose stdout output 1'] = `
|
||||
It looks like this is your first time using Cypress: 1.2.3
|
||||
|
||||
✔ Verified Cypress! /path/to/executable/dir
|
||||
|
||||
Opening Cypress...
|
||||
|
||||
`
|
||||
|
||||
@@ -84,7 +84,8 @@ const runSmokeTest = () => {
|
||||
if (code === 0) {
|
||||
const smokeTestReturned = stdout.trim()
|
||||
debug('smoke test output "%s"', smokeTestReturned)
|
||||
if (smokeTestReturned !== String(random)) {
|
||||
|
||||
if (!util.stdoutLineMatches(String(random), smokeTestReturned)) {
|
||||
return reject(new Error(stripIndent`
|
||||
Smoke test returned wrong code.
|
||||
|
||||
|
||||
@@ -24,6 +24,12 @@ function normalizeModuleOptions (options = {}) {
|
||||
})(options)
|
||||
}
|
||||
|
||||
function stdoutLineMatches (expectedLine, stdout) {
|
||||
const lines = stdout.split('\n').map(R.trim)
|
||||
const lineMatches = R.equals(expectedLine)
|
||||
return lines.some(lineMatches)
|
||||
}
|
||||
|
||||
const util = {
|
||||
normalizeModuleOptions,
|
||||
|
||||
@@ -89,6 +95,8 @@ const util = {
|
||||
isInstalledGlobally () {
|
||||
return isInstalledGlobally
|
||||
},
|
||||
|
||||
stdoutLineMatches,
|
||||
}
|
||||
|
||||
module.exports = util
|
||||
|
||||
@@ -6,6 +6,7 @@ const cp = require('child_process')
|
||||
const EE = require('events').EventEmitter
|
||||
const Promise = require('bluebird')
|
||||
const snapshot = require('snap-shot-it')
|
||||
const { stripIndent } = require('common-tags')
|
||||
|
||||
const fs = require(`${lib}/fs`)
|
||||
const util = require(`${lib}/util`)
|
||||
@@ -228,6 +229,44 @@ context('.verify', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('smoke test with DEBUG output', function () {
|
||||
beforeEach(function () {
|
||||
this.sandbox.stub(fs, 'statAsync').resolves()
|
||||
this.sandbox.stub(_, 'random').returns('222')
|
||||
const stdoutWithDebugOutput = stripIndent`
|
||||
some debug output
|
||||
date: more debug output
|
||||
222
|
||||
after that more text
|
||||
`
|
||||
this.sandbox.stub(this.cpstdout, 'on').yieldsAsync(stdoutWithDebugOutput)
|
||||
})
|
||||
|
||||
it('finds ping value in the verbose output', function () {
|
||||
const ctx = this
|
||||
|
||||
return info.writeInfoFileContents({
|
||||
version: packageVersion,
|
||||
})
|
||||
.then(() => {
|
||||
return verify.start()
|
||||
})
|
||||
.then(() => {
|
||||
return info.getVerifiedVersion()
|
||||
})
|
||||
.then((vv) => {
|
||||
expect(vv).to.eq(packageVersion)
|
||||
})
|
||||
.delay(LISTR_DELAY)
|
||||
.then(() => {
|
||||
snapshot(
|
||||
'verbose stdout output',
|
||||
normalize(ctx.stdout.toString())
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('smoke test', function () {
|
||||
beforeEach(function () {
|
||||
this.sandbox.stub(fs, 'statAsync').resolves()
|
||||
|
||||
@@ -10,6 +10,37 @@ describe('util', function () {
|
||||
this.sandbox.stub(logger, 'error')
|
||||
})
|
||||
|
||||
context('stdoutLineMatches', () => {
|
||||
const { stdoutLineMatches } = util
|
||||
|
||||
it('is a function', () => {
|
||||
expect(stdoutLineMatches).to.be.a.function
|
||||
})
|
||||
|
||||
it('matches entire output', () => {
|
||||
const line = '444'
|
||||
expect(stdoutLineMatches(line, line)).to.be.true
|
||||
})
|
||||
|
||||
it('matches a line in output', () => {
|
||||
const line = '444'
|
||||
const stdout = ['start', line, 'something else'].join('\n')
|
||||
expect(stdoutLineMatches(line, stdout)).to.be.true
|
||||
})
|
||||
|
||||
it('matches a trimmed line in output', () => {
|
||||
const line = '444'
|
||||
const stdout = ['start', ` ${line} `, 'something else'].join('\n')
|
||||
expect(stdoutLineMatches(line, stdout)).to.be.true
|
||||
})
|
||||
|
||||
it('does not find match', () => {
|
||||
const line = '445'
|
||||
const stdout = ['start', '444', 'something else'].join('\n')
|
||||
expect(stdoutLineMatches(line, stdout)).to.be.false
|
||||
})
|
||||
})
|
||||
|
||||
context('normalizeModuleOptions', () => {
|
||||
const { normalizeModuleOptions } = util
|
||||
|
||||
|
||||
Reference in New Issue
Block a user