From a4721ff5965f8c109d6cd0073bab55cab4e5b9be Mon Sep 17 00:00:00 2001 From: Paul Edwin Date: Fri, 26 Apr 2019 16:49:55 +0100 Subject: [PATCH] address #3069 by using chokidar fs events --- packages/server/lib/open_project.coffee | 21 +++++++++++++-------- packages/server/lib/watchers.coffee | 4 +--- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/server/lib/open_project.coffee b/packages/server/lib/open_project.coffee index 6debba933add..f0532b5a5880 100644 --- a/packages/server/lib/open_project.coffee +++ b/packages/server/lib/open_project.coffee @@ -2,17 +2,19 @@ _ = require("lodash") la = require("lazy-ass") debug = require("debug")("cypress:server:openproject") Promise = require("bluebird") +path = require("path") files = require("./controllers/files") config = require("./config") Project = require("./project") browsers = require("./browsers") +Watchers = require("./watchers") specsUtil = require("./util/specs") preprocessor = require("./plugins/preprocessor") create = -> openProject = null - specIntervalId = null relaunchBrowser = null + watchers = null reset = -> openProject = null @@ -128,7 +130,7 @@ create = -> checkForSpecUpdates = => if not openProject - return @clearSpecInterval() + return @stopSpecWatcher() get() .then(sendIfChanged) @@ -137,6 +139,12 @@ create = -> get = -> openProject.getConfig() .then (cfg) -> + if !watchers + watchers = Watchers() + watchers.watch(path.join(cfg.integrationFolder, cfg.testFiles), { + onChange: => + checkForSpecUpdates() + }) specsUtil.find(cfg) .then (specs = []) -> ## TODO: put back 'integration' property @@ -145,15 +153,12 @@ create = -> integration: specs } - specIntervalId = setInterval(checkForSpecUpdates, 2500) ## immediately check the first time around checkForSpecUpdates() - clearSpecInterval: -> - if specIntervalId - clearInterval(specIntervalId) - specIntervalId = null + stopSpecWatcher: -> + watchers?.close() closeBrowser: -> browsers.close() @@ -171,7 +176,7 @@ create = -> close: -> debug("closing opened project") - @clearSpecInterval() + @stopSpecWatcher() @closeOpenProjectAndBrowsers() create: (path, args = {}, options = {}) -> diff --git a/packages/server/lib/watchers.coffee b/packages/server/lib/watchers.coffee index a741e841d7e4..ccef3282598b 100644 --- a/packages/server/lib/watchers.coffee +++ b/packages/server/lib/watchers.coffee @@ -16,9 +16,7 @@ class Watchers watch: (filePath, options = {}) -> _.defaults options, - interval: 250 - usePolling: true - useFsEvents: false + useFsEvents: true ignored: null onChange: null onReady: null