From 387ca00068be8e591240987e67c9bfd36d37ac3b Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Thu, 13 Jun 2019 23:24:03 -0400 Subject: [PATCH] Do not watch any files in run mode (#4458) * do not watch pluginsFile in run mode * add integration test ensuring watchers aren't applied in run mode Co-authored-by: Brian Mann --- packages/server/lib/project.coffee | 4 ++-- .../server/test/integration/cypress_spec.coffee | 10 ++++++++++ packages/server/test/unit/project_spec.coffee | 14 ++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/server/lib/project.coffee b/packages/server/lib/project.coffee index 41ef0a666198..62e0f260484c 100644 --- a/packages/server/lib/project.coffee +++ b/packages/server/lib/project.coffee @@ -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) @@ -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") diff --git a/packages/server/test/integration/cypress_spec.coffee b/packages/server/test/integration/cypress_spec.coffee index 5da658fa2ff1..5488ed7c873e 100644 --- a/packages/server/test/integration/cypress_spec.coffee +++ b/packages/server/test/integration/cypress_spec.coffee @@ -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) => diff --git a/packages/server/test/unit/project_spec.coffee b/packages/server/test/unit/project_spec.coffee index ebcbf1d20034..e2059b00bdbc 100644 --- a/packages/server/test/unit/project_spec.coffee +++ b/packages/server/test/unit/project_spec.coffee @@ -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)