Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom context file #1277

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/middleware/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var getXUACompatibleUrl = function(url) {
return value;
};

var createKarmaMiddleware = function(filesPromise, serveStaticFile,
var createKarmaMiddleware = function(filesPromise, serveStaticFile, serveCWDFile,
/* config.basePath */ basePath, /* config.urlRoot */ urlRoot, /* config.client */ client) {

return function(request, response, next) {
Expand Down Expand Up @@ -101,7 +101,14 @@ var createKarmaMiddleware = function(filesPromise, serveStaticFile,
// or debug.html - execution context without channel to the server
if (requestUrl === '/context.html' || requestUrl === '/debug.html') {
return filesPromise.then(function(files) {
serveStaticFile(requestUrl, response, function(data) {

var fileToServe = requestUrl, serveFileHandler = serveStaticFile;
if(requestUrl === '/context.html' && client && client.contextFile) {
fileToServe = path.normalize(client.contextFile);
serveFileHandler = serveCWDFile;
}

serveFileHandler(fileToServe, response, function(data) {
common.setNoCacheHeaders(response);

var scriptTags = files.included.map(function(file) {
Expand Down
2 changes: 2 additions & 0 deletions lib/web-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var createCustomHandler = function(customFileHandlers, /* config.basePath */ bas

var createWebServer = function(injector, emitter) {
var serveStaticFile = common.createServeFile(fs, path.normalize(__dirname + '/../static'));
var serveCWDFile = common.createServeFile(fs, path.normalize(process.cwd()));
var serveFile = common.createServeFile(fs);
var filesPromise = new common.PromiseContainer();

Expand All @@ -40,6 +41,7 @@ var createWebServer = function(injector, emitter) {
injector = injector.createChild([{
serveFile: ['value', serveFile],
serveStaticFile: ['value', serveStaticFile],
serveCWDFile: ['value', serveCWDFile],
filesPromise: ['value', filesPromise]
}]);

Expand Down