From 84d1afd27d8b1328d3a3a2ae1905b7774ee8509e Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Mon, 16 Nov 2020 13:17:24 -0500 Subject: [PATCH] feat: print bundled Node and Electron versions in `cypress version` (#9183) --- circle.yml | 10 ++++- cli/NPM_README.md | 2 +- cli/__snapshots__/cli_spec.js | 21 ++++++++++ cli/lib/cli.js | 2 + cli/lib/exec/versions.js | 25 +++++++++-- cli/lib/tasks/install.js | 2 +- cli/lib/tasks/state.js | 18 ++++++-- cli/lib/tasks/verify.js | 5 ++- cli/test/lib/cli_spec.js | 35 ++++++++++++---- cli/test/lib/exec/versions_spec.js | 46 ++++++++++++++++++--- cli/test/lib/tasks/install_spec.js | 26 ++++++------ cli/test/lib/tasks/state_spec.js | 31 +++++++++----- package.json | 1 + packages/electron/lib/electron.js | 41 +++++++++++++++++- packages/electron/lib/print-node-version.js | 3 ++ packages/electron/package.json | 1 + scripts/binary/build.js | 44 ++++++++++++++------ yarn.lock | 15 +++++++ 18 files changed, 266 insertions(+), 62 deletions(-) create mode 100644 packages/electron/lib/print-node-version.js diff --git a/circle.yml b/circle.yml index c0b0aa96c952..3986ae437c35 100644 --- a/circle.yml +++ b/circle.yml @@ -8,7 +8,7 @@ macBuildFilters: &macBuildFilters branches: only: - develop - - remove-old-binary-file + - include-electron-node-version defaults: &defaults parallelism: 1 @@ -308,6 +308,10 @@ commands: working_directory: /tmp/<> # 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/<> + command: npx cypress version - run: name: Types check 🧩 (maybe) working_directory: /tmp/<> @@ -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 diff --git a/cli/NPM_README.md b/cli/NPM_README.md index 42e17c5a55be..9e489a6d64dd 100644 --- a/cli/NPM_README.md +++ b/cli/NPM_README.md @@ -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 diff --git a/cli/__snapshots__/cli_spec.js b/cli/__snapshots__/cli_spec.js index e736e998a92b..c5bdf0d423d5 100644 --- a/cli/__snapshots__/cli_spec.js +++ b/cli/__snapshots__/cli_spec.js @@ -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'] = ` @@ -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'] = ` diff --git a/cli/lib/cli.js b/cli/lib/cli.js index c0f22b296c39..db87059c8a10 100644 --- a/cli/lib/cli.js +++ b/cli/lib/cli.js @@ -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) diff --git a/cli/lib/exec/versions.js b/cli/lib/exec/versions.js index bb3589ef7494..94fd9f1b9915 100644 --- a/cli/lib/exec/versions.js +++ b/cli/lib/exec/versions.js @@ -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 }) } diff --git a/cli/lib/tasks/install.js b/cli/lib/tasks/install.js index 366e4b69fbf0..076ffd55c101 100644 --- a/cli/lib/tasks/install.js +++ b/cli/lib/tasks/install.js @@ -290,7 +290,7 @@ const start = (options = {}) => { }) .then(() => { return Promise.all([ - state.getBinaryPkgVersionAsync(binaryDir), + state.getBinaryPkgAsync(binaryDir).then(state.getBinaryPkgVersion), getVersionSpecifier(), ]) }) diff --git a/cli/lib/tasks/state.js b/cli/lib/tasks/state.js index 9023df2b3bd6..6f92a752f760 100644 --- a/cli/lib/tasks/state.js +++ b/cli/lib/tasks/state.js @@ -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') @@ -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) @@ -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, diff --git a/cli/lib/tasks/verify.js b/cli/lib/tasks/verify.js index f12ff88d46e7..3e3966d579bf 100644 --- a/cli/lib/tasks/verify.js +++ b/cli/lib/tasks/verify.js @@ -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) { diff --git a/cli/test/lib/cli_spec.js b/cli/test/lib/cli_spec.js index 6b48d7e95a7b..4b5127c2ca19 100644 --- a/cli/test/lib/cli_spec.js +++ b/cli/test/lib/cli_spec.js @@ -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(() => { @@ -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(() => { @@ -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(() => { @@ -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(() => { @@ -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(() => { @@ -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(() => { @@ -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(() => { diff --git a/cli/test/lib/exec/versions_spec.js b/cli/test/lib/exec/versions_spec.js index 53f4b7897235..7a9124ddfb41 100644 --- a/cli/test/lib/exec/versions_spec.js +++ b/cli/test/lib/exec/versions_spec.js @@ -1,3 +1,5 @@ +const { expect } = require('chai') + require('../../spec_helper') const util = require(`${lib}/util`) @@ -5,31 +7,63 @@ 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', + }) + }) + }) }) }) diff --git a/cli/test/lib/tasks/install_spec.js b/cli/test/lib/tasks/install_spec.js index 34714aeb3564..ee909330d870 100644 --- a/cli/test/lib/tasks/install_spec.js +++ b/cli/test/lib/tasks/install_spec.js @@ -55,7 +55,7 @@ describe('/lib/tasks/install', function () { sinon.stub(fs, 'removeAsync').resolves() sinon.stub(state, 'getVersionDir').returns('/cache/Cypress/1.2.3') sinon.stub(state, 'getBinaryDir').returns('/cache/Cypress/1.2.3/Cypress.app') - sinon.stub(state, 'getBinaryPkgVersionAsync').resolves() + sinon.stub(state, 'getBinaryPkgAsync').resolves() sinon.stub(fs, 'ensureDirAsync').resolves(undefined) os.platform.returns('darwin') }) @@ -181,14 +181,14 @@ describe('/lib/tasks/install', function () { describe('when version is already installed', function () { beforeEach(function () { - state.getBinaryPkgVersionAsync.resolves(packageVersion) + state.getBinaryPkgAsync.resolves({ version: packageVersion }) }) it('doesn\'t attempt to download', function () { return install.start() .then(() => { expect(download.start).not.to.be.called - expect(state.getBinaryPkgVersionAsync).to.be.calledWith('/cache/Cypress/1.2.3/Cypress.app') + expect(state.getBinaryPkgAsync).to.be.calledWith('/cache/Cypress/1.2.3/Cypress.app') }) }) @@ -217,7 +217,7 @@ describe('/lib/tasks/install', function () { describe('when getting installed version fails', function () { beforeEach(function () { - state.getBinaryPkgVersionAsync.resolves(null) + state.getBinaryPkgAsync.resolves(null) return install.start() }) @@ -240,7 +240,7 @@ describe('/lib/tasks/install', function () { describe('when there is no install version', function () { beforeEach(function () { - state.getBinaryPkgVersionAsync.resolves(null) + state.getBinaryPkgAsync.resolves(null) return install.start() }) @@ -268,7 +268,7 @@ describe('/lib/tasks/install', function () { describe('when getting installed version does not match needed version', function () { beforeEach(function () { - state.getBinaryPkgVersionAsync.resolves('x.x.x') + state.getBinaryPkgAsync.resolves({ version: 'x.x.x' }) return install.start() }) @@ -291,7 +291,7 @@ describe('/lib/tasks/install', function () { describe('with force: true', function () { beforeEach(function () { - state.getBinaryPkgVersionAsync.resolves(packageVersion) + state.getBinaryPkgAsync.resolves({ version: packageVersion }) return install.start({ force: true }) }) @@ -316,7 +316,7 @@ describe('/lib/tasks/install', function () { beforeEach(function () { sinon.stub(util, 'isInstalledGlobally').returns(true) - state.getBinaryPkgVersionAsync.resolves('x.x.x') + state.getBinaryPkgAsync.resolves({ version: 'x.x.x' }) return install.start() }) @@ -341,7 +341,7 @@ describe('/lib/tasks/install', function () { beforeEach(function () { util.isCi.returns(true) - state.getBinaryPkgVersionAsync.resolves('x.x.x') + state.getBinaryPkgAsync.resolves({ version: 'x.x.x' }) return install.start() }) @@ -381,7 +381,7 @@ describe('/lib/tasks/install', function () { describe('CYPRESS_INSTALL_BINARY is URL or Zip', function () { it('uses cache when correct version installed given URL', function () { - state.getBinaryPkgVersionAsync.resolves('1.2.3') + state.getBinaryPkgAsync.resolves({ version: '1.2.3' }) util.pkgVersion.returns('1.2.3') process.env.CYPRESS_INSTALL_BINARY = 'www.cypress.io/cannot-download/2.4.5' @@ -392,7 +392,7 @@ describe('/lib/tasks/install', function () { }) it('uses cache when mismatch version given URL ', function () { - state.getBinaryPkgVersionAsync.resolves('1.2.3') + state.getBinaryPkgAsync.resolves({ version: '1.2.3' }) util.pkgVersion.returns('4.0.0') process.env.CYPRESS_INSTALL_BINARY = 'www.cypress.io/cannot-download/2.4.5' @@ -405,7 +405,7 @@ describe('/lib/tasks/install', function () { it('uses cache when correct version installed given Zip', function () { sinon.stub(fs, 'pathExistsAsync').withArgs('/path/to/zip.zip').resolves(true) - state.getBinaryPkgVersionAsync.resolves('1.2.3') + state.getBinaryPkgAsync.resolves({ version: '1.2.3' }) util.pkgVersion.returns('1.2.3') process.env.CYPRESS_INSTALL_BINARY = '/path/to/zip.zip' @@ -419,7 +419,7 @@ describe('/lib/tasks/install', function () { it('uses cache when mismatch version given Zip ', function () { sinon.stub(fs, 'pathExistsAsync').withArgs('/path/to/zip.zip').resolves(true) - state.getBinaryPkgVersionAsync.resolves('1.2.3') + state.getBinaryPkgAsync.resolves({ version: '1.2.3' }) util.pkgVersion.returns('4.0.0') process.env.CYPRESS_INSTALL_BINARY = '/path/to/zip.zip' diff --git a/cli/test/lib/tasks/state_spec.js b/cli/test/lib/tasks/state_spec.js index d4befad2791c..9ae16bbf16d7 100644 --- a/cli/test/lib/tasks/state_spec.js +++ b/cli/test/lib/tasks/state_spec.js @@ -5,6 +5,7 @@ const path = require('path') const Promise = require('bluebird') const proxyquire = require('proxyquire') const mockfs = require('mock-fs') +const { expect } = require('chai') const debug = require('debug')('test') const fs = require(`${lib}/fs`) @@ -32,8 +33,18 @@ describe('lib/tasks/state', function () { os.platform.returns('darwin') }) - context('.getBinaryPkgVersionAsync', function () { - it('resolves version from version file when it exists', function () { + context('.getBinaryPkgVersion', function () { + it('returns version if present', () => { + expect(state.getBinaryPkgVersion({ version: '1.2.3' })).to.equal('1.2.3') + }) + + it('returns null if passed null', () => { + expect(state.getBinaryPkgVersion(null)).to.equal(null) + }) + }) + + context('.getBinaryPkgAsync', function () { + it('resolves with loaded file when the file exists', function () { sinon .stub(fs, 'pathExistsAsync') .withArgs(binaryPkgPath) @@ -44,8 +55,8 @@ describe('lib/tasks/state', function () { .withArgs(binaryPkgPath) .resolves({ version: '2.0.48' }) - return state.getBinaryPkgVersionAsync(binaryDir).then((binaryVersion) => { - expect(binaryVersion).to.equal('2.0.48') + return state.getBinaryPkgAsync(binaryDir).then((result) => { + expect(result).to.deep.equal({ version: '2.0.48' }) }) }) @@ -53,9 +64,9 @@ describe('lib/tasks/state', function () { sinon.stub(fs, 'pathExistsAsync').resolves(false) return state - .getBinaryPkgVersionAsync(binaryDir) - .then((binaryVersion) => { - return expect(binaryVersion).to.equal(null) + .getBinaryPkgAsync(binaryDir) + .then((result) => { + return expect(result).to.equal(null) }) }) @@ -75,9 +86,9 @@ describe('lib/tasks/state', function () { .resolves({ version: '3.4.5' }) return state - .getBinaryPkgVersionAsync(customBinaryDir) - .then((binaryVersion) => { - return expect(binaryVersion).to.equal('3.4.5') + .getBinaryPkgAsync(customBinaryDir) + .then((result) => { + return expect(result).to.deep.equal({ version: '3.4.5' }) }) }) }) diff --git a/package.json b/package.json index f1573892eeec..c983e8d7c381 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "check-terminal": "node scripts/check-terminal.js", "clean": "lerna run clean --parallel", "clean-deps": "find . -depth -name node_modules -type d -exec rm -rf {} \\;", + "clean-untracked-files": "git clean -d -f", "precypress:open": "yarn ensure-deps", "cypress:open": "node $(yarn bin cypress) open --dev --global", "precypress:open:debug": "yarn ensure-deps", diff --git a/packages/electron/lib/electron.js b/packages/electron/lib/electron.js index d84ca4d6daf5..a8dec77a485a 100644 --- a/packages/electron/lib/electron.js +++ b/packages/electron/lib/electron.js @@ -5,12 +5,20 @@ const debug = require('debug')('cypress:electron') const Promise = require('bluebird') const minimist = require('minimist') const inspector = require('inspector') +const execa = require('execa') const paths = require('./paths') const install = require('./install') let fs = require('fs-extra') fs = Promise.promisifyAll(fs) +/** + * If running as root on Linux, no-sandbox must be passed or Chrome will not start + */ +const isSandboxNeeded = () => { + return (os.platform() === 'linux') && (process.geteuid() === 0) +} + module.exports = { installIfNeeded () { return install.check() @@ -26,6 +34,36 @@ module.exports = { return install.getElectronVersion() }, + /** + * Returns the Node version bundled inside Electron. + */ + getElectronNodeVersion () { + debug('getting Electron Node version') + + const args = [] + + if (isSandboxNeeded()) { + args.push('--no-sandbox') + } + + // runs locally installed "electron" bin alias + const localScript = path.join(__dirname, 'print-node-version.js') + + debug('local script that prints Node version %s', localScript) + + args.push(localScript) + + const options = { + preferLocal: true, // finds the "node_modules/.bin/electron" + timeout: 5000, // prevents hanging Electron if there is an error for some reason + } + + debug('Running Electron with %o %o', args, options) + + return execa('electron', args, options) + .then((result) => result.stdout) + }, + icons () { return install.icons() }, @@ -73,8 +111,7 @@ module.exports = { }).then(() => { const execPath = paths.getPathToExec() - // if running as root, no-sandbox must be passed or Chrome will not start - if ((os.platform() === 'linux') && (process.geteuid() === 0)) { + if (isSandboxNeeded()) { argv.unshift('--no-sandbox') } diff --git a/packages/electron/lib/print-node-version.js b/packages/electron/lib/print-node-version.js new file mode 100644 index 000000000000..2f29a8999538 --- /dev/null +++ b/packages/electron/lib/print-node-version.js @@ -0,0 +1,3 @@ +/* eslint-disable-next-line no-console */ +console.log(process.version.replace('v', '')) +process.exit(0) diff --git a/packages/electron/package.json b/packages/electron/package.json index 822396bbafba..44ffad00af7c 100644 --- a/packages/electron/package.json +++ b/packages/electron/package.json @@ -25,6 +25,7 @@ }, "devDependencies": { "electron": "10.1.5", + "execa": "4.1.0", "mocha": "3.5.3" }, "files": [ diff --git a/scripts/binary/build.js b/scripts/binary/build.js index 3adebf23f039..aebfc5508bdd 100644 --- a/scripts/binary/build.js +++ b/scripts/binary/build.js @@ -147,25 +147,45 @@ const buildCypressApp = function (platform, version, options = {}) { return packages.npmInstallAll(pathToPackages) } + /** + * Creates the package.json file that sits in the root of the output app + */ const createRootPackage = function () { log(`#createRootPackage ${platform} ${version}`) - return fs.outputJsonAsync(distDir('package.json'), { - name: 'cypress', - productName: 'Cypress', - description: rootPackage.description, - version, - main: 'index.js', - scripts: {}, - env: 'production', - }) - .then(() => { - const str = `\ + const electronVersion = electron.getElectronVersion() + + la(electronVersion, 'missing Electron version', electronVersion) + + return electron.getElectronNodeVersion() + .then((electronNodeVersion) => { + la(electronNodeVersion, 'missing Electron Node version', electronNodeVersion) + + const json = { + name: 'cypress', + productName: 'Cypress', + description: rootPackage.description, + version, // Cypress version + electronVersion, + electronNodeVersion, + main: 'index.js', + scripts: {}, + env: 'production', + } + + const outputFilename = distDir('package.json') + + debug('writing to %s json %o', outputFilename, json) + + return fs.outputJsonAsync(outputFilename, json) + .then(() => { + const str = `\ process.env.CYPRESS_INTERNAL_ENV = process.env.CYPRESS_INTERNAL_ENV || 'production' require('./packages/server')\ ` - return fs.outputFileAsync(distDir('index.js'), str) + return fs.outputFileAsync(distDir('index.js'), str) + }) }) } diff --git a/yarn.lock b/yarn.lock index 3c66b1a69391..645c760ce1aa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14096,6 +14096,21 @@ execa@4.0.2: signal-exit "^3.0.2" strip-final-newline "^2.0.0" +execa@4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/execa/-/execa-4.1.0.tgz#4e5491ad1572f2f17a77d388c6c857135b22847a" + integrity sha512-j5W0//W7f8UxAn8hXVnwG8tLwdiUy4FJLcSupCg6maBYZDpyBvTApK7KyuI4bKj8KOh1r2YH+6ucuYtJv1bTZA== + dependencies: + cross-spawn "^7.0.0" + get-stream "^5.0.0" + human-signals "^1.1.1" + is-stream "^2.0.0" + merge-stream "^2.0.0" + npm-run-path "^4.0.0" + onetime "^5.1.0" + signal-exit "^3.0.2" + strip-final-newline "^2.0.0" + execa@^0.2.2: version "0.2.2" resolved "https://registry.yarnpkg.com/execa/-/execa-0.2.2.tgz#e2ead472c2c31aad6f73f1ac956eef45e12320cb"