Skip to content

Commit

Permalink
fix(watcher): use correct file sha in url query string
Browse files Browse the repository at this point in the history
Use the most recently computed file sha present on the served file
when setting the file sha in the scripts tags added to the context.html.

This fixes an issue where the sha query arg would always be the sha of
the file when karma initially started and would not take into account
changes to the file when the watcher is running.

Closes #2317, #2264
  • Loading branch information
Chris Casola committed Mar 21, 2017
1 parent 28e77e0 commit 3dec192
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/middleware/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* - setting propert caching headers
*/

var _ = require('lodash')
var from = require('core-js/library/fn/array/from')
var path = require('path')
var util = require('util')
var url = require('url')
Expand Down Expand Up @@ -74,6 +76,12 @@ var isFirefox = function (req) {
return firefox
}

var findByPath = function (files, path) {
return _.find(from(files), function (file) {
return file.path === path
})
}

var createKarmaMiddleware = function (
filesPromise,
serveStaticFile,
Expand Down Expand Up @@ -183,7 +191,12 @@ var createKarmaMiddleware = function (
filePath = filePathToUrlPath(filePath, basePath, urlRoot, proxyPath)

if (requestUrl === '/context.html') {
filePath += '?' + file.sha
var servedFile = findByPath(files.served, file.path)
if (servedFile) {
filePath += '?' + servedFile.sha
} else {
filePath += '?' + file.sha
}
}
}

Expand Down

0 comments on commit 3dec192

Please sign in to comment.