Skip to content

Commit

Permalink
Do not watch any files in run mode (#4458)
Browse files Browse the repository at this point in the history
* do not watch pluginsFile in run mode

* add integration test ensuring watchers aren't applied in run mode


Co-authored-by: Brian Mann <brian.mann86@gmail.com>
  • Loading branch information
flotwig and brian-mann committed Jun 14, 2019
1 parent d185a74 commit 387ca00
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/server/lib/project.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class Project extends EE

watchPluginsFile: (cfg, options) ->
debug("attempt watch plugins file: #{cfg.pluginsFile}")
if not cfg.pluginsFile
if not cfg.pluginsFile or options.isTextTerminal
return Promise.resolve()

fs.pathExists(cfg.pluginsFile)
Expand All @@ -206,7 +206,7 @@ class Project extends EE

watchSettings: (onSettingsChanged) ->
## bail if we havent been told to
## watch anything
## watch anything (like in run mode)
return if not onSettingsChanged

debug("watch settings files")
Expand Down
10 changes: 10 additions & 0 deletions packages/server/test/integration/cypress_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,16 @@ describe "lib/cypress", ->
expect(browsers.open).to.be.calledWithMatch(ELECTRON_BROWSER, {url: "http://localhost:8888/__/#/tests/integration/test2.coffee"})
@expectExitWith(0)

it "does not watch settings or plugins in run mode", ->
watch = sinon.spy(Watchers.prototype, "watch")
watchTree = sinon.spy(Watchers.prototype, "watchTree")

cypress.start(["--run-project=#{@pluginConfig}"])
.then =>
expect(watchTree).not.to.be.called
expect(watch).not.to.be.called
@expectExitWith(0)

it "scaffolds out integration and example specs if they do not exist when not runMode", ->
config.get(@pristinePath)
.then (cfg) =>
Expand Down
14 changes: 10 additions & 4 deletions packages/server/test/unit/project_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -380,22 +380,28 @@ describe "lib/project", ->

it "does nothing when {pluginsFile: false}", ->
@config.pluginsFile = false
@project.watchPluginsFile(@config).then =>
@project.watchPluginsFile(@config, {}).then =>
expect(@project.watchers.watchTree).not.to.be.called

it "does nothing if pluginsFile does not exist", ->
fs.pathExists.resolves(false)
@project.watchPluginsFile(@config).then =>
@project.watchPluginsFile(@config, {}).then =>
expect(@project.watchers.watchTree).not.to.be.called

it "does nothing if in run mode", ->
@project.watchPluginsFile(@config, {
isTextTerminal: true
}).then =>
expect(@project.watchers.watchTree).not.to.be.called

it "watches the pluginsFile", ->
@project.watchPluginsFile(@config).then =>
@project.watchPluginsFile(@config, {}).then =>
expect(@project.watchers.watchTree).to.be.calledWith(@config.pluginsFile)
expect(@project.watchers.watchTree.lastCall.args[1]).to.be.an("object")
expect(@project.watchers.watchTree.lastCall.args[1].onChange).to.be.a("function")

it "calls plugins.init when file changes", ->
@project.watchPluginsFile(@config).then =>
@project.watchPluginsFile(@config, {}).then =>
@project.watchers.watchTree.firstCall.args[1].onChange()
expect(plugins.init).to.be.calledWith(@config)

Expand Down

0 comments on commit 387ca00

Please sign in to comment.