Skip to content

Commit

Permalink
fix: use app.whenReady and remove delay race for electron startup (#1…
Browse files Browse the repository at this point in the history
…5075)

Co-authored-by: Thorsten Lorenz <thlorenz@gmx.de>
  • Loading branch information
flotwig and thlorenz committed Feb 15, 2021
1 parent b4c0117 commit 10fdd7b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 132 deletions.
68 changes: 0 additions & 68 deletions packages/server/__snapshots__/spec_writer_spec.ts.js
Expand Up @@ -97,39 +97,6 @@ describe('top level suite', () => {
`

exports['lib/util/spec_writer #appendCommandsToTest can add commands to an existing test defined with it.only 1'] = `
describe('top level suite', () => {
describe('inner suite with describe', () => {
it('test with it', () => {
cy.get('.btn').click()
})
specify('test with specify', () => {
cy.get('.btn').click()
})
// eslint-disable-next-line mocha/no-exclusive-tests
it.only('test with it.only', () => {
cy.get('.btn').click()
/* ==== Generated with Cypress Studio ==== */
cy.get('.input').type('typed text');
cy.get('.btn').click();
/* ==== End Cypress Studio ==== */
})
})
context('inner suite with context', () => {
})
// eslint-disable-next-line mocha/no-exclusive-tests
describe.only('inner suite with describe.only', () => {
})
})
`

exports['lib/util/spec_writer #createNewTestInSuite can create a new test in a suite defined with describe 1'] = `
describe('top level suite', () => {
describe('inner suite with describe', () => {
Expand Down Expand Up @@ -202,41 +169,6 @@ describe('top level suite', () => {
`

exports['lib/util/spec_writer #createNewTestInSuite can create a new test in a suite defined with describe.only 1'] = `
describe('top level suite', () => {
describe('inner suite with describe', () => {
it('test with it', () => {
cy.get('.btn').click()
})
specify('test with specify', () => {
cy.get('.btn').click()
})
// eslint-disable-next-line mocha/no-exclusive-tests
it.only('test with it.only', () => {
cy.get('.btn').click()
})
})
context('inner suite with context', () => {
})
// eslint-disable-next-line mocha/no-exclusive-tests
describe.only('inner suite with describe.only', () => {
/* === Test Created with Cypress Studio === */
it('test added to describe.only', function() {
/* ==== Generated with Cypress Studio ==== */
cy.get('.input').type('typed text');
cy.get('.btn').click();
/* ==== End Cypress Studio ==== */
});
})
})
`

exports['lib/util/spec_writer #appendCommandsToTest can add commands to an existing test defined with it only 1'] = `
describe('top level suite', () => {
describe('inner suite with describe', () => {
Expand Down
20 changes: 3 additions & 17 deletions packages/server/lib/modes/interactive-e2e.js
Expand Up @@ -3,9 +3,7 @@ const os = require('os')
const EE = require('events')
const { app } = require('electron')
const image = require('electron').nativeImage
const Promise = require('bluebird')
const cyIcons = require('@cypress/icons')
const electronApp = require('../util/electron-app')
const savedState = require('../saved_state')
const menu = require('../gui/menu')
const Events = require('../gui/events')
Expand Down Expand Up @@ -112,21 +110,9 @@ module.exports = {
})
},

run (options) {
const waitForReady = () => {
return new Promise((resolve, reject) => {
return app.on('ready', resolve)
})
}
async run (options) {
await app.whenReady()

electronApp.allowRendererProcessReuse()

return Promise.any([
waitForReady(),
Promise.delay(500),
])
.then(() => {
return this.ready(options)
})
return this.ready(options)
},
}
17 changes: 11 additions & 6 deletions packages/server/lib/modes/run.js
@@ -1,5 +1,6 @@
/* eslint-disable no-console, @cypress/dev/arrow-body-multiline-braces */
const _ = require('lodash')
const { app } = require('electron')
const la = require('lazy-ass')
const pkg = require('@packages/root')
const path = require('path')
Expand Down Expand Up @@ -27,7 +28,6 @@ const newlines = require('../util/newlines')
const terminal = require('../util/terminal')
const specsUtil = require('../util/specs')
const humanTime = require('../util/human_time')
const electronApp = require('../util/electron-app')
const settings = require('../util/settings')
const chromePolicyCheck = require('../util/chrome_policy_check')
const experiments = require('../experiments')
Expand Down Expand Up @@ -1557,11 +1557,16 @@ module.exports = {
})
},

run (options) {
return electronApp
.waitForReady()
.then(() => {
return this.ready(options)
async run (options) {
// electron >= 5.0.0 will exit the app if all browserwindows are closed,
// this is obviously undesirable in run mode
// https://github.com/cypress-io/cypress/pull/4720#issuecomment-514316695
app.on('window-all-closed', () => {
debug('all BrowserWindows closed, not exiting')
})

await app.whenReady()

return this.ready(options)
},
}
40 changes: 0 additions & 40 deletions packages/server/lib/util/electron-app.js
Expand Up @@ -8,53 +8,13 @@ const scale = () => {
}
}

const allowRendererProcessReuse = () => {
const { app } = require('electron')

// @see https://github.com/electron/electron/issues/18397
// NOTE: in Electron 9, this can be removed, since it will be the new default
app.allowRendererProcessReuse = true
}

// NOTE: this function is only called in run mode
const waitForReady = () => {
const debug = require('debug')('cypress:server:electron-app')

const Promise = require('bluebird')
const { app } = require('electron')

allowRendererProcessReuse()

// electron >= 5.0.0 will exit the app if all browserwindows are closed,
// this is obviously undesirable in run mode
// https://github.com/cypress-io/cypress/pull/4720#issuecomment-514316695
app.on('window-all-closed', () => {
debug('all BrowserWindows closed, not exiting')
})

const onReadyEvent = () => {
return new Promise((resolve) => {
app.on('ready', resolve)
})
}

return Promise.any([
onReadyEvent(),
Promise.delay(500),
])
}

const isRunning = () => {
// are we in the electron or the node process?
return Boolean(process.versions && process.versions.electron)
}

module.exports = {
allowRendererProcessReuse,

scale,

waitForReady,

isRunning,
}
1 change: 1 addition & 0 deletions packages/server/test/support/helpers/electron_stub.js
Expand Up @@ -20,6 +20,7 @@ module.exports = {
appendArgument () {},
},
disableHardwareAcceleration () {},
async whenReady () {},
},
systemPreferences: {
isDarkMode () {},
Expand Down
2 changes: 1 addition & 1 deletion packages/server/test/unit/modes/interactive_spec.js
Expand Up @@ -167,7 +167,7 @@ describe('gui/interactive', () => {

context('.run', () => {
beforeEach(() => {
sinon.stub(electron.app, 'on').withArgs('ready').yieldsAsync()
sinon.stub(electron.app, 'whenReady').resolves()
})

it('calls ready with options', () => {
Expand Down

4 comments on commit 10fdd7b

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 10fdd7b Feb 15, 2021

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.5.0/circle-develop-10fdd7b9f837f65fdf2f06418a42d9d2b2b40f6d/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 10fdd7b Feb 15, 2021

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.5.0/appveyor-develop-10fdd7b9f837f65fdf2f06418a42d9d2b2b40f6d/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 10fdd7b Feb 15, 2021

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.5.0/appveyor-develop-10fdd7b9f837f65fdf2f06418a42d9d2b2b40f6d/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 10fdd7b Feb 15, 2021

Choose a reason for hiding this comment

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

Circle has built the darwin 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.5.0/circle-develop-10fdd7b9f837f65fdf2f06418a42d9d2b2b40f6d/cypress.tgz

Please sign in to comment.