Skip to content

Commit

Permalink
address #3069 by using chokidar fs events
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Edwin authored and Paul Edwin committed Apr 29, 2019
1 parent 2f3de5b commit 16200f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 13 additions & 8 deletions packages/server/lib/open_project.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -128,7 +130,7 @@ create = ->

checkForSpecUpdates = =>
if not openProject
return @clearSpecInterval()
return @stopSpecWatcher()

get()
.then(sendIfChanged)
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -171,7 +176,7 @@ create = ->
close: ->
debug("closing opened project")

@clearSpecInterval()
@stopSpecWatcher()
@closeOpenProjectAndBrowsers()

create: (path, args = {}, options = {}) ->
Expand Down
4 changes: 1 addition & 3 deletions packages/server/lib/watchers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 16200f8

Please sign in to comment.