Skip to content

Commit

Permalink
fix(middleware): Inject config.urlRoot.
Browse files Browse the repository at this point in the history
Closes #1516.
  • Loading branch information
dignifiedquire committed Aug 6, 2015
1 parent eb1c8d2 commit 569ca0e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/middleware/source_files.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/**
* Source Files middleware is responsible for serving all the source files under the test.
*/

var from = require('core-js/library/fn/array/from')
var querystring = require('querystring')
var common = require('./common')
var _ = require('../helper')._
var logger = require('../logger')
var log = logger.create('middlware:source-files')

// Files is a Set
var findByPath = function (files, path) {
Expand All @@ -14,9 +12,8 @@ var findByPath = function (files, path) {
})
}

var createSourceFilesMiddleware = function (filesPromise, serveFile,
/* config.basePath */ basePath,
/* config.urlRoot */ urlRoot) {
// Source Files middleware is responsible for serving all the source files under the test.
var createSourceFilesMiddleware = function (filesPromise, serveFile, basePath, urlRoot) {
return function (request, response, next) {
var requestedFilePath = querystring.unescape(request.url)
.replace(urlRoot, '/')
Expand All @@ -26,6 +23,9 @@ var createSourceFilesMiddleware = function (filesPromise, serveFile,

request.pause()

log.debug('Requesting %s', request.url, urlRoot)
log.debug('Fetching %s', requestedFilePath)

return filesPromise.then(function (files) {
// TODO(vojta): change served to be a map rather then an array
var file = findByPath(files.served, requestedFilePath)
Expand All @@ -49,7 +49,9 @@ var createSourceFilesMiddleware = function (filesPromise, serveFile,
}
}

createSourceFilesMiddleware.$inject = ['filesPromise', 'serveFile', 'config.basePath']
createSourceFilesMiddleware.$inject = [
'filesPromise', 'serveFile', 'config.basePath', 'config.urlRoot'
]

// PUBLIC API
exports.create = createSourceFilesMiddleware
21 changes: 21 additions & 0 deletions test/e2e/proxy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,24 @@ Feature: Proxying
.
PhantomJS
"""

Scenario: URLRoot
Given a configuration with:
"""
files = ['proxy/*.js'];
browsers = ['PhantomJS'];
plugins = [
'karma-jasmine',
'karma-phantomjs-launcher'
];
urlRoot = '/__karma__';
proxies = {
'/foo.js': '/base/proxy/foo.js'
}
"""
When I start Karma
Then it passes with:
"""
.
PhantomJS
"""

0 comments on commit 569ca0e

Please sign in to comment.