From 5334d1a86b46f3c106b5a86f0bee7e4a58c5e4ae Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Wed, 14 Nov 2018 19:24:20 +0300 Subject: [PATCH] fix(file-list): do not preprocess up-to-date files (#3196) It improves performance of "karma run" command which refreshes fileList. Closes #2829 --- lib/file-list.js | 6 ++++++ test/unit/file-list.spec.js | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/file-list.js b/lib/file-list.js index a6dac0f25..f175a86e3 100644 --- a/lib/file-list.js +++ b/lib/file-list.js @@ -102,6 +102,12 @@ class FileList { return Promise.resolve(file) } + const prevFile = this._findFile(path, patternObject) + if (prevFile && file.mtime <= prevFile.mtime) { + log.debug(`Not preprocessing "${path}" as file hasn't been changed since the last preprocessing`) + return Promise.resolve(prevFile) + } + return this._preprocess(file).then(() => file) }) .then((files) => { diff --git a/test/unit/file-list.spec.js b/test/unit/file-list.spec.js index 3bec4bc68..bd2c9241a 100644 --- a/test/unit/file-list.spec.js +++ b/test/unit/file-list.spec.js @@ -375,9 +375,15 @@ describe('FileList', () => { }) }) - it('preprocesses all files', () => { + it('preprocesses new and/or changed files', () => { return list.refresh().then((files) => { expect(preprocess.callCount).to.be.eql(5) + preprocess.resetHistory() + mg.statCache['/some/a.js'].mtime++ + return list.refresh().then((files) => { + expect(preprocess.callCount).to.be.eql(1) + mg.statCache['/some/a.js'].mtime-- + }) }) })