Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Wait for child process to be ready #19792

Merged
merged 8 commits into from
Feb 17, 2022
2 changes: 2 additions & 0 deletions packages/server/lib/plugins/child/run_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ const runPlugins = (ipc, pluginsFile, projectRoot) => {
ipc.on('execute', (event, ids, args) => {
execute(ipc, event, ids, args)
})

ipc.send('ready')
}

// for testing purposes
Expand Down
4 changes: 3 additions & 1 deletion packages/server/lib/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ const init = (config, options) => {
Object.keys(config).sort().forEach((key) => orderedConfig[key] = config[key])
config = orderedConfig

ipc.send('load', config)
ipc.on('ready', () => {
ipc.send('load', config)
})

ipc.on('loaded', (newCfg, registrations) => {
_.omit(config, 'projectRoot', 'configFile')
Expand Down
18 changes: 11 additions & 7 deletions packages/server/test/unit/plugins/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,19 @@ describe('lib/plugins/index', () => {
})
})

it('sends \'load\' event with config via ipc', () => {
ipc.on.withArgs('loaded').yields([])
it('sends \'load\' event with config via ipc once it receives \'ready\'', () => {
const config = { pluginsFile: 'cypress-plugin', testingType: 'e2e' }

return plugins.init(config, getOptions({ testingType: 'e2e' })).then(() => {
expect(ipc.send).to.be.calledWith('load', {
...config,
...configExtras,
})
plugins.init(config, getOptions({ testingType: 'e2e' }))

expect(ipc.send).to.not.be.called

// simulate async ready event
ipc.on.withArgs('ready').firstCall.callback()

expect(ipc.send).to.be.calledWith('load', {
...config,
...configExtras,
})
})

Expand Down