diff --git a/packages/desktop-gui/src/lib/ipc.js b/packages/desktop-gui/src/lib/ipc.js index 6194e6e5076c..828a4d8f3775 100644 --- a/packages/desktop-gui/src/lib/ipc.js +++ b/packages/desktop-gui/src/lib/ipc.js @@ -52,6 +52,7 @@ register('open:finder') register('open:project', false) register('on:config:changed', false) register('on:spec:changed', false) +register('on:plugins:changed', false) register('on:project:error', false) register('on:project:warning', false) register('ping:api:server') diff --git a/packages/desktop-gui/src/projects/projects-api.js b/packages/desktop-gui/src/projects/projects-api.js index b5bd22847f53..abdecf1e31ac 100644 --- a/packages/desktop-gui/src/projects/projects-api.js +++ b/packages/desktop-gui/src/projects/projects-api.js @@ -155,8 +155,22 @@ const openProject = (project) => { specsStore.setChosenSpecByRelativePath(relativeSpecPath) }) - ipc.onConfigChanged(() => { - reopenProject(project) + ipc.onConfigChanged((filename) => { + // TODO decide if making this "fake" error is reasonable + project.setWarning({ + isCypressErr: true, + type: 'CONFIGURATION_CHANGED', + message: `This file was changed: \`${filename}\`\nPlease restart Cypress for changes to take effect.`, + }) + }) + + ipc.onPluginsChanged((filename) => { + // TODO decide if making this "fake" error is reasonable + project.setWarning({ + isCypressErr: true, + type: 'CONFIGURATION_CHANGED', + message: `This file was changed: \`${filename}\`\nPlease restart Cypress for changes to take effect.`, + }) }) ipc.onProjectError((__, error) => { diff --git a/packages/server/lib/gui/events.coffee b/packages/server/lib/gui/events.coffee index 314dda806dfe..0916b005e343 100644 --- a/packages/server/lib/gui/events.coffee +++ b/packages/server/lib/gui/events.coffee @@ -54,6 +54,9 @@ handleEvent = (options, bus, event, id, type, arg) -> when "on:config:changed" onBus("config:changed") + when "on:plugins:changed" + onBus("plugins:changed") + when "on:project:error" onBus("project:error") @@ -183,8 +186,13 @@ handleEvent = (options, bus, event, id, type, arg) -> when "open:project" onSettingsChanged = -> + ## add filename here bus.emit("config:changed") + onPluginsChanged = -> + ## add filename here + bus.emit("plugins:changed") + onSpecChanged = (spec) -> bus.emit("spec:changed", spec) @@ -203,6 +211,7 @@ handleEvent = (options, bus, event, id, type, arg) -> onFocusTests: onFocusTests onSpecChanged: onSpecChanged onSettingsChanged: onSettingsChanged + onPluginsChanged: onPluginsChanged onError: onError onWarning: onWarning }) diff --git a/packages/server/lib/project.coffee b/packages/server/lib/project.coffee index b062a0776bc1..5e27c7853a76 100644 --- a/packages/server/lib/project.coffee +++ b/packages/server/lib/project.coffee @@ -193,12 +193,7 @@ class Project extends EE debug("watch plugins file") @watchers.watchTree(cfg.pluginsFile, { onChange: => - ## TODO: completely re-open project instead? - debug("plugins file changed") - ## re-init plugins after a change - @_initPlugins(cfg, options) - .catch (err) -> - options.onError(err) + options.onPluginsChanged() }) watchSettings: (onSettingsChanged) -> @@ -217,6 +212,7 @@ class Project extends EE ## call our callback function ## when settings change! + ## TODO: pass the file path to the config:change event onSettingsChanged.call(@) } diff --git a/packages/server/test/unit/gui/events_spec.coffee b/packages/server/test/unit/gui/events_spec.coffee index 097475ed5c7c..be14ad37e316 100644 --- a/packages/server/test/unit/gui/events_spec.coffee +++ b/packages/server/test/unit/gui/events_spec.coffee @@ -450,6 +450,17 @@ describe "lib/gui/events", -> open.lastCall.args[0].onSettingsChanged() assert.sendCalledWith(undefined) + it "sends 'plugins:changed' onPluginsChanged", -> + open = sinon.stub(Project.prototype, "open") + sinon.stub(Project.prototype, "getConfig").resolves({some: "config"}) + + @handleEvent("open:project", "/_test-output/path/to/project") + .then => + @handleEvent("on:plugins:changed") + .then (assert) => + open.lastCall.args[0].onPluginsChanged() + assert.sendCalledWith(undefined) + it "sends 'spec:changed' onSpecChanged", -> open = sinon.stub(Project.prototype, "open") sinon.stub(Project.prototype, "getConfig").resolves({some: "config"}) diff --git a/packages/server/test/unit/project_spec.coffee b/packages/server/test/unit/project_spec.coffee index ebcbf1d20034..3e23d96ca412 100644 --- a/packages/server/test/unit/project_spec.coffee +++ b/packages/server/test/unit/project_spec.coffee @@ -395,21 +395,13 @@ describe "lib/project", -> expect(@project.watchers.watchTree.lastCall.args[1].onChange).to.be.a("function") it "calls plugins.init when file changes", -> - @project.watchPluginsFile(@config).then => - @project.watchers.watchTree.firstCall.args[1].onChange() - expect(plugins.init).to.be.calledWith(@config) - - it "handles errors from calling plugins.init", (done) -> - error = {name: "foo", message: "foo"} - plugins.init.rejects(error) - @project.watchPluginsFile(@config, { - onError: (err) -> - expect(err).to.eql(error) - done() - }) - .then => + options = { onPluginsChanged: sinon.stub() } + + @project.watchPluginsFile(@config, options).then => @project.watchers.watchTree.firstCall.args[1].onChange() - return + + ## TODO expect to be called with file path + expect(options.onPluginsChanged).to.be.called context "#watchSettingsAndStartWebsockets", -> beforeEach ->