Skip to content

Commit

Permalink
feat: print bundled Node and Electron versions in cypress version (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov authored Nov 16, 2020
1 parent 470c69e commit 84d1afd
Show file tree
Hide file tree
Showing 18 changed files with 266 additions and 62 deletions.
10 changes: 9 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ macBuildFilters: &macBuildFilters
branches:
only:
- develop
- remove-old-binary-file
- include-electron-node-version

defaults: &defaults
parallelism: 1
Expand Down Expand Up @@ -308,6 +308,10 @@ commands:
working_directory: /tmp/<<parameters.repo>>
# force installing the freshly built binary
command: CYPRESS_INSTALL_BINARY=~/cypress/cypress.zip npm i ~/cypress/cypress.tgz
- run:
name: Print Cypress version
working_directory: /tmp/<<parameters.repo>>
command: npx cypress version
- run:
name: Types check 🧩 (maybe)
working_directory: /tmp/<<parameters.repo>>
Expand Down Expand Up @@ -1286,6 +1290,10 @@ jobs:
working_directory: test-binary
# force installing the freshly built binary
command: CYPRESS_INSTALL_BINARY=/root/cypress/cypress.zip npm i /root/cypress/cypress.tgz
- run:
name: Cypress version
working_directory: test-binary
command: $(yarn bin)/cypress version
- run:
name: Verify Cypress binary
working_directory: test-binary
Expand Down
2 changes: 1 addition & 1 deletion cli/NPM_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ After installing you'll be able to:

## Install

Requires Node version >= 4.0.0
Requires Node version >= 10.0.0

```sh
npm install --save-dev cypress
Expand Down
21 changes: 21 additions & 0 deletions cli/__snapshots__/cli_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,26 +359,43 @@ exports['cli CYPRESS_INTERNAL_ENV catches environment "foo" 1'] = `
exports['cli version and binary version 1'] = `
Cypress package version: 1.2.3
Cypress binary version: X.Y.Z
Electron version: not found
Bundled Node version: not found
`

exports['cli version and binary version 2'] = `
Cypress package version: 1.2.3
Cypress binary version: X.Y.Z
Electron version: not found
Bundled Node version: not found
`

exports['cli version with electron and node 1'] = `
Cypress package version: 1.2.3
Cypress binary version: X.Y.Z
Electron version: 10.10.88
Bundled Node version: 11.10.3
`

exports['cli version no binary version 1'] = `
Cypress package version: 1.2.3
Cypress binary version: not installed
Electron version: not found
Bundled Node version: not found
`

exports['cli --version no binary version 1'] = `
Cypress package version: 1.2.3
Cypress binary version: not installed
Electron version: not found
Bundled Node version: not found
`

exports['cli -v no binary version 1'] = `
Cypress package version: 1.2.3
Cypress binary version: not installed
Electron version: not found
Bundled Node version: not found
`

exports['cli cypress run warns with space-separated --spec 1'] = `
Expand Down Expand Up @@ -445,11 +462,15 @@ 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
Electron version: not found
Bundled Node version: not found
`

exports['cli version and binary version with npm log warn'] = `
Cypress package version: 1.2.3
Cypress binary version: X.Y.Z
Electron version: not found
Bundled Node version: not found
`

exports['prints explanation when no cache'] = `
Expand Down
2 changes: 2 additions & 0 deletions cli/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ function showVersions () {
.then((versions = {}) => {
logger.always('Cypress package version:', versions.package)
logger.always('Cypress binary version:', versions.binary)
logger.always('Electron version:', versions.electronVersion)
logger.always('Bundled Node version:', versions.electronNodeVersion)
process.exit(0)
})
.catch(util.logErrorExit1)
Expand Down
25 changes: 21 additions & 4 deletions cli/lib/exec/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,29 @@ const getVersions = () => {

return state.getBinaryDir()
})
.then(state.getBinaryPkgVersionAsync)
.then((binaryVersion) => {
return {
.then(state.getBinaryPkgAsync)
.then((pkg) => {
const versions = {
binary: state.getBinaryPkgVersion(pkg),
electronVersion: state.getBinaryElectronVersion(pkg),
electronNodeVersion: state.getBinaryElectronNodeVersion(pkg),
}

debug('binary versions %o', versions)

return versions
})
.then((binaryVersions) => {
const versions = {
package: util.pkgVersion(),
binary: binaryVersion || 'not installed',
binary: binaryVersions.binary || 'not installed',
electronVersion: binaryVersions.electronVersion || 'not found',
electronNodeVersion: binaryVersions.electronNodeVersion || 'not found',
}

debug('combined versions %o', versions)

return versions
})
}

Expand Down
2 changes: 1 addition & 1 deletion cli/lib/tasks/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ const start = (options = {}) => {
})
.then(() => {
return Promise.all([
state.getBinaryPkgVersionAsync(binaryDir),
state.getBinaryPkgAsync(binaryDir).then(state.getBinaryPkgVersion),
getVersionSpecifier(),
])
})
Expand Down
18 changes: 15 additions & 3 deletions cli/lib/tasks/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const _ = require('lodash')
const os = require('os')
const path = require('path')
const untildify = require('untildify')
const R = require('ramda')
const debug = require('debug')('cypress:cli')

const fs = require('../fs')
Expand Down Expand Up @@ -159,7 +160,11 @@ const getPathToExecutable = (binaryDir) => {
return path.join(binaryDir, getPlatformExecutable())
}

const getBinaryPkgVersionAsync = (binaryDir) => {
/**
* Resolves with an object read from the binary app package.json file.
* If the file does not exist resolves with null
*/
const getBinaryPkgAsync = (binaryDir) => {
const pathToPackageJson = getBinaryPkgPath(binaryDir)

debug('Reading binary package.json from:', pathToPackageJson)
Expand All @@ -171,15 +176,22 @@ const getBinaryPkgVersionAsync = (binaryDir) => {
}

return fs.readJsonAsync(pathToPackageJson)
.get('version')
})
}

const getBinaryPkgVersion = R.propOr(null, 'version')
const getBinaryElectronVersion = R.propOr(null, 'electronVersion')
const getBinaryElectronNodeVersion = R.propOr(null, 'electronNodeVersion')

module.exports = {
getPathToExecutable,
getPlatformExecutable,
getBinaryPkgVersionAsync,
// those names start to sound like Java
getBinaryElectronNodeVersion,
getBinaryElectronVersion,
getBinaryPkgVersion,
getBinaryVerifiedAsync,
getBinaryPkgAsync,
getBinaryPkgPath,
getBinaryDir,
getCacheDir,
Expand Down
5 changes: 4 additions & 1 deletion cli/lib/tasks/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,10 @@ const start = (options = {}) => {
return debug('binaryDir is ', binaryDir)
})
.then(() => {
return state.getBinaryPkgVersionAsync(binaryDir)
return state.getBinaryPkgAsync(binaryDir)
})
.then((pkg) => {
return state.getBinaryPkgVersion(pkg)
})
.then((binaryVersion) => {
if (!binaryVersion) {
Expand Down
35 changes: 27 additions & 8 deletions cli/test/lib/cli_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ describe('cli', () => {
it('reports package version', (done) => {
sinon.stub(util, 'pkgVersion').returns('1.2.3')
sinon
.stub(state, 'getBinaryPkgVersionAsync')
.stub(state, 'getBinaryPkgAsync')
.withArgs(binaryDir)
.resolves('X.Y.Z')
.resolves({
version: 'X.Y.Z',
})

this.exec('version')
process.exit.callsFake(() => {
Expand All @@ -164,7 +166,7 @@ describe('cli', () => {

it('reports package and binary message', (done) => {
sinon.stub(util, 'pkgVersion').returns('1.2.3')
sinon.stub(state, 'getBinaryPkgVersionAsync').resolves('X.Y.Z')
sinon.stub(state, 'getBinaryPkgAsync').resolves({ version: 'X.Y.Z' })

this.exec('version')
process.exit.callsFake(() => {
Expand All @@ -173,13 +175,28 @@ describe('cli', () => {
})
})

it('reports electron and node message', (done) => {
sinon.stub(util, 'pkgVersion').returns('1.2.3')
sinon.stub(state, 'getBinaryPkgAsync').resolves({
version: 'X.Y.Z',
electronVersion: '10.10.88',
electronNodeVersion: '11.10.3',
})

this.exec('version')
process.exit.callsFake(() => {
snapshot('cli version with electron and node 1', logger.print())
done()
})
})

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')
sinon.stub(state, 'getBinaryPkgAsync').resolves({ version: 'X.Y.Z' })

this.exec('version')
process.exit.callsFake(() => {
Expand All @@ -195,7 +212,9 @@ describe('cli', () => {
})

sinon.stub(util, 'pkgVersion').returns('1.2.3')
sinon.stub(state, 'getBinaryPkgVersionAsync').resolves('X.Y.Z')
sinon.stub(state, 'getBinaryPkgAsync').resolves({
version: 'X.Y.Z',
})

this.exec('version')
process.exit.callsFake(() => {
Expand All @@ -207,7 +226,7 @@ describe('cli', () => {

it('handles non-existent binary version', (done) => {
sinon.stub(util, 'pkgVersion').returns('1.2.3')
sinon.stub(state, 'getBinaryPkgVersionAsync').resolves(null)
sinon.stub(state, 'getBinaryPkgAsync').resolves(null)

this.exec('version')
process.exit.callsFake(() => {
Expand All @@ -218,7 +237,7 @@ describe('cli', () => {

it('handles non-existent binary --version', (done) => {
sinon.stub(util, 'pkgVersion').returns('1.2.3')
sinon.stub(state, 'getBinaryPkgVersionAsync').resolves(null)
sinon.stub(state, 'getBinaryPkgAsync').resolves(null)

this.exec('--version')
process.exit.callsFake(() => {
Expand All @@ -229,7 +248,7 @@ describe('cli', () => {

it('handles non-existent binary -v', (done) => {
sinon.stub(util, 'pkgVersion').returns('1.2.3')
sinon.stub(state, 'getBinaryPkgVersionAsync').resolves(null)
sinon.stub(state, 'getBinaryPkgAsync').resolves(null)

this.exec('-v')
process.exit.callsFake(() => {
Expand Down
46 changes: 40 additions & 6 deletions cli/test/lib/exec/versions_spec.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,69 @@
const { expect } = require('chai')

require('../../spec_helper')

const util = require(`${lib}/util`)
const state = require(`${lib}/tasks/state`)
const versions = require(`${lib}/exec/versions`)

describe('lib/exec/versions', function () {
const binaryDir = '/cache/1.2.3/Cypress.app'

beforeEach(function () {
sinon.stub(state, 'getBinaryDir').returns('/cache/1.2.3/Cypress.app')
sinon.stub(state, 'getBinaryPkgVersionAsync').withArgs('/cache/1.2.3/Cypress.app').resolves('1.2.3')
sinon.stub(state, 'getBinaryDir').returns(binaryDir)
sinon.stub(state, 'getBinaryPkgAsync').withArgs(binaryDir).resolves({
version: '1.2.3',
electronVersion: '10.1.2',
electronNodeVersion: '12.16.3',
})

sinon.stub(util, 'pkgVersion').returns('4.5.6')
})

describe('.getVersions', function () {
it('gets the correct binary and package version', function () {
return versions.getVersions().then(({ package, binary }) => {
expect(package).to.eql('4.5.6')
expect(binary).to.eql('1.2.3')
expect(package, 'package version').to.eql('4.5.6')
expect(binary, 'binary version').to.eql('1.2.3')
})
})

it('gets the correct Electron and bundled Node version', function () {
return versions.getVersions().then(({ electronVersion, electronNodeVersion }) => {
expect(electronVersion, 'electron version').to.eql('10.1.2')
expect(electronNodeVersion, 'node version').to.eql('12.16.3')
})
})

it('gets correct binary version if CYPRESS_RUN_BINARY', function () {
sinon.stub(state, 'parseRealPlatformBinaryFolderAsync').resolves('/my/cypress/path')
process.env.CYPRESS_RUN_BINARY = '/my/cypress/path'
state.getBinaryPkgVersionAsync
state.getBinaryPkgAsync
.withArgs('/my/cypress/path')
.resolves('7.8.9')
.resolves({
version: '7.8.9',
})

return versions.getVersions().then(({ package, binary }) => {
expect(package).to.eql('4.5.6')
expect(binary).to.eql('7.8.9')
})
})

it('reports default versions if not found', function () {
// imagine package.json only has version there
state.getBinaryPkgAsync.withArgs(binaryDir).resolves({
version: '90.9.9',
})

return versions.getVersions().then((versions) => {
expect(versions).to.deep.equal({
'package': '4.5.6',
'binary': '90.9.9',
'electronVersion': 'not found',
'electronNodeVersion': 'not found',
})
})
})
})
})
Loading

3 comments on commit 84d1afd

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 84d1afd Nov 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.0.0/circle-develop-84d1afd27d8b1328d3a3a2ae1905b7774ee8509e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 84d1afd Nov 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.0.0/appveyor-develop-84d1afd27d8b1328d3a3a2ae1905b7774ee8509e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 84d1afd Nov 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.0.0/appveyor-develop-84d1afd27d8b1328d3a3a2ae1905b7774ee8509e/cypress.tgz

Please sign in to comment.