Skip to content

Commit ad50062

Browse files
jhnnsflotwig
andauthored
fix: Wait for child process to be ready (#19792)
Co-authored-by: Zach Bloomquist <[email protected]> Co-authored-by: Zach Bloomquist <[email protected]>
1 parent 0d3e645 commit ad50062

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

packages/server/lib/plugins/child/run_plugins.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ const runPlugins = (ipc, pluginsFile, projectRoot) => {
212212
ipc.on('execute', (event, ids, args) => {
213213
execute(ipc, event, ids, args)
214214
})
215+
216+
ipc.send('ready')
215217
}
216218

217219
// for testing purposes

packages/server/lib/plugins/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ const init = (config, options) => {
139139
Object.keys(config).sort().forEach((key) => orderedConfig[key] = config[key])
140140
config = orderedConfig
141141

142-
ipc.send('load', config)
142+
ipc.on('ready', () => {
143+
ipc.send('load', config)
144+
})
143145

144146
ipc.on('loaded', (newCfg, registrations) => {
145147
_.omit(config, 'projectRoot', 'configFile')

packages/server/test/unit/plugins/index_spec.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,19 @@ describe('lib/plugins/index', () => {
115115
})
116116
})
117117

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

122-
return plugins.init(config, getOptions({ testingType: 'e2e' })).then(() => {
123-
expect(ipc.send).to.be.calledWith('load', {
124-
...config,
125-
...configExtras,
126-
})
121+
plugins.init(config, getOptions({ testingType: 'e2e' }))
122+
123+
expect(ipc.send).to.not.be.called
124+
125+
// simulate async ready event
126+
ipc.on.withArgs('ready').firstCall.callback()
127+
128+
expect(ipc.send).to.be.calledWith('load', {
129+
...config,
130+
...configExtras,
127131
})
128132
})
129133

0 commit comments

Comments
 (0)