Skip to content

Commit

Permalink
WIP: update events for config/plugins changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lilaconlee committed Jan 24, 2019
1 parent deccabe commit 15f1807
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 22 deletions.
1 change: 1 addition & 0 deletions packages/desktop-gui/src/lib/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
18 changes: 16 additions & 2 deletions packages/desktop-gui/src/projects/projects-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
9 changes: 9 additions & 0 deletions packages/server/lib/gui/events.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)

Expand All @@ -203,6 +211,7 @@ handleEvent = (options, bus, event, id, type, arg) ->
onFocusTests: onFocusTests
onSpecChanged: onSpecChanged
onSettingsChanged: onSettingsChanged
onPluginsChanged: onPluginsChanged
onError: onError
onWarning: onWarning
})
Expand Down
8 changes: 2 additions & 6 deletions packages/server/lib/project.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand All @@ -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(@)
}

Expand Down
11 changes: 11 additions & 0 deletions packages/server/test/unit/gui/events_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down
20 changes: 6 additions & 14 deletions packages/server/test/unit/project_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down

0 comments on commit 15f1807

Please sign in to comment.