From 74bfdf3f41781e3d77a293b36565a71e879979f9 Mon Sep 17 00:00:00 2001 From: Chris Casola Date: Sat, 1 Apr 2017 11:35:40 -0400 Subject: [PATCH] fix(file-list): always use file from first matcher If a file is matched by multiple patterns, only the file from the first pattern should be used. This fixes issues that occurr when the same file appears in multiple buckets. One such issue is that the watcher reruns the preprocessors on the first occurrence of the file but the second version of the file is the one being included in the context. This results in the browser not requesting the updated version of the file after the watch fires. --- lib/file-list.js | 9 ++++++++- test/e2e/files.feature | 38 +++++++++++++++++++++++++++++-------- test/unit/file-list.spec.js | 11 +++++++++++ 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/lib/file-list.js b/lib/file-list.js index 5cfc928e4..ca9c9e2e2 100644 --- a/lib/file-list.js +++ b/lib/file-list.js @@ -150,6 +150,7 @@ List.prototype._isRefreshing = function () { List.prototype._refresh = function () { var self = this var buckets = this.buckets + var matchedFiles = new Set() var promise = Promise.map(this._patterns, function (patternObject) { var pattern = patternObject.pattern @@ -174,6 +175,12 @@ List.prototype._refresh = function () { return Promise.resolve() } + if (matchedFiles.has(path)) { + return Promise.resolve() + } + + matchedFiles.add(path) + var mtime = mg.statCache[path].mtime var doNotCache = patternObject.nocache var file = new File(path, mtime, doNotCache) @@ -191,7 +198,7 @@ List.prototype._refresh = function () { files = _.compact(files) if (_.isEmpty(files)) { - log.warn('All files matched by "%s" were excluded.', pattern) + log.warn('All files matched by "%s" were excluded or matched by prior matchers.', pattern) } else { buckets.set(pattern, new Set(files)) } diff --git a/test/e2e/files.feature b/test/e2e/files.feature index 8b27d195e..25dab2255 100644 --- a/test/e2e/files.feature +++ b/test/e2e/files.feature @@ -38,11 +38,15 @@ Feature: Including files ]; """ When I start Karma - Then it passes with: + Then it passes with like: """ . PhantomJS """ + And it passes with like: + """ + files/log_foo.js" were excluded or matched by prior matchers. + """ Scenario: Execute a test excluding an explicitly included file in another order Given a configuration with: @@ -59,11 +63,15 @@ Feature: Including files ]; """ When I start Karma - Then it passes with: + Then it passes with like: """ . PhantomJS """ + And it passes with like: + """ + files/log_foo.js" were excluded or matched by prior matchers. + """ Scenario: Execute a test excluding an file included with brackets patterns Given a configuration with: @@ -80,11 +88,15 @@ Feature: Including files ]; """ When I start Karma - Then it passes with: + Then it passes with like: """ . PhantomJS """ + And it passes with like: + """ + files/{log,bug}_foo.js" were excluded or matched by prior matchers. + """ Scenario: Execute a test excluding an file included with wildcard Given a configuration with: @@ -101,11 +113,15 @@ Feature: Including files ]; """ When I start Karma - Then it passes with: + Then it passes with like: """ . PhantomJS """ + And it passes with like: + """ + files/*.js" were excluded or matched by prior matchers. + """ Scenario: Execute a test excluding an file included with glob-star Given a configuration with: @@ -122,12 +138,15 @@ Feature: Including files ]; """ When I start Karma - Then it passes with: + Then it passes with like: """ . PhantomJS """ - + And it passes with like: + """ + files/**" were excluded or matched by prior matchers. + """ Scenario: Execute a test excluding an file included with ext. glob patterns Given a configuration with: @@ -145,9 +164,12 @@ Feature: Including files ]; """ When I start Karma - Then it passes with: + Then it passes with like: """ . PhantomJS """ - + And it passes with like: + """ + files/{log,bug}_foo.js" were excluded or matched by prior matchers. + """ diff --git a/test/unit/file-list.spec.js b/test/unit/file-list.spec.js index 33867bbd1..efb95ede7 100644 --- a/test/unit/file-list.spec.js +++ b/test/unit/file-list.spec.js @@ -266,6 +266,17 @@ describe('FileList', () => { }) }) + it('uses the file from the first matcher if two matchers match the same file', () => { + list = new List(patterns('/a.*', '*.txt'), [], emitter, preprocess, 100) + return list.refresh().then(() => { + var first = pathsFrom(list.buckets.get('/a.*')) + var second = pathsFrom(list.buckets.get('*.txt')) + + expect(first).to.contain('/a.txt') + expect(second).not.to.contain('/a.txt') + }) + }) + it('cancels refreshs', () => { var checkResult = (files) => { expect(_.pluck(files.served, 'path')).to.contain('/some/a.js', '/some/b.js', '/some/c.js')