Skip to content

Commit

Permalink
fix(file-list): do not preprocess up-to-date files (#3196)
Browse files Browse the repository at this point in the history
It improves performance of "karma run" command which refreshes fileList.

Closes #2829
  • Loading branch information
segrey authored and johnjbarton committed Nov 14, 2018
1 parent dc5f5de commit 5334d1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/file-list.js
Expand Up @@ -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) => {
Expand Down
8 changes: 7 additions & 1 deletion test/unit/file-list.spec.js
Expand Up @@ -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--
})
})
})

Expand Down

0 comments on commit 5334d1a

Please sign in to comment.