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

feat: Support for custom context and/or debug html files #1360

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
16 changes: 14 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, serveFile,
/* config.basePath */ basePath, /* config.urlRoot */ urlRoot, /* config.client */ client) {

return function(request, response, next) {
Expand Down Expand Up @@ -101,7 +101,19 @@ 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 fileServer;
if (client && client.contextFile) {
fileServer = serveFile;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like the rest of the file follows 2-space indentations; you have 4-space

requestUrl = path.normalize(process.cwd() + client.contextFile);
} else if (client && client.debugFile) {
fileServer = serveFile;
requestUrl = path.normalize(process.cwd() + client.debugFile);
} else {
fileServer = serveStaticFile;
}

fileServer(requestUrl, response, function(data) {
common.setNoCacheHeaders(response);

var scriptTags = files.included.map(function(file) {
Expand Down
8 changes: 4 additions & 4 deletions test/unit/middleware/karma.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe 'middleware.karma', ->
response = new HttpResponseMock
filesDeferred = q.defer()
serveFile = createServeFile fsMock, '/karma/static'
handler = createKarmaMiddleware filesDeferred.promise, serveFile,
handler = createKarmaMiddleware filesDeferred.promise, serveFile, null,
'/base/path', '/__karma__/', clientConfig

# helpers
Expand Down Expand Up @@ -80,7 +80,7 @@ describe 'middleware.karma', ->


it 'should serve client.html', (done) ->
handler = createKarmaMiddleware null, serveFile, '/base', '/'
handler = createKarmaMiddleware null, serveFile, null, '/base', '/'

response.once 'end', ->
expect(nextSpy).not.to.have.been.called
Expand All @@ -91,7 +91,7 @@ describe 'middleware.karma', ->


it 'should serve /?id=xxx', (done) ->
handler = createKarmaMiddleware null, serveFile, '/base', '/'
handler = createKarmaMiddleware null, serveFile, null, '/base', '/'

response.once 'end', ->
expect(nextSpy).not.to.have.been.called
Expand All @@ -101,7 +101,7 @@ describe 'middleware.karma', ->
callHandlerWith '/?id=123'

it 'should serve /?x-ua-compatible with replaced values', (done) ->
handler = createKarmaMiddleware null, serveFile, '/base', '/'
handler = createKarmaMiddleware null, serveFile, null, '/base', '/'

response.once 'end', ->
expect(nextSpy).not.to.have.been.called
Expand Down