From 3dec1920ff83f186f4957ed5ca4ac7452e0f7efe Mon Sep 17 00:00:00 2001 From: Chris Casola Date: Tue, 21 Mar 2017 16:05:57 -0400 Subject: [PATCH] fix(watcher): use correct file sha in url query string 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 --- lib/middleware/karma.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/middleware/karma.js b/lib/middleware/karma.js index 3392096bd..f1bae3fc7 100644 --- a/lib/middleware/karma.js +++ b/lib/middleware/karma.js @@ -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') @@ -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, @@ -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 + } } }